我正在尝试使用Sass::Engine.new
以编程方式将一些sass渲染到CSS中。我遇到了一个问题,我无法弄清楚如何让它允许@import GEMMIFIED_SASS_MODULE
。例如,这就是我正在尝试的:
?> sass = "@import \"blueprint/reset\"\nh1\n width: 100%"
=> "@import \"blueprint/reset\"\nh1\n width: 100%"
>> puts sass # For readable version
@import "blueprint/reset"
h1
width: 100%
=> nil
>> Sass::Engine.new(sass, :syntax => :sass).render
Sass::SyntaxError: File to import not found or unreadable: blueprint/reset.
Load path: /Users/username/projects/my_app
from (sass):1
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/import_node.rb:64:in `rescue in import'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/import_node.rb:42:in `import'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/import_node.rb:25:in `imported_file'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:149:in `rescue in visit_import'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:154:in `visit_import'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:37:in `visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:18:in `visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:53:in `map'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:53:in `visit_children'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:27:in `block in visit_children'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:39:in `with_environment'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:26:in `visit_children'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:37:in `block in visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:47:in `visit_root'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/base.rb:37:in `visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:18:in `visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/visitors/perform.rb:7:in `visit'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/tree/root_node.rb:20:in `render'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/engine.rb:299:in `_render'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/sass-3.1.15/lib/sass/engine.rb:246:in `render'
from (irb):30
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/username/.rvm/gems/ruby-1.9.2-p290@my_app/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
当我将一些sass放入文件并在顶部使用@import blueprint/reset
时,我没有问题,它可以在开发模式中通过{{1 }}。但是我有一个新的用例,我需要自己渲染一些并遇到这个问题。在尝试渲染之前,我尝试添加rake assets:precompile
,require 'compass'
和require 'compass-rails'
,但它不起作用。需要工作(在需要文件后,它表示require 'compass/rails'
或true
),但我的false
电话中似乎仍无法使用。
在我的Gemfile中,我有:
Sass::Engine.new().render
任何人都知道在使用Sass :: Engine时我可以做些什么来使库可见?我在Reference或Documentation
中找不到任何内容答案 0 :(得分:0)
您没有提供蓝图的路径,而SASS找不到它。
Compass是为解决此问题而创建的工具。它提供了一个扩展生态系统,可以直接导入而无需提供路径。
你正试图用普通的SASS做到这一点。要解决此问题,您必须使SASS熟悉Compass扩展的存储位置:
# Allowing vanilla SASS use Compass extensions
Compass.sass_engine_options[:load_paths].each do |path|
Sass.load_paths << path
end