Class: Rote::Filters::Eval
- Inherits:
-
MacroFilter
- Object
- MacroFilter
- Rote::Filters::Eval
- Defined in:
- lib/rote/filters/eval.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from MacroFilter
Instance Method Summary collapse
-
#initialize(macro_re = MACRO_RE) ⇒ Eval
constructor
A new instance of Eval.
- #macro_eval(cmd, body, raw) ⇒ Object
Methods inherited from MacroFilter
Constructor Details
Instance Method Details
#macro_eval(cmd, body, raw) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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. begin oldsio, $stdout = $stdout, StringIO.new eval body $stdout.rewind $stdout.read ensure $stdout = oldsio end end |