Module: Cyborg::SassParser
Instance Method Summary collapse
- #expand_vars(file) ⇒ Object
-
#load_yaml(data) ⇒ Object
Global vars beginning with underscore will have their children promoted to globals and will be assigned without the underscore.
- #parse(file) ⇒ Object
- #promote_globals(data) ⇒ Object
- #read_file(file) ⇒ Object
Instance Method Details
#expand_vars(file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cyborg/sass/importer.rb', line 32 def (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) ⇒ Object
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'
15 16 17 |
# File 'lib/cyborg/sass/importer.rb', line 15 def load_yaml(data) promote_globals YAML.load(data) end |
#parse(file) ⇒ Object
43 44 45 |
# File 'lib/cyborg/sass/importer.rb', line 43 def parse(file) file end |
#promote_globals(data) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
19 20 21 |
# File 'lib/cyborg/sass/importer.rb', line 19 def read_file(file) IO.read(file) end |