Class: Sass::Globbing::Importer
- Inherits:
-
Importers::Filesystem
- Object
- Importers::Filesystem
- Sass::Globbing::Importer
- Includes:
- Singleton
- Defined in:
- lib/sass/globbing/importer.rb
Constant Summary collapse
- GLOB =
/\*/
- SASS_EXTENSIONS =
{ ".sass" => :sass, ".scss" => :scss }
Instance Method Summary collapse
- #each_globbed_file(glob, base_pathname, options) ⇒ Object
- #find(name, options) ⇒ Object
- #find_relative(name, base, options, absolute = false) ⇒ Object
-
#initialize ⇒ Importer
constructor
A new instance of Importer.
- #key(name, options) ⇒ Object
- #mtime(name, options) ⇒ Object
- #sass_file?(filename) ⇒ Boolean
- #syntax(filename) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Importer
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, ) Dir["#{base_pathname.dirname}/#{glob}"].sort.each do |filename| next if filename == [: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, ) if [:filename] # globs must be relative find_relative(name, [:filename], , 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, , 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, ) 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, .merge( :filename => base_pathname.to_s, :importer => self, :syntax => :scss )) else super(name, base, ) end end |
#key(name, options) ⇒ Object
78 79 80 |
# File 'lib/sass/globbing/importer.rb', line 78 def key(name, ) ["Glob:" + File.dirname(File.(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, ) if name =~ GLOB && [:filename] mtime = nil each_globbed_file(name, Pathname.new([:filename]), ) 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
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_s ⇒ Object
82 83 84 |
# File 'lib/sass/globbing/importer.rb', line 82 def to_s "Sass::Globbing::Importer" end |