资产管道无法编译

时间:2013-01-31 18:33:26

标签: ruby-on-rails ruby-on-rails-3 sass asset-pipeline

我有一个具有三个不同CSS主题的应用程序,每个主题都有十几种颜色方案。一切都在开发中运作良好,但资产管道给我一些奇怪的问题。

基本上我有几个像这样的文件

/themes
  /cool-theme
    _theme.scss
    /color-schemes
      red.scss

我的想法是我预先编译除了部分之外的所有* .scss文件(以下划线开头),因为它们包含在SASS中。所以我使用这段代码:

stylesheets_directory = "#{Rails.root}/app/assets/stylesheets"
config.assets.precompile += Dir.glob("#{stylesheets_directory}/**/*.scss").
                            map{|f| f[stylesheets_directory.size+1..-1]}.
                            select do |file|
                            if config.assets.precompile.include?(file)
                              puts "Already have #{file}"
                              false
                            elsif File.basename(file)[0...1] == "_"
                              puts "Partial detected #{file}"
                              false
                            else
                              puts "Including #{file}"
                              true
                            end
                          end

代码运行正常并显示我在资产期间预期的输出:预编译。排除应有的一切,包括应有的一切。

问题是/ public / assets目录从不包含application.css以外的任何css文件。它缺少red.css,blue.css等......

我在俯瞰什么?

1 个答案:

答案 0 :(得分:2)

管道适用于Javascript文件和样式表的方式是,它默认只为您预编译application.jsapplication.css文件。 这就是您尝试将更多资源附加到config.assets.precompile数组的原因。你走在正确的轨道上,但犯了一些错误。

文件扩展名

您需要重命名

app/assets/stylesheets/themes/cool-theme/color-schemes/red.scss

app/assets/stylesheets/themes/cool-theme/color-schemes/red.css.scss

这告诉管道在完成编译时你希望它是一个.css文件。

资产路径

目前您正在添加类似

的路径
/Path/To/Your/app/assets/stylesheets/themes/cool-theme/color-schemes/red.scss

config.assets.precompile数组。相反,您需要以这种格式传递路径

themes/cool-theme/color-schemes/red.css

预编译资产时,您会看到在themes内创建的新public/assets/文件夹,其中包含目录树的其余部分,并附带已编译的red.css文件。


我将修复您的代码,以便将config.assets.precompile的路径附加到您身上,因为您似乎无法进行上述必要的更改。

相关问题