Module: TextTube::Filterable

Included in:
Coderay, EmbeddingAudio, EmbeddingVideo, InsideBlock, LinkReffing, Spiffing
Defined in:
lib/texttube/filterable.rb

Overview

Add this to your filter module.

Examples:

module AFilter
  extend TextTube::Filterable

  filter_with :double do |text|
    text * 2
  end

  filter_with :triple do |text|
    text * 3
  end
end

Instance Method Summary collapse

Instance Method Details

#filter_with(name) {|String, Hash| ... } ⇒ Object

Add a filter.

Examples:

filter_with :triple do |text|
  text * 3
end
filter_with :number do |text,options|
  text * options[:times].to_i
end

Parameters:

  • name (#to_sym)

Yields:

  • (String, Hash)

    Pass the string to be filtered, and optionally, any options.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/texttube/filterable.rb', line 34

def filter_with name, &block
  name = name.to_sym
  filters << name unless filters.include? name
  define_method name do |current=self, options=nil|
    if current.respond_to? :keys
      options=current
      current=self
    end
    options = [options, @options, self.class.options].find{|opts|
      !opts.nil? && 
      opts.respond_to?(:keys) && 
      !opts.empty?
    } || {}

    block.call current, options[name]
  end
end

#filtersArray<Symbol>

See all current filters.

Returns:

  • (Array<Symbol>)


20
21
22
# File 'lib/texttube/filterable.rb', line 20

def filters
  @filters ||= []
end