class Rote::Filters::Eval

Page filter that evaluates Ruby code in it's body in the current interpreter. The code is directly evaluated, and anything it writes to standard out becomes the macro replacement.

Obviously you can place Ruby code directly in your pages, using ERB, and for many cases that is the route you should take. There is a (somewhat) subtle difference between the to alternatives however: ERB is always evaluated right at the start of rendering, before any Text Filters are run, whereas #:eval# code is executed during the page filter stage, which happens after ERB and text filtering, but before layout is applied.

Public Class Methods

new(macro_re = MACRO_RE) click to toggle source
# File lib/rote/filters/eval.rb, line 31
def initialize(macro_re = MACRO_RE)

Public Instance Methods

macro_eval(cmd,body,raw) click to toggle source
# File lib/rote/filters/eval.rb, line 35
def macro_eval(cmd,body,raw)
  # no need to fiddle with $SAFE here is there?
  # FIXME this is a hack.
  # Utility is still limited I guess, since current Page isn't
  # readily available to the macro code. We can probably fix
  # that though.
  # If thread safety becomes an issue, this'll probably need 
  # to be critical sectioned.
    oldsio, $stdout = $stdout,
    eval body        
    $stdout = oldsio