Module: Compass::ImportOnce::Importer

### Home Classes Methods

### In Files

- lib/compass/import-once/importer.rb

### Methods

- #dummy_engine
- #find
- #find_relative
- #handle_force_import
- #import_tracker_key
- #imported!
- #imported?
- #key
- #maybe_replace_with_dummy_engine
- #mtime
- #normalize_filesystem_importers
- #tracker

### Class/Module Index

Quicksearch

- Compass
- Compass::ImportOnce
- Compass::ImportOnce::Engine
- Compass::ImportOnce::Importer
- Sass
- Sass::Engine

No matching classes.

# Compass::ImportOnce::Importer

Any importer object that is extended with this module will get the import once behavior.

### Public Instance Methods

find(uri, options, *args) click to toggle source

    # File lib/compass/import-once/importer.rb, line 10
    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

find_relative(uri, base, options, *args) click to toggle source

    # File lib/compass/import-once/importer.rb, line 5
    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

key(uri, options, *args) click to toggle source

    # File lib/compass/import-once/importer.rb, line 15
    def key(uri, options, *args)
      if uri =~ /^\(NOT IMPORTED\) (.*)$/
        ["(import-once)", $1]
      else
        super
      end
    end

mtime(uri, options, *args) click to toggle source

    # File lib/compass/import-once/importer.rb, line 23
    def mtime(uri, options, *args)
      if uri =~ /^\(NOT IMPORTED\) (.*)$/
        File.mtime($1) if File.exist?($1)
      else
        super
      end
    end

### Protected Instance Methods

dummy_engine(engine, options) click to toggle source

    # File lib/compass/import-once/importer.rb, line 67
    def dummy_engine(engine, options)
      new_options = engine.options.merge(:filename => "(NOT IMPORTED) #{engine.options[:filename]}" )
      Sass::Engine.new("", new_options)
    end

handle_force_import(uri) click to toggle source

any uri that ends with an exclamation mark will be forced to import

    # File lib/compass/import-once/importer.rb, line 34
    def handle_force_import(uri)
      if uri.end_with?("!")
        [uri[0...-1], true]
      else
        [uri, false]
      end
    end

import_tracker_key(engine, options) click to toggle source

    # File lib/compass/import-once/importer.rb, line 63
    def import_tracker_key(engine, options)
      normalize_filesystem_importers(key(engine.options[:filename], options)).join("|").freeze
    end

imported!(engine, options) click to toggle source

    # File lib/compass/import-once/importer.rb, line 76
    def imported!(engine, options)
      tracker(options) << import_tracker_key(engine, options)
    end

imported?(engine, options) click to toggle source

    # File lib/compass/import-once/importer.rb, line 72
    def imported?(engine, options)
      tracker(options).include?(import_tracker_key(engine, options))
    end

maybe_replace_with_dummy_engine(engine, options, force_import) click to toggle source

    # File lib/compass/import-once/importer.rb, line 42
    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

normalize_filesystem_importers(key) click to toggle source

Giant hack to support sass-globbing. Need to find a better fix.

    # File lib/compass/import-once/importer.rb, line 57
    def normalize_filesystem_importers(key)
      key.map do |part|
        part.sub(/Glob:/, 'Sass::Importers::Filesystem:')
      end
    end

tracker(options) click to toggle source

    # File lib/compass/import-once/importer.rb, line 51
    def tracker(options)
       Compass::ImportOnce.import_tracker[options[:css_filename]] ||= Set.new
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.