Class: Rake::Pipeline::Web::Filters::SassCompiler

Inherits:
Filter
  • Object
show all
Defined in:
lib/rake-pipeline-web-filters/sass_compiler.rb

Overview

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

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::SassCompiler
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SassCompiler.

Parameters:

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

    options to pass to the Sass compiler

  • block (Proc)

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

Options Hash (options):

  • :additional_load_paths (Array)

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



30
31
32
33
34
35
36
37
# File 'lib/rake-pipeline-web-filters/sass_compiler.rb', line 30

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.



22
23
24
# File 'lib/rake-pipeline-web-filters/sass_compiler.rb', line 22

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:

  • inputs (Array<FileWrapper>)

    an Array of FileWrapper objects representing the inputs to this filter.

  • output (FileWrapper)

    a single FileWrapper object representing the output.



47
48
49
50
51
# File 'lib/rake-pipeline-web-filters/sass_compiler.rb', line 47

def generate_output(inputs, output)
  inputs.each do |input|
    output.write Sass.compile(input.read, options)
  end
end