Class: Benoit::Filters::SassFilter

Inherits:
Rake::Pipeline::Filter
  • Object
show all
Defined in:
lib/benoit/filters/sass_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SassFilter

Returns a new instance of SassFilter.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/benoit/filters/sass_filter.rb', line 15

def initialize(options={})
  load_paths = options.delete(:additional_load_paths) || []

  # TODO: Handle files that don't end in .scss
  block ||= proc { |input| input.sub(/\.(?:css\.)?(scss|sass)$/, '.css') }
  super(&block)
  Compass.add_project_configuration
  Compass.configuration.project_path ||= Dir.pwd
  @additional_load_paths = Compass.configuration.sass_load_paths
  @additional_load_paths += load_paths.map do |f|
    File.expand_path(f)
  end


  @options = options
  @options[:load_paths] ||= []
  @options[:load_paths].concat(additional_load_paths)

end

Instance Attribute Details

#additional_load_pathsObject (readonly)

Returns the value of attribute additional_load_paths.



13
14
15
# File 'lib/benoit/filters/sass_filter.rb', line 13

def additional_load_paths
  @additional_load_paths
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/benoit/filters/sass_filter.rb', line 13

def options
  @options
end

Instance Method Details

#additional_dependencies(input = nil) ⇒ Object



57
58
59
# File 'lib/benoit/filters/sass_filter.rb', line 57

def additional_dependencies(input=nil)
  Dir.glob("**/*.scss")
end

#generate_output(inputs, output) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/benoit/filters/sass_filter.rb', line 35

def generate_output(inputs, output)
  inputs.each do |input|
    begin
      sass_options = sass_options_for_file(input).merge(filename: input.path)
      sass_engine = Sass::Engine.for_file(input.fullpath, sass_options)
      output.write sass_engine.render
    rescue Sass::SyntaxError => ex
      path = ex.sass_filename.gsub(input.root + "/", "")
      missing_files = ex.message.scan(/File to import not found or unreadable: ([\w\-]*)\./).flatten
      if missing_files.empty?
        error = Benoit::CompilerError.new(nil, path, ex)
        error.line = ex.sass_line
      else
        error = Benoit::FileMissingError.new(missing_files.first, ex.sass_line, path, ex)
      end
      raise error
    rescue StandardError => ex
      raise Benoit::CompilerError.new(nil, path, ex)
    end
  end
end