Browse files

Merge pull request #1 from arcresu/less

Less template and `Less::Parser#imports`
  • Loading branch information...
2 parents 64f99fc + 08610fc commit 72b8d93a9b48e187188826dac8caac52dfd835e7 @guilleiguaran committed Jul 5, 2012
Showing with 8 additions and 15 deletions.
  1. +8 −15 lib/sprockets/less_template.rb
View
23 lib/sprockets/less_template.rb
@@ -4,17 +4,16 @@ module Sprockets
class LessTemplate < Tilt::Template
self.default_mime_type = 'text/css'
- IMPORT_SCANNER = /@import\s*['"]([^'"]+)['"]\s*;/.freeze
-
def self.engine_initialized?
- defined? ::Less
+ defined?(::Less)
end
def initialize_engine
require_template_library 'less'
end
def prepare
+ nil
end
def evaluate(context, locals, &block)
@@ -24,21 +23,15 @@ def evaluate(context, locals, &block)
:paths => context.environment.paths
}
::Less.Parser['scope'] = context
- depend_on(context, data)
- ::Less::Parser.new(options).parse(data).to_css
+ parser = ::Less::Parser.new(options)
+ parser.imports.each do |path|
+ pathname = context.resolve(path) rescue nil
+ context.depend_on(path) unless path.nil?
+ end
+ parser.parse(data).to_css
rescue ::Less::ParseError => e
context.__LINE__ = e.line
raise e
end
-
- protected
- def depend_on(context, data)
- import_paths = data.scan(IMPORT_SCANNER).flatten.compact.uniq
- import_paths.each do |path|
- pathname = context.resolve(path) rescue nil
- context.depend_on(path) if pathname && pathname.to_s =~ /.less$/
- depend_on context, File.read(pathname) if pathname
- end
- end
end
end

0 comments on commit 72b8d93

Please sign in to comment.