class SassJSONVars::Importer
Public Instance Methods
watched_file?(uri)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 7 def watched_file?(uri) !!(uri =~ /\.json$/ && uri.start_with?(root + File::SEPARATOR)) end
Protected Instance Methods
extensions()
click to toggle source
# File lib/sass-json-vars/importer.rb, line 14 def extensions {'json' => :scss} end
json?(name)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 18 def json?(name) File.extname(name) == '.json' end
Private Instance Methods
_convert_to_sass(item)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 40 def _convert_to_sass(item) if item.is_a? Array _make_list(item) elsif item.is_a? Hash _make_map(item) else item.to_s end end
_find(dir, name, options)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 24 def _find(dir, name, options) return unless json? name full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options)) return unless full_filename && File.readable?(full_filename) json = JSON.parse(IO.read(full_filename)) variables = json.map { |key, value| "$#{key}: #{_convert_to_sass(value)};" }.join("\n") Sass::Engine.new(variables, options.merge( :filename => full_filename, :importer => self, :syntax => :scss )) end
_make_list(item)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 50 def _make_list(item) '(' + item.map { |i| _convert_to_sass(i) }.join(',') + ')' end
_make_map(item)
click to toggle source
# File lib/sass-json-vars/importer.rb, line 54 def _make_map(item) '(' + item.map {|key, value| key.to_s + ':' + _convert_to_sass(value) }.join(',') + ')' end