Module: Cog::Generator::Filters

Included in:
Cog::Generator
Defined in:
lib/cog/generator/filters.rb

Overview

Filters are methods which translate text into more text

Instance Method Summary collapse

Instance Method Details

#call_filter(name, text) ⇒ String

Call a filter by name

Parameters:

  • name (Symbol)

    the filter to call

  • text (String)

    the text to pass through the filter

Returns:

  • (String)

    the filtered text

Raises:

  • (Errors::NoSuchFilter)


17
18
19
20
21
22
# File 'lib/cog/generator/filters.rb', line 17

def call_filter(name, text)
  gcontext[:filters] ||= %w(comment)
  name = name.to_s
  raise Errors::NoSuchFilter.new(name) unless gcontext[:filters].member? name
  method(name).call text
end

#comment(text) ⇒ String

Returns a comment appropriate for the current language context.

Parameters:

  • text (String)

    some text which should be rendered as a comment

Returns:

  • (String)

    a comment appropriate for the current language context



9
10
11
# File 'lib/cog/generator/filters.rb', line 9

def comment(text)
  Cog.active_language.comment text
end