Class: Rote::Filters::Exec

Inherits:
MacroFilter show all
Defined in:
lib/rote/filters/exec.rb

Overview

Page filter that runs it’s body through the specified command, and captures the output. E.g.:

#:exec#python#
  print "Hello, World!"
#:exec#

Although this filter can be used to execute Ruby code, you must bear in mind that this will happen in a separate interpreter process, so no variables or requires from the current environment will be available. If you wish to evaluate Ruby code in your pages, you should use either ERB (evaluated at the beginning of the render), or the Eval filter (evaluated near the end).

Instance Attribute Summary

Attributes inherited from MacroFilter

#handler_blk, #names

Instance Method Summary collapse

Methods inherited from MacroFilter

#filter, #handler

Constructor Details

#initialize(macro_re = MACRO_RE) ⇒ Exec

Returns a new instance of Exec.



30
31
32
# File 'lib/rote/filters/exec.rb', line 30

def initialize(macro_re = MACRO_RE)
  super([],macro_re)
end

Instance Method Details

#macro_exec(cmd, body, raw) ⇒ Object



34
35
36
37
38
39
# File 'lib/rote/filters/exec.rb', line 34

def macro_exec(cmd,body,raw)
  res = IO.popen(cmd, 'w+') do |io|
    Thread.new { io.write body; io.close_write }
    io.read
  end
end