Simple template engine
Essentially just convenient wrapper around ERB which is used internally by Turing::CGIHandler.
Methods
Public Class methods
Specify template file (what) and variables that will be pushed as instance variables to the Template.
[ show source ]
# File lib/turing/cgi_handler.rb, line 219 219: def initialize(what, variables = nil) # {{{ 220: (variables || {}).each do |k,v| 221: instance_variable_set("@" + k.to_s, v) 222: end 223: @__what__ = what 224: end
Public Instance methods
shortcut for CGI.escapeHTML
can you say "Rails" ? :)
[ show source ]
# File lib/turing/cgi_handler.rb, line 237 237: def h(var) # {{{ 238: CGI.escapeHTML(var) 239: end
render given template and return result as string.
[ show source ]
# File lib/turing/cgi_handler.rb, line 227 227: def render # {{{ 228: erb = ERB.new(File.open(@__what__).read, nil, '%-') 229: erb.result(binding) 230: rescue 231: raise "Failure rendering template #{@what}: #{$!}" 232: end