class Sprockets::SassImporter - sass-rails-4.0.4 Documentation

# class Sprockets::SassImporter

### Constants

GLOB

### Attributes

context[R]

### Public Instance Methods

each_globbed_file(glob, base_pathname, options) { |filename| ... } click to toggle source

    # File lib/sass/rails/importer.rb, line 39
    def each_globbed_file(glob, base_pathname, options)
      Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
        next if filename == options[:filename]
        yield filename if File.directory?(filename) || context.asset_requirable?(filename)
      end
    end

extensions() click to toggle source
Calls superclass method

    # File lib/sass/rails/importer.rb, line 10
    def extensions
      {
        'css'          => :scss,
        'css.scss'     => :scss,
        'css.sass'     => :sass,
        'css.erb'      => :scss,
        'scss.erb'     => :scss,
        'sass.erb'     => :sass,
        'css.scss.erb' => :scss,
        'css.sass.erb' => :sass
      }.merge!(super)
    end

find(name, options) click to toggle source

    # File lib/sass/rails/importer.rb, line 31
    def find(name, options)
      if name =~ GLOB
        nil # globs must be relative
      else
        engine_from_path(name, root, options)
      end
    end

find_relative(name, base, options) click to toggle source

    # File lib/sass/rails/importer.rb, line 23
    def find_relative(name, base, options)
      if name =~ GLOB
        glob_imports(name, Pathname.new(base), options)
      else
        engine_from_path(name, File.dirname(base), options)
      end
    end

glob_imports(glob, base_pathname, options) click to toggle source

    # File lib/sass/rails/importer.rb, line 46
    def glob_imports(glob, base_pathname, options)
      contents = ""
      each_globbed_file(glob, base_pathname.dirname, options) do |filename|
        if File.directory?(filename)
          depend_on(filename)
        elsif context.asset_requirable?(filename)
          depend_on(filename)
          contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
        end
      end
      return nil if contents.empty?
      Sass::Engine.new(contents, options.merge(
        :filename => base_pathname.to_s,
        :importer => self,
        :syntax => :scss
      ))
    end

### Private Instance Methods

depend_on(filename) click to toggle source

    # File lib/sass/rails/importer.rb, line 66
    def depend_on(filename)
      context.depend_on(filename)
      context.depend_on(globbed_file_parent(filename))
    end

engine_from_path(name, dir, options) click to toggle source

    # File lib/sass/rails/importer.rb, line 79
    def engine_from_path(name, dir, options)
      full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
      return unless full_filename && File.readable?(full_filename)

      engine = Sass::Engine.new(evaluate(full_filename), options.merge(
        syntax: syntax,
        filename: full_filename,
        importer: self
      ))

      if engine && (filename = engine.options[:filename])
        @context.depend_on(filename)
      end

      engine
    end

evaluate(filename) click to toggle source

    # File lib/sass/rails/importer.rb, line 96
    def evaluate(filename)
      attributes = context.environment.attributes_for(filename)
      processors = context.environment.preprocessors(attributes.content_type) +
        attributes.engines.reverse - [Sprockets::ScssTemplate, Sprockets::SassTemplate]

      context.evaluate(filename, processors: processors)
    end

globbed_file_parent(filename) click to toggle source

    # File lib/sass/rails/importer.rb, line 71
    def globbed_file_parent(filename)
      if File.directory?(filename)
        File.expand_path('..', filename)
      else
        File.dirname(filename)
      end
    end