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.
@@ -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
- instance_eval(&block) if block
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
- instance_eval(&block) if block
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 = instance_eval(&content)
112
+ result = content.call(self)
109
113
  if result.equal?(self)
110
114
  ""
111
115
  elsif result.respond_to?(:render)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElementComponent
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: element_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Paulo Correia