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



47
48
49
50
51
52
# File 'lib/sass/globbing/importer.rb', line 47

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



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sass/globbing/importer.rb', line 35

def find(name, options)
  if options[:filename] # globs must be relative
    if name =~ GLOB
      find_glob(name, options[:filename], options) { "/* No files to import found in #{comment_safe(name)} */" }
    else
      super(name, options)
    end
  else
    nil
  end
end

#find_relative(name, base, options) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/sass/globbing/importer.rb', line 27

def find_relative(name, base, options)
  if name =~ GLOB
    find_glob(name, base, options) { nil }
  else
    super(name, base, options)
  end
end

#key(name, options) ⇒ Object



73
74
75
# File 'lib/sass/globbing/importer.rb', line 73

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

#mtime(name, options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sass/globbing/importer.rb', line 54

def mtime(name, options)
  if name =~ GLOB && options[:filename]
    mtime = nil
    base_pathname = Pathname.new(options[:filename])
    name_pathname = Pathname.new(name)
    if name_pathname.absolute?
      name = name_pathname.relative_path_from(base_pathname.dirname).to_s
    end
    each_globbed_file(name, base_pathname, 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



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

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