2012-09-27 67 views
0

我試圖按照薩斯 - > CSS轉換器代碼Sass websiteFile.load和File.read之間的區別紅寶石

template = File.load('stylesheets/sassy.sass') 
sass_engine = Sass::Engine.new(template) 
output = sass_engine.render 
puts output 

我得到這個錯誤,而我試圖File.load

SyntaxError in PublishController#index 

/Users/jkim/rails/support-rhapsody/app/assets/stylesheets/application.sass:1: target of repeat operator is not specified: /* http:/ 
/Users/jkim/rails/support-rhapsody/app/assets/stylesheets/application.sass:2: no .<digit> floating literal anymore; put 0 before dot 
    v2.0 | 20110126 
    ^
/Users/jkim/rails/support-rhapsody/app/assets/stylesheets/application.sass:2: syntax error, unexpected tINTEGER 
    v2.0 | 20110126 
    ^
/Users/jkim/rails/support-rhapsody/app/assets/stylesheets/application.sass:3: syntax error, unexpected ':', expecting $end 
    License: none (public domain) */ 

但是當我做File.read,它正常工作,直到output = sass_engine.render

我得到這個錯誤,

NoMethodError in PublishController#index 

undefined method `[]' for nil:NilClass 

什麼File.read和File.load之間的區別?如果你知道如何在Sass中解決這個問題,那就更好了。

+0

你試過'ri File.load'和'ri File.read'嗎?這兩種方法的用途非常不同。 –

+0

'ri File.load'獲取'NoMethodError:調用File:Class'的私有方法'load'。和 'ri File.read'得到'ArgumentError:錯誤的參數數量(0代表1..4)' –

+0

你不應該在IRB提示符中輸入'ri'。它是一個單獨的shell命令,可爲您提供rdoc信息。 –

回答

1

那麼在紅寶石內核方法#load這意味着評估加載的文本爲代碼,它看起來像是在這裏完成。 File.read將文本加載爲字符串。

從上海社會科學院文檔的Sass::Engine.new

Creates a new Engine. Note that Engine should only be used directly when compiling in-memory Sass code. If you’re compiling a single Sass file from the filesystem, use Sass::Engine.for_file. If you’re compiling multiple files from the filesystem, use Sass::Plugin.

這樣做。

相關問題