Class: Sass::Importers::Filesystem

Inherits:
Base
  • Object
show all
Defined in:
.ruby-sass/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.

Direct Known Subclasses

DeprecatedPath

Direct Known Subclasses

DeprecatedPath

Constant Summary

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

#initialize(root) ⇒ Filesystem

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

Parameters:

  • root (String)

    The root path. This importer will import files relative to this path.



14
15
16
17
18
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 14

def initialize(root)
  @root = File.expand_path(root)
  @real_root = Sass::Util.realpath(@root).to_s
  @same_name_warnings = Set.new
end

Constructor Details

#initialize(root) ⇒ Filesystem

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

Parameters:

  • root (String)

    The root path. This importer will import files relative to this path.



14
15
16
17
18
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 14

def initialize(root)
  @root = File.expand_path(root)
  @real_root = Sass::Util.realpath(@root).to_s
  @same_name_warnings = Set.new
end

Instance Attribute Details

#rootObject

Returns the value of attribute root



8
9
10
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 8

def root
  @root
end

Instance Method Details

#directories_to_watchObject



58
59
60
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 58

def directories_to_watch
  [root]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 53

def eql?(other)
  !other.nil? && other.respond_to?(:root) && root.eql?(other.root)
end

#find(name, options) ⇒ Object

See Also:



26
27
28
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 26

def find(name, options)
  _find(@root, name, options)
end

#find_relative(name, base, options) ⇒ Object

See Also:



21
22
23
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 21

def find_relative(name, base, options)
  _find(File.dirname(base), name, options)
end

#hashObject



49
50
51
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 49

def hash
  @root.hash
end

#key(name, options) ⇒ Object

See Also:



39
40
41
42
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 39

def key(name, options)
  [self.class.name + ":" + File.dirname(File.expand_path(name)),
   File.basename(name)]
end

#mtime(name, options) ⇒ Object

See Also:



31
32
33
34
35
36
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 31

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

#public_url(name, sourcemap_directory) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 69

def public_url(name, sourcemap_directory)
  file_pathname = Sass::Util.cleanpath(File.absolute_path(name, @root))
  return Sass::Util.file_uri_from_path(file_pathname) if sourcemap_directory.nil?

  sourcemap_pathname = Sass::Util.cleanpath(sourcemap_directory)
  begin
    Sass::Util.file_uri_from_path(
      Sass::Util.relative_path_from(file_pathname, sourcemap_pathname))
  rescue ArgumentError # when a relative path cannot be constructed
    Sass::Util.file_uri_from_path(file_pathname)
  end
end

#to_sObject

See Also:



45
46
47
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 45

def to_s
  @root
end

#watched_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



63
64
65
66
67
# File '.ruby-sass/lib/sass/importers/filesystem.rb', line 63

def watched_file?(filename)
  # Check against the root with symlinks resolved, since Listen
  # returns fully-resolved paths.
  filename =~ /\.s[ac]ss$/ && filename.start_with?(@real_root + File::SEPARATOR)
end