-
-
Save sixtyfive/323233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Throw this in config/initializers and add | |
# @import variables.sass to the top of application.sass | |
# to have all variables in app_config.yml | |
# available as variables in your sass stylesheets | |
# | |
# First draft by unixmonkey (http://gist.github.com/323198) | |
# flatten method added by J. R. Schmid <[email protected]> | |
app_config = YAML::load(File.open(File.join(RAILS_ROOT, 'config', 'app_config.yml'))) | |
def flatten(input, prefix = nil) | |
output = {} | |
input.each do |key,value| | |
if value.class == Hash | |
output = output.merge(flatten(value, key)) | |
else | |
output["#{prefix}_#{key}"] = value | |
end | |
end | |
return output | |
end | |
sass_variables = [] | |
flatten(app_config).each do |key,value| | |
sass_variables << "!#{key}= #{value}" | |
end | |
File.open(File.join(RAILS_ROOT, 'public', 'stylesheets', 'sass', 'variables.sass'), 'w+') do |file| | |
file.write(sass_variables.join("\n")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment