Class: Rake::Pipeline::Web::Filters::JadeFilter

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

Overview

A filter that compiles input files written in Jade to HTML using the Jade compiler

Requires node and npmjs.org/package/jade by

sudo

npm install jade -g

Examples:

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

  # Compile each Jade file under the app/assets
  # directory.
  filter Rake::Pipeline::Web::Filters::JadeFilter
end
!!!ruby
Rake::Pipeline.build do
  input "app/assets", "**/*.jade"
  output "public"

  jade :pretty
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of JadeFilter


35
36
37
38
39
# File 'lib/rake-pipeline-web-filters/jade_filter.rb', line 35

def initialize(options={}, &block)
  block ||= proc { |input| input.sub(/\.(jade)$/, '.html') }
  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.


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

def options
  @options
end

Instance Method Details

#generate_output(inputs, output) ⇒ Object


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

def generate_output(inputs, output)

  inputs.each do |input|
    if options[:pretty]
      `jade < #{input.root}/#{input.path} -P --path #{input.root}/#{input.path} > #{output.root}/#{output.path}`
    else
      `jade < #{input.root}/#{input.path} --path #{input.root}/#{input.path} > #{output.root}/#{output.path}`
    end
    out = output.read
    output.write out
  end
end