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.
Constant Summary collapse
- REDUNDANT_DIRECTORY =
%r{#{Regexp.escape(File::SEPARATOR)}\.#{Regexp.escape(File::SEPARATOR)}}
Instance Attribute Summary collapse
-
#root
Returns the value of attribute root.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #escape_glob_characters(name) protected
-
#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)
- #hash
-
#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. -
#remove_root(name)
protected
If a full uri is passed, this removes the root from it otherwise returns the name unchanged.
-
#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.
15 16 17 |
# File 'lib/sass/importers/filesystem.rb', line 15
def initialize(root)
@root = File.expand_path(root)
end
|
Instance Attribute Details
#root
Returns the value of attribute root.
9 10 11 |
# File 'lib/sass/importers/filesystem.rb', line 9
def root
@root
end
|
Instance Method Details
#eql?(other) ⇒ Boolean
52 53 54 |
# File 'lib/sass/importers/filesystem.rb', line 52
def eql?(other)
root.eql?(other.root)
end
|
#escape_glob_characters(name) (protected)
96 97 98 99 100 |
# File 'lib/sass/importers/filesystem.rb', line 96
def escape_glob_characters(name)
name.gsub(/[\*\[\]\{\}\?]/) do |char|
"\\#{char}"
end
end
|
#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.
75 76 77 |
# File 'lib/sass/importers/filesystem.rb', line 75
def extensions
{'sass' => :sass, 'scss' => :scss}
end
|
#find(name, options)
25 26 27 |
# File 'lib/sass/importers/filesystem.rb', line 25
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.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sass/importers/filesystem.rb', line 109
def find_real_file(dir, name)
for (f,s) in possible_files(remove_root(name))
path = (dir == "." || Pathname.new(f).absolute?) ? f : "#{dir}/#{f}"
if full_path = Dir[path].first
full_path.gsub!(REDUNDANT_DIRECTORY,File::SEPARATOR)
return full_path, s
end
end
nil
end
|
#find_relative(name, base, options)
20 21 22 |
# File 'lib/sass/importers/filesystem.rb', line 20
def find_relative(name, base, options)
_find(File.dirname(base), name, options)
end
|
#hash
48 49 50 |
# File 'lib/sass/importers/filesystem.rb', line 48
def hash
@root.hash
end
|
#key(name, options)
38 39 40 41 |
# File 'lib/sass/importers/filesystem.rb', line 38
def key(name, options)
[self.class.name + ":" + File.dirname(File.expand_path(name)),
File.basename(name)]
end
|
#mtime(name, options)
30 31 32 33 34 35 |
# File 'lib/sass/importers/filesystem.rb', line 30
def mtime(name, options)
file, s = find_real_file(@root, name)
File.mtime(file) if file
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.
86 87 88 89 90 91 92 93 94 |
# File 'lib/sass/importers/filesystem.rb', line 86
def possible_files(name)
name = escape_glob_characters(name)
dirname, basename, extname = split(name)
sorted_exts = extensions.sort
syntax = extensions[extname]
return [["#{dirname}/{_,}#{basename}.#{extensions.invert[syntax]}", syntax]] if syntax
sorted_exts.map {|ext, syn| ["#{dirname}/{_,}#{basename}.#{ext}", syn]}
end
|
#remove_root(name) (protected)
If a full uri is passed, this removes the root from it otherwise returns the name unchanged
60 61 62 63 64 65 66 |
# File 'lib/sass/importers/filesystem.rb', line 60
def remove_root(name)
if name.index(@root + "/") == 0
name[(@root.length + 1)..-1]
else
name
end
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.
122 123 124 125 126 127 128 129 130 |
# File 'lib/sass/importers/filesystem.rb', line 122
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
44 45 46 |
# File 'lib/sass/importers/filesystem.rb', line 44
def to_s
@root
end
|