Module: Slippers::AttributeToRenderNode

Included in:
AttributeWithExpressionOptionNode
Defined in:
lib/engine/slippers_nodes.rb

Instance Method Summary collapse

Instance Method Details

#attributeObject



38
39
40
# File 'lib/engine/slippers_nodes.rb', line 38

def attribute
  text_value
end

#eval(object_to_render, template_group) ⇒ Object



4
5
6
# File 'lib/engine/slippers_nodes.rb', line 4

def eval(object_to_render, template_group)
  [object_to_render].flatten.inject('') { |rendered, item| rendered + render(value_of(item, template_group), template_group) }
end

#null_valuesObject



32
33
# File 'lib/engine/slippers_nodes.rb', line 32

def null_values
end

#render(object_to_render, template_group) ⇒ Object



16
17
18
19
20
21
# File 'lib/engine/slippers_nodes.rb', line 16

def render(object_to_render, template_group)
  substitue_null_values(object_to_render)
  return template_group.render(object_to_render) if template_group && template_group.has_registered?(object_to_render.class)
  return object_to_render.compact.join(seperator) if object_to_render.respond_to?('join')
  object_to_render.to_s
end

#seperatorObject



35
36
# File 'lib/engine/slippers_nodes.rb', line 35

def seperator
end

#substitue_null_values(object_to_render) ⇒ Object



23
24
25
26
# File 'lib/engine/slippers_nodes.rb', line 23

def substitue_null_values(object_to_render)
  return unless null_values && object_to_render.respond_to?('map!')
  object_to_render.map!{|x| if x then x else null_values end }
end

#to_symObject



28
29
30
# File 'lib/engine/slippers_nodes.rb', line 28

def to_sym
  attribute.to_sym
end

#value_of(item, template_group) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/engine/slippers_nodes.rb', line 8

def value_of(item, template_group)
  return default_string(template_group) if attribute == ''
  return item.to_s if attribute == 'it'
  return item[to_sym] if item.respond_to?(:[]) && item[to_sym]
  return item.send(attribute) if item.respond_to?(attribute)
  default_string(template_group)
end