Class: Sass::Globbing::Importer

Inherits:
Importers::Filesystem
  • Object
show all
Includes:
Singleton
Defined in:
lib/sass/globbing/importer.rb

Constant Summary collapse

GLOB =
/\*/
SASS_EXTENSIONS =
{
  ".sass" => :sass,
  ".scss" => :scss
}

Instance Method Summary collapse

Constructor Details

#initializeImporter

Returns a new instance of Importer.



15
16
17
# File 'lib/sass/globbing/importer.rb', line 15

def initialize
  super(".")
end

Instance Method Details

#each_globbed_file(glob, base_pathname, options) ⇒ Object



57
58
59
60
61
62
# File 'lib/sass/globbing/importer.rb', line 57

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

#find(name, options) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/sass/globbing/importer.rb', line 49

def find(name, options)
  if options[:filename] # globs must be relative
    find_relative(name, options[:filename], options, true)
  else
    nil
  end
end

#find_relative(name, base, options, absolute = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sass/globbing/importer.rb', line 27

def find_relative(name, base, options, absolute = false)
  if name =~ GLOB
    contents = ""
    base = base.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
    base_pathname = Pathname.new(base)
    each_globbed_file(name, base_pathname, options) do |filename|
      contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
    end
    if contents.empty? && !absolute
      return nil
    end
    contents = "/* No files to import found in #{comment_safe(name)} */" if contents.empty?
    Sass::Engine.new(contents, options.merge(
      :filename => base_pathname.to_s,
      :importer => self,
      :syntax => :scss
    ))
  else
    super(name, base, options)
  end
end

#key(name, options) ⇒ Object



78
79
80
# File 'lib/sass/globbing/importer.rb', line 78

def key(name, options)
  ["Glob:" + File.dirname(File.expand_path(name)), File.basename(name)]
end

#mtime(name, options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sass/globbing/importer.rb', line 64

def mtime(name, options)
  if name =~ GLOB && options[:filename]
    mtime = nil
    each_globbed_file(name, Pathname.new(options[:filename]), options) do |p|
      if mtime.nil?
        mtime = File.mtime(p)
      else
        mtime = [mtime, File.mtime(p)].max
      end
    end
    mtime
  end
end

#sass_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/sass/globbing/importer.rb', line 19

def sass_file?(filename)
  SASS_EXTENSIONS.has_key?(File.extname(filename.to_s))
end

#syntax(filename) ⇒ Object



23
24
25
# File 'lib/sass/globbing/importer.rb', line 23

def syntax(filename)
  SASS_EXTENSIONS[File.extname(filename.to_s)]
end

#to_sObject



82
83
84
# File 'lib/sass/globbing/importer.rb', line 82

def to_s
  "Sass::Globbing::Importer"
end