Class: HtmlMockup::Release::Processors::Sass

Inherits:
Base
  • Object
show all
Defined in:
lib/html_mockup/release/processors/sass.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from HtmlMockup::Release::Processors::Base

Instance Method Details

#call(release, options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    Options as described below, all other options will be passed to Sass.compile_file.

Options Hash (options):

  • :match (Array)

    An array of shell globs, defaults to [“stylesheets/*/.scss”]

  • :skip (Array)

    An array of regexps which will be skipped, defaults to [/_.*.scssZ/], Attention! Skipped files will be deleted as well!



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/html_mockup/release/processors/sass.rb', line 10

def call(release, options={})
  options = {
    :match => ["stylesheets/**/*.scss"],
    :skip => [/\/_.*\.scss\Z/],
    :style => :expanded
  }.update(options)
  
  match = options.delete(:match)
  skip = options.delete(:skip)
  
  unless options.has_key?(:load_paths)
    if ::Sass::Plugin.options[:template_location].kind_of?(Hash)
      options[:load_paths] = ::Sass::Plugin.template_location_array.map{|k,v| k }
    else
      options[:load_paths] = [(release.build_path + "stylesheets").to_s]
    end
  end
  
  # Sassify SCSS files
  files = release.get_files(match)
  files.each do |f|
    if !skip.detect{|r| r.match(f) }
      release.log(self, "Processing: #{f}")          
      # Compile SCSS
      ::Sass.compile_file(f, f.gsub(/\.scss$/, ".css"), options)
    end        
  end
  
  # Cleanup
  files.each do |f|
    # Remove source file
    File.unlink(f)
  end
  
end