Class: Rake::Pipeline::Web::Filters::SassFilter

Inherits:
Filter
  • Object
show all
Includes:
FilterWithDependencies
Defined in:
lib/rake-pipeline-web-filters/sass_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

Instance Method Summary collapse

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 #output_name_generator.

Options Hash (options):

  • :additional_load_paths (Array)

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


34
35
36
37
38
39
40
41
42
# File 'lib/rake-pipeline-web-filters/sass_filter.rb', line 34

def initialize(options={}, &block)
  block ||= proc { |input| input.sub(/\.(scss|sass)$/, '.css') }
  super(&block)

  @options = compass_options
  @additional_load_paths = Array(options.delete(:additional_load_paths))
  @options[:load_paths].concat(@additional_load_paths)
  @options.merge!(options)
end

Instance Attribute Details

#additional_load_pathsHash (readonly)

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

Returns:

  • (Hash)

    a hash of options to pass to Sass when compiling.


26
27
28
# File 'lib/rake-pipeline-web-filters/sass_filter.rb', line 26

def additional_load_paths
  @additional_load_paths
end

#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.


26
27
28
# File 'lib/rake-pipeline-web-filters/sass_filter.rb', line 26

def options
  @options
end

Instance Method Details

#additional_dependencies(input) ⇒ Object


58
59
60
61
# File 'lib/rake-pipeline-web-filters/sass_filter.rb', line 58

def additional_dependencies(input)
  engine = Sass::Engine.new(input.read, sass_options_for_file(input))
  engine.dependencies.map { |dep| dep.options[:filename] }
end

#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.


52
53
54
55
56
# File 'lib/rake-pipeline-web-filters/sass_filter.rb', line 52

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