Class: Sprockets::SassImporter

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

Constant Summary collapse

GLOB =
/\*|\[.+\]/

Instance Method Summary collapse

Instance Method Details

#each_globbed_file(glob, base_pathname, options) ⇒ Object



39
40
41
42
43
44
# File 'lib/sass/rails/importer.rb', line 39

def each_globbed_file(glob, base_pathname, options)
  Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
    next if filename == options[:filename]
    yield filename if File.directory?(filename) || context.asset_requirable?(filename)
  end
end

#extensionsObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sass/rails/importer.rb', line 10

def extensions
  {
    'css'          => :scss,
    'css.scss'     => :scss,
    'css.sass'     => :sass,
    'css.erb'      => :scss,
    'scss.erb'     => :scss,
    'sass.erb'     => :sass,
    'css.scss.erb' => :scss,
    'css.sass.erb' => :sass
  }.merge!(super)
end

#find(name, options) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/sass/rails/importer.rb', line 31

def find(name, options)
  if name =~ GLOB
    nil # globs must be relative
  else
    engine_from_path(name, root, options)
  end
end

#find_relative(name, base, options) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/sass/rails/importer.rb', line 23

def find_relative(name, base, options)
  if name =~ GLOB
    glob_imports(name, Pathname.new(base), options)
  else
    engine_from_path(name, File.dirname(base), options)
  end
end

#glob_imports(glob, base_pathname, options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sass/rails/importer.rb', line 46

def glob_imports(glob, base_pathname, options)
  contents = ""
  each_globbed_file(glob, base_pathname.dirname, options) do |filename|
    if File.directory?(filename)
      context.depend_on(filename)
    elsif context.asset_requirable?(filename)
      context.depend_on(filename)
      contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
    end
  end
  return nil if contents.empty?
  Sass::Engine.new(contents, options.merge(
    :filename => base_pathname.to_s,
    :importer => self,
    :syntax => :scss
  ))
end