element_component 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +2 -2
- data/README.md +88 -83
- data/examples/alert_example.rb +10 -10
- data/examples/badge_example.rb +2 -2
- data/examples/breadcrumb_example.rb +14 -10
- data/examples/button_example.rb +2 -2
- data/examples/button_group_example.rb +3 -3
- data/examples/card_example.rb +13 -13
- data/examples/carousel_example.rb +26 -24
- data/examples/close_button_example.rb +2 -2
- data/examples/dropdown_example.rb +46 -38
- data/examples/list_group_example.rb +26 -18
- data/examples/modal_example.rb +23 -21
- data/examples/nav_example.rb +25 -23
- data/examples/navbar_example.rb +38 -30
- data/examples/pagination_example.rb +16 -16
- data/examples/progress_example.rb +12 -12
- data/examples/spinner_example.rb +2 -2
- data/examples/table_example.rb +3 -3
- data/lib/element_component/components/dropdown.rb +1 -1
- data/lib/element_component/element.rb +9 -5
- data/lib/element_component/version.rb +1 -1
- metadata +1 -1
data/examples/table_example.rb
CHANGED
|
@@ -23,9 +23,9 @@ puts
|
|
|
23
23
|
# =============================================================================
|
|
24
24
|
# Table with Content
|
|
25
25
|
# =============================================================================
|
|
26
|
-
table = ElementComponent::Components::Table.new(striped: true) do
|
|
27
|
-
add_content("<thead><tr><th>Name</th><th>Age</th></tr></thead>")
|
|
28
|
-
add_content("<tbody><tr><td>John</td><td>30</td></tr></tbody>")
|
|
26
|
+
table = ElementComponent::Components::Table.new(striped: true) do |t|
|
|
27
|
+
t.add_content("<thead><tr><th>Name</th><th>Age</th></tr></thead>")
|
|
28
|
+
t.add_content("<tbody><tr><td>John</td><td>30</td></tr></tbody>")
|
|
29
29
|
end
|
|
30
30
|
puts "=== Table with Content ==="
|
|
31
31
|
puts table.render
|
|
@@ -33,7 +33,7 @@ module ElementComponent
|
|
|
33
33
|
btn = Element.new("button", "aria-expanded": "false", "data-bs-toggle": "dropdown",
|
|
34
34
|
class: "btn btn-#{variant} dropdown-toggle", type: "button", **btn_attributes)
|
|
35
35
|
btn.add_content(label) if label
|
|
36
|
-
|
|
36
|
+
block&.call(self)
|
|
37
37
|
add_content(btn)
|
|
38
38
|
end
|
|
39
39
|
self
|
|
@@ -11,18 +11,20 @@ module ElementComponent
|
|
|
11
11
|
|
|
12
12
|
add_attribute!(attribute)
|
|
13
13
|
reset_contents!
|
|
14
|
-
|
|
14
|
+
block&.call(self)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def add_content!(content)
|
|
17
|
+
def add_content!(content = nil, &)
|
|
18
18
|
reset_contents!
|
|
19
19
|
|
|
20
|
-
add_content(content)
|
|
20
|
+
add_content(content, &)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def add_content(content = nil, &block)
|
|
24
24
|
if block_given?
|
|
25
25
|
@contents.push(block)
|
|
26
|
+
elsif content.is_a?(Array)
|
|
27
|
+
@contents.push(*content)
|
|
26
28
|
else
|
|
27
29
|
@contents.push(content)
|
|
28
30
|
end
|
|
@@ -82,9 +84,11 @@ module ElementComponent
|
|
|
82
84
|
|
|
83
85
|
after_render(@html) if respond_to? "after_render"
|
|
84
86
|
|
|
85
|
-
@html
|
|
87
|
+
defined?(ActiveSupport::SafeBuffer) ? @html.html_safe : @html
|
|
86
88
|
end
|
|
87
89
|
|
|
90
|
+
def render_in(view_context, &block) = render
|
|
91
|
+
|
|
88
92
|
private
|
|
89
93
|
|
|
90
94
|
def build
|
|
@@ -105,7 +109,7 @@ module ElementComponent
|
|
|
105
109
|
in Element
|
|
106
110
|
content.render
|
|
107
111
|
in Proc
|
|
108
|
-
result =
|
|
112
|
+
result = content.call(self)
|
|
109
113
|
if result.equal?(self)
|
|
110
114
|
""
|
|
111
115
|
elsif result.respond_to?(:render)
|