Class: Arbre::HTML::Element
Constant Summary
Constants included
from Arbre::HTML
AUTO_BUILD_ELEMENTS, HTML5_ELEMENTS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#build_tag, #current_dom_context, #insert_tag, #insert_text_node_if_string, #with_current_dom_context
#current_dom_context, #method_missing
Constructor Details
#initialize(assigns = {}, helpers = nil) ⇒ Element
Returns a new instance of Element.
19
20
21
22
|
# File 'lib/active_admin/arbre/element.rb', line 19
def initialize(assigns = {}, helpers = nil)
@_assigns, @_helpers = assigns, helpers
@children = Collection.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Arbre::HTML
Instance Attribute Details
Returns the value of attribute children.
9
10
11
|
# File 'lib/active_admin/arbre/element.rb', line 9
def children
@children
end
|
Returns the value of attribute parent.
8
9
10
|
# File 'lib/active_admin/arbre/element.rb', line 8
def parent
@parent
end
|
Class Method Details
.builder_method(method_name) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/active_admin/arbre/element.rb', line 11
def self.builder_method(method_name)
::Arbre::HTML::BuilderMethods.class_eval <<-EOF, __FILE__, __LINE__
def #{method_name}(*args, &block)
insert_tag #{self.name}, *args, &block
end
EOF
end
|
Instance Method Details
#<<(child) ⇒ Object
69
70
71
|
# File 'lib/active_admin/arbre/element.rb', line 69
def <<(child)
add_child(child)
end
|
#add_child(child) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_admin/arbre/element.rb', line 41
def add_child(child)
return unless child
if child.is_a?(Array)
child.each{|item| add_child(item) }
return @children
end
unless child.is_a?(Element)
child = TextNode.from_string(child)
end
if child.respond_to?(:parent)
child.parent.remove_child(child) if child.parent
child.parent = self
end
@children << child
end
|
24
25
26
|
# File 'lib/active_admin/arbre/element.rb', line 24
def assigns
@_assigns
end
|
#build(*args, &block) ⇒ Object
36
37
38
39
|
# File 'lib/active_admin/arbre/element.rb', line 36
def build(*args, &block)
insert_text_node_if_string(block.call(self)) if block
end
|
100
101
102
|
# File 'lib/active_admin/arbre/element.rb', line 100
def content
children.to_html
end
|
#content=(contents) ⇒ Object
85
86
87
88
|
# File 'lib/active_admin/arbre/element.rb', line 85
def content=(contents)
clear_children!
add_child(contents)
end
|
81
82
83
|
# File 'lib/active_admin/arbre/element.rb', line 81
def document
parent.document if parent?
end
|
#each(&block) ⇒ Object
112
113
114
|
# File 'lib/active_admin/arbre/element.rb', line 112
def each(&block)
[to_html].each(&block)
end
|
#get_elements_by_tag_name(tag_name) ⇒ Object
Also known as:
find_by_tag
90
91
92
93
94
95
96
97
|
# File 'lib/active_admin/arbre/element.rb', line 90
def get_elements_by_tag_name(tag_name)
elements = Collection.new
children.each do |child|
elements << child if child.tag_name == tag_name
elements.concat(child.get_elements_by_tag_name(tag_name))
end
elements
end
|
28
29
30
|
# File 'lib/active_admin/arbre/element.rb', line 28
def helpers
@_helpers
end
|
#html_safe ⇒ Object
104
105
106
|
# File 'lib/active_admin/arbre/element.rb', line 104
def html_safe
to_html
end
|
#indent_level ⇒ Object
108
109
110
|
# File 'lib/active_admin/arbre/element.rb', line 108
def indent_level
parent? ? parent.indent_level + 1 : 0
end
|
#parent? ⇒ Boolean
77
78
79
|
# File 'lib/active_admin/arbre/element.rb', line 77
def parent?
!@parent.nil?
end
|
#remove_child(child) ⇒ Object
64
65
66
67
|
# File 'lib/active_admin/arbre/element.rb', line 64
def remove_child(child)
child.parent = nil if child.respond_to?(:parent=)
@children.delete(child)
end
|
32
33
34
|
# File 'lib/active_admin/arbre/element.rb', line 32
def tag_name
@tag_name ||= self.class.name.demodulize.downcase
end
|
#to_ary ⇒ Object
Also known as:
to_a
137
138
139
|
# File 'lib/active_admin/arbre/element.rb', line 137
def to_ary
Collection.new [self]
end
|
124
125
126
|
# File 'lib/active_admin/arbre/element.rb', line 124
def to_html
content
end
|
116
117
118
|
# File 'lib/active_admin/arbre/element.rb', line 116
def to_s
to_html
end
|
120
121
122
|
# File 'lib/active_admin/arbre/element.rb', line 120
def to_str
to_s
end
|