module Cyborg::SassParser

Public Instance Methods

expand_vars(file) click to toggle source
# File lib/cyborg/sass/importer.rb, line 32
def expand_vars(file)
  content   = read_file(file)
  file_data = load_yaml(content)

  content = content.gsub(/\$(?<var>\w+)/) do
    file_data[$~[:var]].inspect
  end

  load_yaml content
end
load_yaml(data) click to toggle source

Global vars beginning with underscore will have their children promoted to globals and will be assigned without the underscore

For example: _colors: { yellow: '#fco' }

becomes: colors: { yellow: '#fco'}, yellow: '#fco'
# File lib/cyborg/sass/importer.rb, line 15
def load_yaml(data)
  promote_globals YAML.load(data)
end
parse(file) click to toggle source
# File lib/cyborg/sass/importer.rb, line 43
def parse(file)
  expand_vars file
end
promote_globals( data ) click to toggle source
# File lib/cyborg/sass/importer.rb, line 23
def promote_globals( data )
  data.keys.select{|k| k.start_with?('_') }.each do |key|
    data[key.sub(/^_/,'')] = data[key]
    data = data.delete(key).merge(data)
  end

  data
end
read_file(file) click to toggle source
# File lib/cyborg/sass/importer.rb, line 19
def read_file(file)
  IO.read(file)
end