Class: DatoDast::Nodes::Base
- Inherits:
-
Object
- Object
- DatoDast::Nodes::Base
show all
- Defined in:
- lib/dato_dast/nodes/base.rb
Direct Known Subclasses
AttributedQuote, Blockquote, Code, Generic, Heading, Item, Link, List, ListItem, Paragraph, Root, Span, ThematicBreak
Constant Summary
collapse
- EMPTY =
""
- NEWLINE =
"\n"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(node, links = [], blocks = [], config = nil) ⇒ Base
Returns a new instance of Base.
11
12
13
14
15
16
|
# File 'lib/dato_dast/nodes/base.rb', line 11
def initialize(node, links = [], blocks = [], config = nil)
@node = node
@links = links
@blocks = blocks
@config = config
end
|
Class Method Details
.type ⇒ Object
7
8
9
|
# File 'lib/dato_dast/nodes/base.rb', line 7
def self.type
name.demodulize.camelize(:lower)
end
|
Instance Method Details
#children ⇒ Object
26
27
28
|
# File 'lib/dato_dast/nodes/base.rb', line 26
def children
@node["children"]
end
|
#css_class ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/dato_dast/nodes/base.rb', line 42
def css_class
if node_config && node_config["css_class"].is_a?(Proc)
node_config["css_class"].call(proc_object)
else
@node["css_class"] || node_config["css_class"]
end
end
|
50
51
52
53
54
55
56
|
# File 'lib/dato_dast/nodes/base.rb', line 50
def meta
if node_config && node_config["meta"].is_a?(Proc)
node_config["meta"].call(proc_object)
else
@node["meta"] || node_config["meta"]
end
end
|
#node_config ⇒ Object
58
59
60
|
# File 'lib/dato_dast/nodes/base.rb', line 58
def node_config
@node_config ||= config.types[type]
end
|
#render ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/dato_dast/nodes/base.rb', line 70
def render
open_wrappers +
html_tag.open +
render_value +
html_tag.close +
close_wrappers
end
|
#render_children ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/dato_dast/nodes/base.rb', line 82
def render_children
return EMPTY unless children.present?
children.map do |child|
Nodes.wrap(child, @links, @blocks, config).render
end.join("\n").gsub(/\n+/, "\n")
end
|
#render_value ⇒ Object
78
79
80
|
# File 'lib/dato_dast/nodes/base.rb', line 78
def render_value
render_children
end
|
#tag ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/dato_dast/nodes/base.rb', line 34
def tag
if node_config && node_config["tag"].is_a?(Proc)
node_config["tag"].call(proc_object)
else
@node["tag"] || node_config["tag"]
end
end
|
#tag_info ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/dato_dast/nodes/base.rb', line 62
def tag_info
{
"tag" => tag,
"css_class" => css_class,
"meta" => meta,
}
end
|
#type ⇒ Object
22
23
24
|
# File 'lib/dato_dast/nodes/base.rb', line 22
def type
@node["type"]
end
|
#wrappers ⇒ Object
30
31
32
|
# File 'lib/dato_dast/nodes/base.rb', line 30
def wrappers
@node["wrappers"] || Array.wrap(node_config["wrappers"])
end
|