Class: Rake::Pipeline::Web::Filters::MarkdownFilter

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

Overview

A filter that compiles input files written in Markdown to Markdown using the Redcarpet compiler.

Examples:

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

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MarkdownFilter.

Parameters:

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

    options to pass to the markdown compiler

  • block (Proc)

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

Options Hash (options):

  • :compiler (#call)

    If you wish to use a different Markdown compiler, you can do so by passing anything that responds to ‘:call`, which will be passed the Markdown text and any options (other than `:compiler`).

  • :renderer (Redcarpet::Render::Base)

    a Redcarpet renderer. Used only if using the default compiler.

See Also:



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

def initialize(options={}, &block)
  block ||= proc { |input| input.sub(/\.(md|mdown|mkdown|markdown)$/, '.html') }
  super(&block)
  @compiler = options.delete(:compiler)
  @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.



45
46
47
48
49
# File 'lib/rake-pipeline-web-filters/markdown_filter.rb', line 45

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