Parent

Class/Module Index [+]

Quicksearch

Sass::Importers::Filesystem

The default importer, used for any strings found in the load path. Simply loads Sass files from the filesystem using the default logic.

Attributes

root[RW]

Public Class Methods

new(root) click to toggle source

Creates a new filesystem importer that imports files relative to a given path.

@param root [String] The root path.

This importer will import files relative to this path.
# File lib/sass/importers/filesystem.rb, line 15
def initialize(root)
  @root = File.expand_path(root)
end

Public Instance Methods

eql?(other) click to toggle source
# File lib/sass/importers/filesystem.rb, line 52
def eql?(other)
  root.eql?(other.root)
end
find(name, options) click to toggle source

@see Base#find

# File lib/sass/importers/filesystem.rb, line 25
def find(name, options)
  _find(@root, name, options)
end
find_relative(name, base, options) click to toggle source

@see Base#find_relative

# File lib/sass/importers/filesystem.rb, line 20
def find_relative(name, base, options)
  _find(File.dirname(base), name, options)
end
hash() click to toggle source
# File lib/sass/importers/filesystem.rb, line 48
def hash
  @root.hash
end
key(name, options) click to toggle source

@see Base#key

# 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) click to toggle source

@see Base#mtime

# 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
to_s() click to toggle source

@see Base#to_s

# File lib/sass/importers/filesystem.rb, line 44
def to_s
  @root
end

Protected Instance Methods

escape_glob_characters(name) click to toggle source
# File lib/sass/importers/filesystem.rb, line 96
def escape_glob_characters(name)
  name.gsub(/[\*\[\]\{\}\?]/) do |char|
    "\\#{char}"
  end
end
extensions() click to toggle source

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.

@return [{String => Symbol}]

# File lib/sass/importers/filesystem.rb, line 75
def extensions
  {'sass' => :sass, 'scss' => :scss}
end
find_real_file(dir, name) click to toggle source

Given a base directory and an `@import`ed name, finds an existant file that matches the name.

@param dir [String] The directory relative to which to search. @param name [String] The filename to search for. @return [(String, Symbol)] A filename-syntax pair.

# 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
possible_files(name) click to toggle source

Given an `@import`ed path, returns an array of possible on-disk filenames and their corresponding syntaxes for that path.

@param name [String] The filename. @return [Array(String, Symbol)] An array of pairs.

The first element of each pair is a filename to look for;
the second element is the syntax that file would be in (`:sass` or `:scss`).
# 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) click to toggle source

If a full uri is passed, this removes the root from it otherwise returns the name unchanged

# 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) click to toggle source

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.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.