Class: Stylist::Processors::SassProcessor
- Inherits:
-
Processor
- Object
- Processor
- Stylist::Processors::SassProcessor
show all
- Defined in:
- lib/stylist/processors/sass_processor.rb
Class Method Summary
collapse
Methods inherited from Processor
configuration, expand_stylesheet_sources
Class Method Details
6
7
8
|
# File 'lib/stylist/processors/sass_processor.rb', line 6
def configure
configuration.add_option_group :sass, { :source_path => ::Rails.root.join('app/stylesheets'), :compress => true }
end
|
.process!(collection) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/stylist/processors/sass_processor.rb', line 10
def process!(collection)
stylesheets_to_process(collection).each do |stylesheet|
source_path = source_path_for(stylesheet)
if source_path && source_path.exist?
puts "Processing #{source_path}..."
engine = File.open(source_path) {|f| ::Sass::Engine.new(f.read, :syntax => syntax_from_source_path(source_path)) }
css = engine.to_css
css.delete!("\n") if configuration.sass.compress
File.open(stylesheet, "w") { |f| f.puts css }
end
end
end
|
.source_has_been_changed?(file) ⇒ Boolean
37
38
39
40
|
# File 'lib/stylist/processors/sass_processor.rb', line 37
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
23
24
25
|
# File 'lib/stylist/processors/sass_processor.rb', line 23
def source_path_for(file)
Pathname.glob(File.join(configuration.sass.source_path, File.basename(file, '.css')+'.s[ac]ss'))[0]
end
|
.stylesheets_to_process(collection) ⇒ Object
31
32
33
34
35
|
# File 'lib/stylist/processors/sass_processor.rb', line 31
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
|
.syntax_from_source_path(path) ⇒ Object
27
28
29
|
# File 'lib/stylist/processors/sass_processor.rb', line 27
def syntax_from_source_path(path)
path.to_s.ends_with?('.scss') ? :scss : :sass
end
|