Class: Stylist::Processors::LessProcessor
- Inherits:
-
Processor
- Object
- Processor
- Stylist::Processors::LessProcessor
show all
- Defined in:
- lib/stylist/processors/less_processor.rb
Class Method Summary
collapse
Methods inherited from Processor
configuration, expand_stylesheet_sources
Class Method Details
7
8
9
|
# File 'lib/stylist/processors/less_processor.rb', line 7
def configure
configuration.add_option_group :less, { :source_path => ::Rails.root.join('app/stylesheets'), :compress => true }
end
|
.process!(collection) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/stylist/processors/less_processor.rb', line 11
def process!(collection)
stylesheets_to_process(collection).each do |stylesheet|
source_path = source_path_for(stylesheet)
if source_path && source_path.exist?
engine = File.open(source_path) {|f| ::Less::Engine.new(f) }
css = engine.to_css
css.delete!("\n") if configuration.less.compress
File.open(stylesheet, "w") { |f| f.puts css }
end
end
end
|
.source_has_been_changed?(file) ⇒ Boolean
34
35
36
37
|
# File 'lib/stylist/processors/less_processor.rb', line 34
def source_has_been_changed?(file)
source_path = source_path_for(file)
source_path && (File.new(source_path).mtime >= File.new(file).mtime)
end
|
.source_path_for(file) ⇒ Object
24
25
26
|
# File 'lib/stylist/processors/less_processor.rb', line 24
def source_path_for(file)
Pathname.glob(File.join(configuration.less.source_path, File.basename(file, '.css')+'.{css,less,lss}'))[0]
end
|
.stylesheets_to_process(collection) ⇒ Object
28
29
30
31
32
|
# File 'lib/stylist/processors/less_processor.rb', line 28
def stylesheets_to_process(collection)
expand_stylesheet_sources(collection.values.flatten).select do |file|
(File.exists?(file) and source_has_been_changed?(file)) or not File.exists?(file)
end
end
|