Class: P2::Template

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(proc, mode: :html) ⇒ Template

Returns a new instance of Template.

Parameters:

  • proc (Proc)

    template proc

  • mode (Symbol) (defaults to: :html)

    mode (:html, :xml)



11
12
13
14
# File 'lib/p2/template.rb', line 11

def initialize(proc, mode: :html)
  @proc = proc
  @mode = mode
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



7
8
9
# File 'lib/p2/template.rb', line 7

def mode
  @mode
end

#procObject (readonly)

Returns the value of attribute proc.



7
8
9
# File 'lib/p2/template.rb', line 7

def proc
  @proc
end

Instance Method Details

#applyObject



20
21
22
# File 'lib/p2/template.rb', line 20

def apply(*, **, &)
  Template.new(@proc.apply(*, **, &), mode: @mode)
end

#compiled_procObject



24
25
26
# File 'lib/p2/template.rb', line 24

def compiled_proc
  @proc.compiled_proc(mode: @mode)
end

#renderObject



16
17
18
# File 'lib/p2/template.rb', line 16

def render(*, **, &)
  (mode == :xml) ? @proc.render_xml(*, **, &) : @proc.render(*, **, &)
end