0

我正在尝试在Sass 网站上关注 Sass -> CSS 转换器代码。

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 中解决这个问题,那就更好了。

4

1 回答 1

1

好吧,在 Ruby Kernel 方法中#load,这意味着评估作为代码加载的文本,这看起来就像在这里完成的那样。 File.read将文本加载为字符串。

来自 sass 文档Sass::Engine.new

创建一个新引擎。注意 Engine 只能在编译内存中的 Sass 代码时直接使用。如果您从文件系统编译单个 Sass 文件,请使用 Sass::Engine.for_file。如果要从文件系统编译多个文件,请使用 Sass::Plugin。

就这样做吧。

于 2012-09-27T18:17:18.280 回答