Class: Arbre::HTML::Element
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#append_return_block, #build_tag, #current_dom_context, #insert_tag, #with_current_dom_context
Methods included from Builder
#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/html/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::Builder
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
9
10
11
|
# File 'lib/active_admin/arbre/html/element.rb', line 9
def children
@children
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/active_admin/arbre/html/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/html/element.rb', line 11
def self.builder_method(method_name)
::Arbre::Builder::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/html/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/html/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 = Arbre::HTML::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
|
#assigns ⇒ Object
24
25
26
|
# File 'lib/active_admin/arbre/html/element.rb', line 24
def assigns
@_assigns
end
|
#build(*args, &block) ⇒ Object
36
37
38
39
|
# File 'lib/active_admin/arbre/html/element.rb', line 36
def build(*args, &block)
append_return_block(block.call(self)) if block
end
|
#content ⇒ Object
110
111
112
|
# File 'lib/active_admin/arbre/html/element.rb', line 110
def content
children.to_s
end
|
#content=(contents) ⇒ Object
85
86
87
88
|
# File 'lib/active_admin/arbre/html/element.rb', line 85
def content=(contents)
clear_children!
add_child(contents)
end
|
#document ⇒ Object
81
82
83
|
# File 'lib/active_admin/arbre/html/element.rb', line 81
def document
parent.document if parent?
end
|
#each(&block) ⇒ Object
122
123
124
|
# File 'lib/active_admin/arbre/html/element.rb', line 122
def each(&block)
[to_s].each(&block)
end
|
#get_elements_by_class_name(class_name) ⇒ Object
Also known as:
find_by_class
100
101
102
103
104
105
106
107
|
# File 'lib/active_admin/arbre/html/element.rb', line 100
def get_elements_by_class_name(class_name)
elements = Collection.new
children.each do |child|
elements << child if child.class_list =~ /#{class_name}/
elements.concat(child.get_elements_by_tag_name(tag_name))
end
elements
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/html/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
|
#helpers ⇒ Object
28
29
30
|
# File 'lib/active_admin/arbre/html/element.rb', line 28
def helpers
@_helpers
end
|
#html_safe ⇒ Object
114
115
116
|
# File 'lib/active_admin/arbre/html/element.rb', line 114
def html_safe
to_s
end
|
#indent_level ⇒ Object
118
119
120
|
# File 'lib/active_admin/arbre/html/element.rb', line 118
def indent_level
parent? ? parent.indent_level + 1 : 0
end
|
#parent? ⇒ Boolean
77
78
79
|
# File 'lib/active_admin/arbre/html/element.rb', line 77
def parent?
!@parent.nil?
end
|
#remove_child(child) ⇒ Object
64
65
66
67
|
# File 'lib/active_admin/arbre/html/element.rb', line 64
def remove_child(child)
child.parent = nil if child.respond_to?(:parent=)
@children.delete(child)
end
|
#tag_name ⇒ Object
32
33
34
|
# File 'lib/active_admin/arbre/html/element.rb', line 32
def tag_name
@tag_name ||= self.class.name.demodulize.downcase
end
|
#to_ary ⇒ Object
Also known as:
to_a
143
144
145
|
# File 'lib/active_admin/arbre/html/element.rb', line 143
def to_ary
Collection.new [self]
end
|
#to_s ⇒ Object
130
131
132
|
# File 'lib/active_admin/arbre/html/element.rb', line 130
def to_s
content
end
|
#to_str ⇒ Object
126
127
128
|
# File 'lib/active_admin/arbre/html/element.rb', line 126
def to_str
to_s
end
|