Class: P2::Template
- Inherits:
-
Object
- Object
- P2::Template
- Defined in:
- lib/p2/template.rb
Overview
Template wrapper class. This class can be used to distinguish between P2 templates and other kinds of procs.
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
Instance Method Summary collapse
- #apply ⇒ Object
- #compiled_proc ⇒ Object
-
#initialize(proc, mode: :html) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
Constructor Details
#initialize(proc, mode: :html) ⇒ Template
Returns a new instance of Template.
11 12 13 14 |
# File 'lib/p2/template.rb', line 11 def initialize(proc, mode: :html) @proc = proc @mode = mode end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/p2/template.rb', line 7 def mode @mode end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
7 8 9 |
# File 'lib/p2/template.rb', line 7 def proc @proc end |
Instance Method Details
#apply ⇒ Object
20 21 22 |
# File 'lib/p2/template.rb', line 20 def apply(*, **, &) Template.new(@proc.apply(*, **, &), mode: @mode) end |
#compiled_proc ⇒ Object
24 25 26 |
# File 'lib/p2/template.rb', line 24 def compiled_proc @proc.compiled_proc(mode: @mode) end |
#render ⇒ Object
16 17 18 |
# File 'lib/p2/template.rb', line 16 def render(*, **, &) (mode == :xml) ? @proc.render_xml(*, **, &) : @proc.render(*, **, &) end |