Class: DatoDast::Nodes::Item
- Inherits:
-
Base
- Object
- Base
- DatoDast::Nodes::Item
show all
- Defined in:
- lib/dato_dast/nodes/item.rb
Constant Summary
Constants inherited
from Base
Base::EMPTY, Base::NEWLINE
Instance Method Summary
collapse
Methods inherited from Base
#config, #css_class, #initialize, #meta, #render_children, #tag, #tag_info, #type, type, #wrappers
Instance Method Details
#children ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/dato_dast/nodes/item.rb', line 24
def children
Array.wrap(structure).map do |child|
case child["type"]
when "field"
build_field(child)
when "value"
build_value(child)
when "item"
build_item(item[child["field"].to_sym])
when "items"
build_items(child)
else
raise DatoDast::Errors::InvalidStructureType.new(error_label)
end.merge((child)).compact
end.flatten
end
|
#item ⇒ Object
8
9
10
11
12
|
# File 'lib/dato_dast/nodes/item.rb', line 8
def item
return @item if @item
@item ||= item_repo.find { |item| item[:id] == item_id }
end
|
#item_id ⇒ Object
4
5
6
|
# File 'lib/dato_dast/nodes/item.rb', line 4
def item_id
@node["item"]
end
|
#item_type ⇒ Object
14
15
16
|
# File 'lib/dato_dast/nodes/item.rb', line 14
def item_type
item[:item_type]
end
|
#render ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/dato_dast/nodes/item.rb', line 49
def render
return super unless node
begin
node.new(item).render
rescue NoMethodError => _e
raise DatoDast::Errors::MissingRenderFunction.new([error_label])
end
end
|
#render_value ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/dato_dast/nodes/item.rb', line 41
def render_value
if node_config["render_value"]
node_config["render_value"].call(item)
else
render_children
end
end
|