Class: Turing::CGIHandler::Template
- Inherits:
-
Object
- Object
- Turing::CGIHandler::Template
- Defined in:
- lib/turing/cgi_handler.rb
Overview
Simple template engine
Essentially just convenient wrapper around ERB which is used internally by Turing::CGIHandler.
Instance Method Summary collapse
-
#h(var) ⇒ Object
shortcut for
CGI.escapeHTML
. -
#initialize(what, variables = nil) ⇒ Template
constructor
Specify template file (
what
) andvariables
that will be pushed as instance variables to the Template. -
#render ⇒ Object
render given template and return result as string.
Constructor Details
#initialize(what, variables = nil) ⇒ Template
Specify template file (what
) and variables
that will be pushed as instance variables to the Template.
217 218 219 220 221 222 |
# File 'lib/turing/cgi_handler.rb', line 217 def initialize(what, variables = nil) # {{{ (variables || {}).each do |k,v| instance_variable_set("@" + k.to_s, v) end @__what__ = what end |
Instance Method Details
#h(var) ⇒ Object
shortcut for CGI.escapeHTML
can you say “Rails” ? :)
235 236 237 |
# File 'lib/turing/cgi_handler.rb', line 235 def h(var) # {{{ CGI.escapeHTML(var) end |
#render ⇒ Object
render given template and return result as string.
225 226 227 228 229 230 |
# File 'lib/turing/cgi_handler.rb', line 225 def render # {{{ erb = ERB.new(File.open(@__what__).read, nil, '%-') erb.result(binding) rescue raise "Failure rendering template #{@what}: #{$!}" end |