Class: Rake::Pipeline::Web::Filters::StylusFilter

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

Overview

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

Requires rubygems.org/gems/stylus

You will need the `node` command on your runtime for this to work. See github.com/lucasmazza/ruby-stylus for more information.

Examples:

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of StylusFilter

Parameters:

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

    options to pass to Stylus

  • block (Proc)

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

Options Hash (options):

  • :use (Array)

    Plugins to import from Node

  • :debug (Boolean)

    Output debug info


33
34
35
36
37
# File 'lib/rake-pipeline-web-filters/stylus_filter.rb', line 33

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


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

def options
  @options
end

Instance Method Details

#generate_output(inputs, output) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rake-pipeline-web-filters/stylus_filter.rb', line 39

def generate_output(inputs, output)
  options.each do |key, value|
    if key == :use
      Stylus.send key, *value
      next
    end
    Stylus.send "#{key}=", value
  end
  inputs.each do |input|
    output.write Stylus.compile(input.read)
  end
end