class Sass::Importers::Filesystem

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

def _find(dir, name, options)

def _find(dir, name, options)
  full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
  return unless full_filename && File.readable?(full_filename)
  options[:syntax] = syntax
  options[:filename] = full_filename
  options[:importer] = self
  Sass::Engine.new(File.read(full_filename), options)
end

def directories_to_watch

Other tags:
    See: Base#directories_to_watch -
def directories_to_watch
  [root]
end

def eql?(other)

def eql?(other)
  root.eql?(other.root)
end

def escape_glob_characters(name)

def escape_glob_characters(name)
  name.gsub(/[\*\[\]\{\}\?]/) do |char|
    "\\#{char}"
  end
end

def extensions

Returns:
  • ({String => Symbol}) -
def extensions
  {'sass' => :sass, 'scss' => :scss}
end

def find(name, options)

Other tags:
    See: Base#find -
def find(name, options)
  _find(@root, name, options)
end

def find_real_file(dir, name, options)

Returns:
  • ((String, Symbol)) - A filename-syntax pair.

Parameters:
  • name (String) -- The filename to search for.
  • dir (String) -- The directory relative to which to search.
def find_real_file(dir, name, options)
  # on windows 'dir' can be in native File::ALT_SEPARATOR form
  dir = dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
  found = possible_files(remove_root(name)).map do |f, s|
    path = (dir == "." || Sass::Util.pathname(f).absolute?) ? f :
      "#{escape_glob_characters(dir)}/#{f}"
    Dir[path].map do |full_path|
      full_path.gsub!(REDUNDANT_DIRECTORY, File::SEPARATOR)
      [Sass::Util.cleanpath(full_path).to_s, s]
    end
  end
  found = Sass::Util.flatten(found, 1)
  return if found.empty?
  if found.size > 1 && !@same_name_warnings.include?(found.first.first)
    found.each {|(f, _)| @same_name_warnings << f}
    relative_to = Sass::Util.pathname(dir)
    if options[:_from_import_node]
      # If _line exists, we're here due to an actual import in an
      # import_node and we want to print a warning for a user writing an
      # ambiguous import.
      candidates = found.map do |(f, _)|
        "  " + Sass::Util.pathname(f).relative_path_from(relative_to).to_s
      end.join("\n")
      raise Sass::SyntaxError.new(<<MESSAGE)
ot clear which file to import for '@import "#{name}"'.
ates:
idates}
 delete or rename all but one of these files.
E
    else
      # Otherwise, we're here via StalenessChecker, and we want to print a
      # warning for a user running `sass --watch` with two ambiguous files.
      candidates = found.map {|(f, _)| "    " + File.basename(f)}.join("\n")
      Sass::Util.sass_warn <<WARNING
G: In #{File.dirname(name)}:
e are multiple files that match the name "#{File.basename(name)}":
idates}
G
    end
  end
  found.first
end

def find_relative(name, base, options)

Other tags:
    See: Base#find_relative -
def find_relative(name, base, options)
  _find(File.dirname(base), name, options)
end

def hash

def hash
  @root.hash
end

def initialize(root)

Parameters:
  • root (String) -- The root path.
def initialize(root)
  @root = File.expand_path(root)
  @same_name_warnings = Set.new
end

def key(name, options)

Other tags:
    See: Base#key -
def key(name, options)
  [self.class.name + ":" + File.dirname(File.expand_path(name)),
   File.basename(name)]
end

def mtime(name, options)

Other tags:
    See: Base#mtime -
def mtime(name, options)
  file, _ = Sass::Util.destructure(find_real_file(@root, name, options))
  File.mtime(file) if file
rescue Errno::ENOENT
  nil
end

def possible_files(name)

Returns:
  • (Array(String, Symbol)) - An array of pairs.

Parameters:
  • name (String) -- The filename.
def possible_files(name)
  name = escape_glob_characters(name)
  dirname, basename, extname = split(name)
  sorted_exts = extensions.sort
  syntax = extensions[extname]
  if syntax
    ret = [["#{dirname}/{_,}#{basename}.#{extensions.invert[syntax]}", syntax]]
  else
    ret = sorted_exts.map {|ext, syn| ["#{dirname}/{_,}#{basename}.#{ext}", syn]}
  end
  # JRuby chokes when trying to import files from JARs when the path starts with './'.
  ret.map {|f, s| [f.sub(/^\.\//, ''), s]}
end

def public_url(name, sourcemap_directory = nil)

def public_url(name, sourcemap_directory = nil)
  if sourcemap_directory.nil?
    warn_about_public_url(name)
  else
    file_pathname = Sass::Util.cleanpath(Sass::Util.absolute_path(name, @root))
    sourcemap_pathname = Sass::Util.cleanpath(sourcemap_directory)
    begin
      file_pathname.relative_path_from(sourcemap_pathname).to_s
    rescue ArgumentError # when a relative path cannot be constructed
      warn_about_public_url(name)
      nil
    end
  end
end

def remove_root(name)

otherwise returns the name unchanged
If a full uri is passed, this removes the root from it
def remove_root(name)
  if name.index(@root + "/") == 0
    name[(@root.length + 1)..-1]
  else
    name
  end
end

def split(name)

Only the known extensions returned from the extensions method will be recognized as such.
Splits a filename into three parts, a directory part, a basename, and an extension
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

def to_s

Other tags:
    See: Base#to_s -
def to_s
  @root
end

def warn_about_public_url(uri)

Returns:
  • (NilClass) - nil

Parameters:
  • uri (String) -- A URI known to be valid for this importer.
def warn_about_public_url(uri)
  @warnings_issued ||= Set.new
  unless @warnings_issued.include?(uri)
    Sass::Util.sass_warn <<WARNING
G: Couldn't determine public URL for "#{uri}" while generating sourcemap.
out a public URL, there's nothing for the source map to link to.
G
    @warnings_issued << uri
  end
  nil
end

def watched_file?(filename)

Other tags:
    See: Base#watched_file? -
def watched_file?(filename)
  filename =~ /\.s[ac]ss$/ &&
    filename.start_with?(root + File::SEPARATOR)
end