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:



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.


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, line 106
def initialize(names = [], code_re = MACRO_RE, &block)
  @names = (names || []).map { |n| n.to_s }
  @block = block
  @code_re = code_re

Public Instance Methods

filter(text,page) click to toggle source
# File lib/rote/filters/base.rb, line 112
def filter(text,page)
  text.gsub(@code_re) { handler($1,$2,$3,$&) || $& }
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, line 118
def handler(macro,args,body,all)
  if @names.include?(macro) then
  elsif respond_to?(meth = "macro_#{macro}") then