Class: Condenser::Sass::Importer

Inherits:
SassC::Importer
  • Object
show all
Defined in:
lib/condenser/transformers/sass/importer.rb

Instance Method Summary collapse

Instance Method Details

#extensionsObject

Allow .css files to be @imported



34
35
36
# File 'lib/condenser/transformers/sass/importer.rb', line 34

def extensions
  { '.sass' => :sass, '.scss' => :scss, '.css' => :scss }
end

#imports(name, base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/condenser/transformers/sass/importer.rb', line 5

def imports(name, base)
  name = expand_path(name, base)
  env = options[:condenser][:environment]
  accept = extensions.keys.map { |x| options[:condenser][:environment].extensions[x] }

  options[:asset][:process_dependencies] << [name, accept.map{ |i| [i] }]

  imports = []
  env.resolve(name, accept: accept).sort_by(&:filename).each do |asset|
    next if asset.filename == options[:filename]
    imports << Import.new(asset.filename, source: asset.source, source_map_path: nil)
  end

  if imports.empty? && env.npm_path
    package = File.join(env.npm_path, name, 'package.json')
    if File.exist?(package)
      package = JSON.parse(File.read(package))
      if package['style']
        imports << Import.new(name, source: File.read(File.join(env.npm_path, name, package['style'])), source_map_path: nil)
      end
    end
  end

  raise Condenser::FileNotFound, "couldn't find file '#{name}'" if imports.empty?

  imports
end