Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created August 17, 2011 14:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwilcox/1151643 to your computer and use it in GitHub Desktop.
Save rwilcox/1151643 to your computer and use it in GitHub Desktop.
AssetPath.sass_require: for sharing SASS variables between SASS files in the Rails 3.1 Asset Pipeline
module AssetPath
# Why this instead of Sproket's require_tree?
# Sprokets compiles one SASS file at a time, which works OK... until you want
# to pull out some SASS things (mixins, layout settings) into separate files.
# In that case, you want to have SASS compile everything all at once, in one big file
# So, use this helper to include all the SASS files down a path
#
# The alternative is the ugly (and not DRY!): <http://asciicasts.com/episodes/268-sass-basics>
# where you list every file manually in the application.css.scass file.
def self.sass_require(base_dir, *inside_dirs)
output = ""
Dir[File.join(base_dir, *inside_dirs, "/**/*")].each do |stylesheet_path|
unless File.directory?(stylesheet_path)
current_file_name = stylesheet_path.gsub(base_dir.to_s, '')
output << "@import '#{current_file_name}';\n"
end
end
output
end
end
@cclough
Copy link

cclough commented Sep 18, 2012

<- rails newbie : where in my app do I put this? christian.clough@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment