Class: Less::Rails::ImportProcessor

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/less/rails/import_processor.rb

Constant Summary collapse

IMPORT_SCANNER =
/@import\s*['"]([^'"]+)['"]\s*;/.freeze
PATHNAME_FINDER =
Proc.new { |scope, path| 
  begin
    scope.resolve(path)
  rescue Sprockets::FileNotFound
    nil
  end
}

Instance Method Summary collapse

Instance Method Details

#depend_on(scope, data, base = File.dirname(scope.logical_path)) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/less/rails/import_processor.rb', line 22

def depend_on(scope, data, base=File.dirname(scope.logical_path))
  import_paths = data.scan(IMPORT_SCANNER).flatten.compact.uniq
  import_paths.each do |path|
    pathname = PATHNAME_FINDER.call(scope,path) || PATHNAME_FINDER.call(scope, File.join(base, path))
    scope.depend_on(pathname) if pathname && pathname.to_s.ends_with?('.less')
    depend_on scope, File.read(pathname), File.dirname(path) if pathname
  end
  data
end

#evaluate(scope, locals, &block) ⇒ Object



17
18
19
20
# File 'lib/less/rails/import_processor.rb', line 17

def evaluate(scope, locals, &block)
  depend_on scope, data
  data
end

#prepareObject



14
15
# File 'lib/less/rails/import_processor.rb', line 14

def prepare
end