I have an application that has three different CSS themes and each of those themes has a dozen or so color schemes. Everything works fine in development but the asset pipeline is giving me some odd issues.
Essentially I have several files like this
/themes
/cool-theme
_theme.scss
/color-schemes
red.scss
The idea is I precompile all the *.scss files except the partials (starting with the underscore) since they are included in the SASS. So I am using this code:
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
The code runs fine and shows an output I expect during assets:precompile. Excludes everything it should and includes everything it should.
The problem is the /public/assets directory never contains the css files for anything other then application.css. It’s missing red.css, blue.css, etc…
What am I overlooking?
The way the pipeline works for Javascript files and stylesheets is it’s only going to precompile an
application.jsandapplication.cssfile for you by default.This is why you have tried to append more assets to the
config.assets.precompileArray. You’re on the right track, but have made a few mistakes.The File Extension
You need to rename
to
This tells the pipeline that you want this to be a
.cssfile when it’s finished compiling.The Asset Path
Currently you’re appending a path like
to the
config.assets.precompileArray. Instead you need to be passing a path in this formatWhen you precompile your assets you’ll see a new
themesfolder created insidepublic/assets/containing the rest of your directory tree, complete with a compiledred.cssfile.I’ll leave fixing your code for appending paths to the
config.assets.precompileup to you as you seem more than capable of making the necessary changes outlined above.