Class: SassC::Rails::Importer

Inherits:
Importer
  • Object
show all
Defined in:
lib/sassc/rails/importer.rb

Defined Under Namespace

Classes: CSSExtension, CssSassExtension, CssScssExtension, ERBExtension, Extension, SassERBExtension

Constant Summary collapse

EXTENSIONS =
[
  CssScssExtension.new,
  CssSassExtension.new,
  SassERBExtension.new,
  ERBExtension.new(".scss.erb"),
  ERBExtension.new(".css.erb"),
  Extension.new(".scss"),
  Extension.new(".sass"),
  CSSExtension.new
].freeze
PREFIXS =
[ "", "_" ]
GLOB =
/(\A|\/)(\*|\*\*\/\*)\z/

Instance Method Summary collapse

Instance Method Details

#imports(path, parent_path) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/sassc/rails/importer.rb', line 89

def imports(path, parent_path)
  parent_dir, _ = File.split(parent_path)
  specified_dir, specified_file = File.split(path)

  if m = path.match(GLOB)
    path = path.sub(m[0], "")
    base = File.expand_path(path, File.dirname(parent_path))
    return glob_imports(base, m[2], parent_path)
  end

  search_paths = ([parent_dir] + load_paths).uniq

  if specified_dir != "."
    search_paths.map! do |path|
      File.join(path, specified_dir)
    end
    search_paths.select! do |path|
      File.directory?(path)
    end
  end

  search_paths.each do |search_path|
    PREFIXS.each do |prefix|
      file_name = prefix + specified_file

      EXTENSIONS.each do |extension|
        try_path = File.join(search_path, file_name + extension.postfix)
        if File.exist?(try_path)
          record_import_as_dependency try_path
          return extension.import_for(try_path, parent_dir, options)
        end
      end
    end
  end

  SassC::Importer::Import.new(path)
end