Class: SassJSONVars::Importer

Inherits:
Sass::Importers::Filesystem
  • Object
show all
Defined in:
lib/sass-json-vars/importer.rb

Instance Method Summary collapse

Instance Method Details

#extensionsObject



10
11
12
# File 'lib/sass-json-vars/importer.rb', line 10

def extensions
  {'json' => :scss}
end

#find(name, options) ⇒ Object



18
19
20
# File 'lib/sass-json-vars/importer.rb', line 18

def find(name, options)
  super(name, options) if json? name
end

#find_relative(name, base, options) ⇒ Object



22
23
24
# File 'lib/sass-json-vars/importer.rb', line 22

def find_relative(name, base, options)
  super(name, base, options) if json? name
end

#json?(name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/sass-json-vars/importer.rb', line 14

def json?(name)
  File.extname(name) == '.json'
end

#sass_engine(uri, options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/sass-json-vars/importer.rb', line 26

def sass_engine(uri, options)
  json = JSON.parse(IO.read(uri))

  variables = json.map do |name, value|
    output = _convert_to_sass(value);
    "$#{name}: #{output}"
  end

  Sass::Engine.new(variables.join("\n"))
end

#watched_file?(uri) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/sass-json-vars/importer.rb', line 6

def watched_file?(uri)
  uri =~ /\.json$/ && uri.start_with?(root + File::SEPARATOR)
end