class Rote::Filters::MacroFilter

Baseclass from which Rote filters can be derived if you want some help with macro replacement.

There are three ways to make a macro filter:

Attributes

handler_blk[RW]

Block that will be called for each supported macro in the filtered text. Like:

{ |macro, args, body, raw_macro| "replacement" }

The presence of a block precludes the use of any macro_xxxx methods on the subclass.

names[RW]

An array of macro names supported by this filter. This can be used to selectively disable individual macro support.

Public Class Methods

new(names = [], code_re = MACRO_RE, &block) click to toggle source

Create a new macro filter. If a three-arg block is passed, it will be called for each macro with a name that exists in the macros array. Otherwise, macros will be sought as methods (e.g. macro_code). If an array of names isn’t passed, a search such methods will be used to populate the names array.

    # File lib/rote/filters/base.rb
106 def initialize(names = [], code_re = MACRO_RE, &block)
107   @names = (names || []).map { |n| n.to_s }
108   @block = block
109   @code_re = code_re
110 end

Public Instance Methods

filter(text,page) click to toggle source
    # File lib/rote/filters/base.rb
112 def filter(text,page)
113   text.gsub(@code_re) { handler($1,$2,$3,$&) || $& }
114 end
handler(macro,args,body,all) click to toggle source

You may override this method if you want to completely override the standard macro dispatch.

    # File lib/rote/filters/base.rb
118 def handler(macro,args,body,all)
119   if @names.include?(macro) then
120     @block[macro,args,body,all]
121   elsif respond_to?(meth = "macro_#{macro}") then
122     self.send(meth,args,body,all)
123   else
124     nil
125   end
126 end