【发布时间】:2011-11-25 09:59:56
【问题描述】:
我正在使用 Rails 3.1,我正在尝试使用两个模板处理程序处理一个文件。
好吧,我已经为 .scss 文件注册了一个新的模板处理程序。现在想处理这样的文件:
app/views/custom_css/stylesheet.css.scss.erb
通过 2 个模板处理程序。首先是 ERB,然后是 SCSS。这样我们就可以拥有动态的 scss 文件了。
我试过这个模板处理程序:
class ActionView::Template::Handlers::Sass
def initialize options = {}
@options = options
end
def erb_handler
@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
end
def call template
source = erb_handler.call(template)
<<CODE
compiler = Compass::Compiler.new *Compass.configuration.to_compiler_arguments
options = compiler.options.merge(#{@options.inspect})
Sass::Engine.new(source, options).render
CODE
end
end
但是,在这种情况下 source 等于:
"@output_buffer = output_buffer || ActionView::OutputBuffer.new;@output_buffer.safe_concat('$background_color: \"#ff0000\";\n\n$test: ');@output_buffer.append= ( 'test' );@output_buffer.safe_concat(';\n\n.container {\n background-color: $background_color;\n}\n');@output_buffer.to_s"
而且我不能轻易地只提取“真正的来源”。
任何想法如何做到这一点?
提前谢谢你!
【问题讨论】:
-
您找到解决方案了吗?因为我正在尝试做类似的事情,但我无法获得“真正的”来源。
标签: ruby-on-rails erb sass