2

我正在尝试使用Sass::Engine.new. 我遇到了一个问题,我不知道如何让它允许@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在顶部使用时,这样做没有问题,它能够在开发模式和 via 中即时编译为 CSS rake assets:precompile。但是我有一个新的用例,我需要自己渲染一些并且遇到了这个问题。在尝试渲染它之前,我尝试添加require 'compass',require 'compass-rails'require 'compass/rails',但它不起作用。需要工作(因为它说true或在需要文件之后),但在我的通话false中似乎仍然不可用。Sass::Engine.new().render

在我的 Gemfile 中,我有:

gem 'haml-rails'
gem 'sass-rails'
gem 'compass-rails'

任何人都知道在使用 Sass::Engine 时我可以做些什么来使库可见?我在参考文档中找不到任何内容

4

1 回答 1

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
于 2013-06-14T11:38:30.120 回答