Class: Bemer::Template

Inherits:
CommonTemplate show all
Extended by:
Forwardable
Defined in:
lib/bemer/template.rb

Instance Attribute Summary

Attributes inherited from CommonTemplate

#mode

Instance Method Summary collapse

Constructor Details

#initialize(mode, body, predicate) ⇒ Template

Returns a new instance of Template.



11
12
13
14
15
16
17
18
# File 'lib/bemer/template.rb', line 11

def initialize(mode, body, predicate)
  super(mode)

  @add_mode  = !@mode.eql?(mode)
  @body      = body
  @method    = [@mode, '='].join.to_sym
  @predicate = predicate
end

Instance Method Details

#apply(node) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/bemer/template.rb', line 20

def apply(node)
  case mode
  when Pipeline::REPLACE_MODE then replace(node)
  when Pipeline::CONTENT_MODE then capture_content(node)
  else node.entity_builder.public_send(method, capture_body(node), false)
  end
end

#apply!(node) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/bemer/template.rb', line 28

def apply!(node)
  return replace!(node) if Pipeline::REPLACE_MODE.eql?(mode)

  content = Pipeline::CONTENT_MODE.eql?(mode) ? capture_content!(node) : capture_body(node)

  node.entity_builder.public_send(method, content)
end