/usr/lib/ruby/vendor_ruby/compass/import-once/importer.rb is in ruby-compass-import-once 1.0.5~dfsg-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | module Compass
module ImportOnce
# Any importer object that is extended with this module will get the import once behavior.
module Importer
def find_relative(uri, base, options, *args)
uri, force_import = handle_force_import(uri)
maybe_replace_with_dummy_engine(super(uri, base, options, *args), options, force_import)
end
def find(uri, options, *args)
uri, force_import = handle_force_import(uri)
maybe_replace_with_dummy_engine(super(uri, options, *args), options, force_import)
end
def key(uri, options, *args)
if uri =~ /^\(NOT IMPORTED\) (.*)$/
["(import-once)", $1]
else
super
end
end
def mtime(uri, options, *args)
if uri =~ /^\(NOT IMPORTED\) (.*)$/
File.mtime($1) if File.exist?($1)
else
super
end
end
protected
# any uri that ends with an exclamation mark will be forced to import
def handle_force_import(uri)
if uri.end_with?("!")
[uri[0...-1], true]
else
[uri, false]
end
end
def maybe_replace_with_dummy_engine(engine, options, force_import)
if engine && !force_import && imported?(engine, options)
engine = dummy_engine(engine, options)
elsif engine
imported!(engine, options)
end
engine
end
def tracker(options)
Compass::ImportOnce.import_tracker[options[:css_filename]] ||= Set.new
end
# Giant hack to support sass-globbing.
# Need to find a better fix.
def normalize_filesystem_importers(key)
key.map do |part|
part.sub(/Glob:/, 'Sass::Importers::Filesystem:')
end
end
def import_tracker_key(engine, options)
normalize_filesystem_importers(key(engine.options[:filename], options)).join("|").freeze
end
def dummy_engine(engine, options)
new_options = engine.options.merge(:filename => "(NOT IMPORTED) #{engine.options[:filename]}" )
Sass::Engine.new("", new_options)
end
def imported?(engine, options)
tracker(options).include?(import_tracker_key(engine, options))
end
def imported!(engine, options)
tracker(options) << import_tracker_key(engine, options)
end
end
end
end
|