Class: Sass::Importers::Filesystem
- Defined in:
- lib/sass/importers/filesystem.rb
Overview
The default importer, used for any strings found in the load path. Simply loads Sass files from the filesystem using the default logic.
Instance Method Summary collapse
-
#extensions ⇒ {String => Symbol}
protected
A hash from file extensions to the syntaxes for those extensions.
- #find(name, options)
-
#find_real_file(dir, name) ⇒ (String, Symbol)
protected
Given a base directory and an
@import
ed name, finds an existant file that matches the name. - #find_relative(name, base, options)
-
#initialize(root) ⇒ Filesystem
constructor
Creates a new filesystem importer that imports files relative to a given path.
- #key(name, options)
- #mtime(name, options)
-
#possible_files(name) ⇒ Array(String, Symbol)
protected
Given an
@import
ed path, returns an array of possible on-disk filenames and their corresponding syntaxes for that path. -
#split(name)
protected
Splits a filename into three parts, a directory part, a basename, and an extension Only the known extensions returned from the extensions method will be recognized as such.
- #to_s
Constructor Details
#initialize(root) ⇒ Filesystem
Creates a new filesystem importer that imports files relative to a given path.
12 13 14 |
# File 'lib/sass/importers/filesystem.rb', line 12
def initialize(root)
@root = root
end
|
Instance Method Details
#extensions ⇒ {String => Symbol} (protected)
A hash from file extensions to the syntaxes for those extensions.
The syntaxes must be :sass
or :scss
.
This can be overridden by subclasses that want normal filesystem importing with unusual extensions.
54 55 56 |
# File 'lib/sass/importers/filesystem.rb', line 54
def extensions
{'sass' => :sass, 'scss' => :scss}
end
|
#find(name, options)
22 23 24 |
# File 'lib/sass/importers/filesystem.rb', line 22
def find(name, options)
_find(@root, name, options)
end
|
#find_real_file(dir, name) ⇒ (String, Symbol) (protected)
Given a base directory and an @import
ed name,
finds an existant file that matches the name.
83 84 85 86 87 88 89 90 |
# File 'lib/sass/importers/filesystem.rb', line 83
def find_real_file(dir, name)
possible_files(name).each do |f, s|
if File.exists?(full_path = join(dir, f))
return full_path, s
end
end
nil
end
|
#find_relative(name, base, options)
17 18 19 |
# File 'lib/sass/importers/filesystem.rb', line 17
def find_relative(name, base, options)
_find(File.dirname(base), name, options)
end
|
#key(name, options)
35 36 37 38 |
# File 'lib/sass/importers/filesystem.rb', line 35
def key(name, options)
[self.class.name + ":" + File.dirname(File.expand_path(name)),
File.basename(name)]
end
|
#mtime(name, options)
27 28 29 30 31 32 |
# File 'lib/sass/importers/filesystem.rb', line 27
def mtime(name, options)
file = find_real_file(@root, name)
File.mtime(name)
rescue Errno::ENOENT
nil
end
|
#possible_files(name) ⇒ Array(String, Symbol) (protected)
Given an @import
ed path, returns an array of possible
on-disk filenames and their corresponding syntaxes for that path.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sass/importers/filesystem.rb', line 65
def possible_files(name)
dirname, basename, extname = split(name)
sorted_exts = extensions.sort
syntax = extensions[extname]
Haml::Util.flatten(
["#{dirname}/#{basename}", "#{dirname}/_#{basename}"].map do |name|
next [["#{name}.#{extensions.invert[syntax]}", syntax]] if syntax
sorted_exts.map {|ext, syn| ["#{name}.#{ext}", syn]}
end, 1)
end
|
#split(name) (protected)
Splits a filename into three parts, a directory part, a basename, and an extension Only the known extensions returned from the extensions method will be recognized as such.
94 95 96 97 98 99 100 101 102 |
# File 'lib/sass/importers/filesystem.rb', line 94
def split(name)
extension = nil
dirname, basename = File.dirname(name), File.basename(name)
if basename =~ /^(.*)\.(#{extensions.keys.map{|e| Regexp.escape(e)}.join('|')})$/
basename = $1
extension = $2
end
[dirname, basename, extension]
end
|
#to_s
41 42 43 |
# File 'lib/sass/importers/filesystem.rb', line 41
def to_s
@root
end
|