一整天后,我能我的問題,感謝解決約翰Feminella和his post on google。對我來說,挑戰性的部分是弄清楚如何創建一個新的Sprockets :: Context。幸運的是,約翰的解決方案不需要上下文。
更新要點here
嘗試#1
此代碼不允許從資產管道導入CSS文件。
@import "foundation";
作品,因爲基礎加載爲羅盤模塊
@import "custom_css";
導致一個錯誤消息說文件找不到
def call(template)
erb = ActionView::Template.registered_template_handler(:erb).call(template)
%{
options = Compass.configuration.to_sass_engine_options.merge(
:syntax => :scss,
:custom => {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)},
)
Sass::Engine.new((begin;#{erb};end), options).render
}
end
嘗試#2
此代碼失敗使用資產數據網址嵌入base64網址
def call(template)
erb = ActionView::Template.registered_template_handler(:erb).call(template)
%{
compiler = Compass::Compiler.new *Compass.configuration.to_compiler_arguments
options = compiler.options.merge({
:syntax => :scss,
:custom => {:resolver => ::Sass::Rails::Resolver.new(CompassRails.context)},
})
Sass::Engine.new((begin;#{erb};end), options).render
}
end
嘗試3
原來在創建上下文可以使用空值。下面的代碼在開發中工作,但會在生產中引發錯誤。
ActionView::Template::Error (can't modify immutable index)
它出現錯誤發生在鏈輪::索引被用來代替鏈輪::環境中的生產。切換到Sprockets :: Environment也不能解決問題。
def call(template)
erb = ActionView::Template.registered_template_handler(:erb).call(template)
%{
context = CompassRails.context.new(::Rails.application.assets, '', Pathname.new(''))
resolver = ::Sass::Rails::Resolver.new(context)
compiler = Compass::Compiler.new *Compass.configuration.to_compiler_arguments
options = compiler.options.merge({
:syntax => :scss,
:custom => {:resolver => resolver}
})
Sass::Engine.new((begin;#{erb};end), options).render
}
end