Class: Extruder::SassFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/extruder/filters/concat_filter.rb

Overview

A filter that compiles input files written in SCSS to CSS using the Sass compiler and the Compass CSS framework.

Requires sass and compass

Examples:

Rake::Pipeline.build do
  input "app/assets", "**/*.scss"
  output "public"

  # Compile each SCSS file under the app/assets
  # directory.
  filter Rake::Pipeline::Web::Filters::SassFilter
end

Instance Attribute Summary collapse

Attributes inherited from Filter

#files, #output_name_generator, #output_root

Instance Method Summary collapse

Methods inherited from Filter

#outputs, #process, processes_binary_files

Constructor Details

#initialize(options = {}, &block) ⇒ SassFilter

Returns a new instance of SassFilter.

Parameters:

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

    options to pass to the Sass compiler

  • block (Proc)

    a block to use as the Filter’s Filter#output_name_generator.

Options Hash (options):

  • :additional_load_paths (Array)

    a list of paths to append to Sass’s :load_path.



105
106
107
108
109
110
111
112
# File 'lib/extruder/filters/concat_filter.rb', line 105

def initialize(options={}, &block)
  block ||= proc { |input| input.sub(/\.(scss|sass)$/, '.css') }
  super(&block)
  Compass.add_project_configuration
  @options = Compass.configuration.to_sass_engine_options
  @options[:load_paths].concat(Array(options.delete(:additional_load_paths)))
  @options.merge!(options)
end

Instance Attribute Details

#optionsHash (readonly)

Returns a hash of options to pass to Sass when compiling.

Returns:

  • (Hash)

    a hash of options to pass to Sass when compiling.



97
98
99
# File 'lib/extruder/filters/concat_filter.rb', line 97

def options
  @options
end

Instance Method Details

#generate_output(inputs, output) ⇒ Object

Implement the #generate_output method required by the Filter API. Compiles each input file with Sass.

Parameters:



122
123
124
125
126
127
128
129
130
131
# File 'lib/extruder/filters/concat_filter.rb', line 122

def generate_output(inputs, output)
  inputs.each do |input|
    sass_opts = if input.path.match(/\.sass$/)
      options.merge(:syntax => :sass)
    else
      options
    end
    output.write Sass.compile(input.read, sass_opts)
  end
end