Skip to content

Instantly share code, notes, and snippets.

@drinchev
Forked from sixtyfive/load_sass_variables.rb
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drinchev/3785f036add6b5a14305 to your computer and use it in GitHub Desktop.
Save drinchev/3785f036add6b5a14305 to your computer and use it in GitHub Desktop.
# 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() added by Raphael J. Schmid <raphael.schmid@gmail.com>
# Full re-write. Configuration function added and can be used in compass/sass
#
# Example configuration.yaml
#
# foo: 1
# bar:
# baz: 2
#
# Example any.scss
#
# $qux: configuration(bar-baz); // qux === 2
# $quz: configuration(foo); // foo === 1
#
require 'yaml'
configurationFile = YAML.load_file('configuration.yaml')
$configurationObject = {}
def process_hash(translations, current_key, hash)
hash.each do |new_key, value|
combined_key = [current_key, new_key].delete_if { |k| k == '' }.join("-")
if value.is_a?(Hash)
process_hash(translations, combined_key, value)
else
translations[combined_key] = value
end
end
end
process_hash($configurationObject, '', configurationFile['default']['layout'])
module Sass::Script::Functions
def configuration(option)
value = $configurationObject[option.to_s]
if(value.is_a?(String))
Sass::Script::Value::String.new(value.to_s)
elsif (value.is_a?(Integer))
Sass::Script::Value::Number.new(value.to_i)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment