Class: Nanoc::Filters::SassCommon::Importer Private

Inherits:
Sass::Importers::Filesystem
  • Object
show all
Defined in:
lib/nanoc/filters/sass/importer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Importer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Importer.



8
9
10
11
# File 'lib/nanoc/filters/sass/importer.rb', line 8

def initialize(filter)
  @filter = filter
  super('.')
end

Instance Attribute Details

#filterObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/nanoc/filters/sass/importer.rb', line 6

def filter
  @filter
end

Class Method Details

.raw_filename_to_item_map_for_config(config, items) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nanoc/filters/sass/importer.rb', line 65

def self.raw_filename_to_item_map_for_config(config, items)
  @raw_filename_to_item_map ||= {}
  @raw_filename_to_item_map[config.object_id] ||=
    {}.tap do |map|
      items.each do |item|
        filename_without_registering_dependency = item._unwrap.content.filename
        if filename_without_registering_dependency
          path = Pathname.new(filename_without_registering_dependency).realpath.to_s
          map[path] = item
        end
      end
    end
end

Instance Method Details

#find(identifier, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nanoc/filters/sass/importer.rb', line 35

def find(identifier, options)
  items = filter.items.find_all(identifier)
  return if items.empty?

  content, syntax = import(items)

  options[:syntax] = syntax
  options[:filename] = identifier.to_s
  options[:importer] = self
  ::Sass::Engine.new(content, options)
end

#find_relative(name, base_identifier, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nanoc/filters/sass/importer.rb', line 13

def find_relative(name, base_identifier, options)
  base_raw_filename = filter.items[base_identifier].raw_filename

  # we can't resolve a relative filename from an in-memory item
  return unless base_raw_filename

  raw_filename, syntax = ::Sass::Util.destructure(find_real_file(File.dirname(base_raw_filename), name, options))
  return unless raw_filename

  item = raw_filename_to_item(raw_filename)

  content = item ? item.raw_content : File.read(raw_filename)
  filename = item ? item.identifier.to_s : raw_filename

  filter.depend_on([item]) if item

  options[:syntax] = syntax
  options[:filename] = filename
  options[:importer] = self
  ::Sass::Engine.new(content, options)
end

#key(identifier, _options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/nanoc/filters/sass/importer.rb', line 47

def key(identifier, _options)
  [self.class.name + ':' + root, identifier.to_s]
end

#public_url(identifier, _sourcemap_directory) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
54
55
56
57
58
59
# File 'lib/nanoc/filters/sass/importer.rb', line 51

def public_url(identifier, _sourcemap_directory)
  path = filter.items[identifier].path
  return path unless path.nil?

  raw_filename = filter.items[identifier].raw_filename
  return if raw_filename.nil?

  ::Sass::Util.file_uri_from_path(raw_filename)
end

#raw_filename_to_item(filename) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
83
84
# File 'lib/nanoc/filters/sass/importer.rb', line 79

def raw_filename_to_item(filename)
  realpath = Pathname.new(filename).realpath.to_s

  map = self.class.raw_filename_to_item_map_for_config(filter.config, filter.items)
  map[realpath]
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
# File 'lib/nanoc/filters/sass/importer.rb', line 61

def to_s
  'Nanoc Sass Importer'
end