module Sass::Rails::SassImporter::Globbing - sass-rails-5.0.3 Documentation

# module Sass::Rails::SassImporter::Globbing

### Constants

GLOB

### Public Instance Methods

find(name, options) click to toggle source
Calls superclass method

    # File lib/sass/rails/importer.rb, line 22
    def find(name, options)
      # globs must be relative
      return if name =~ GLOB
      super
    end

find_relative(name, base, options) click to toggle source
Calls superclass method

    # File lib/sass/rails/importer.rb, line 12
    def find_relative(name, base, options)
      if options[:sprockets] && m = name.match(GLOB)
        path = name.sub(m[0], "")
        base = File.expand_path(path, File.dirname(base))
        glob_imports(base, m[2], options)
      else
        super
      end
    end

### Private Instance Methods

each_globbed_file(base, glob, context) { |path| ... } click to toggle source

    # File lib/sass/rails/importer.rb, line 44
    def each_globbed_file(base, glob, context)
      raise ArgumentError unless glob == "*" || glob == "**/*"

      exts = extensions.keys.map { |ext| Regexp.escape(".#{ext}") }.join("|")
      sass_re = Regexp.compile("(#{exts})$")

      context.depend_on(base)

      Dir["#{base}/#{glob}"].sort.each do |path|
        if File.directory?(path)
          context.depend_on(path)
        elsif sass_re =~ path
          yield path
        end
      end
    end

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

    # File lib/sass/rails/importer.rb, line 29
    def glob_imports(base, glob, options)
      contents = ""
      context = options[:sprockets][:context]
      each_globbed_file(base, glob, context) do |filename|
        next if filename == options[:filename]
        contents << "@import #{filename.inspect};\n"
      end
      return nil if contents == ""
      Sass::Engine.new(contents, options.merge(
        :filename => base,
        :importer => self,
        :syntax => :scss
      ))
    end