Class: Rake::Pipeline::Web::Filters::LessFilter

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

Overview

A filter that compiles input files written in Less to CSS using the Less compiler.

Requires less-js

Examples:

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

  # Compile each less file with Less.js
  filter Rake::Pipeline::Web::Filters::LessFilter
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, context = nil, &block) ⇒ LessFilter

Returns a new instance of LessFilter

Parameters:

  • block (Proc)

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


27
28
29
30
31
# File 'lib/rake-pipeline-web-filters/less_filter.rb', line 27

def initialize(options={}, context = nil, &block)
  block ||= proc { |input| input.sub(/\.less$/, '.css') }
  super(&block)
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

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

Returns:

  • (Hash)

    a hash of options to pass to Less when compiling.


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

def options
  @options
end

Instance Method Details

#external_dependenciesObject


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

def external_dependencies
  [ 'less' ]
end

#generate_output(inputs, output) ⇒ Object

Implement the #generate_output method required by the Filter API. Attempts to compile each input file with LessJs.

Parameters:

  • inputs (Array<FileWrapper>)

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

  • output (FileWrapper)

    a single FileWrapper object representing the output.


42
43
44
45
46
47
# File 'lib/rake-pipeline-web-filters/less_filter.rb', line 42

def generate_output(inputs, output)
  parser = Less::Parser.new options
  inputs.each do |input|
    output.write parser.parse(input.read).to_css
  end
end