spark-component 1.1.0 → 1.1.1
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/CHANGELOG.md +10 -0
- data/Gemfile.lock +2 -2
- data/lib/spark/component/element.rb +26 -9
- data/lib/spark/component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76d73723f8423e6333f1ff46727f363096ad11cb3dc526c531ddbc8e8c30f0eb
|
4
|
+
data.tar.gz: e302e38f303eb1d0c5ed8d8f591583b591dec48cf006d196194f014236a2899c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec683787307ba6b95a59ee247ed138539375d96aab59b365785ddc23db4d98bde114df66d8a0b16df813861c7a6e6a75c8883a7573c60d5f0b7080996683c27
|
7
|
+
data.tar.gz: af9031efb9b8ef31188bdd60d45025f359ccf201866b8a433c1ea1cfd299fb40ac0de40c15b019e747de55fcbec766ceff2ff66ca2846649f4f8a1e3d500a347
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# v1.1.1 - 2020-01-14
|
2
|
+
|
3
|
+
- Fix: When a nested element is referenced it will trigger the parent to yield
|
4
|
+
its block, ensuring that the nested element reference will be instantiated
|
5
|
+
if it is used in the parent's block.
|
6
|
+
- Fix: Elements now have a `blank?` method and `present?` returns `!blank?`. It
|
7
|
+
is important to remember, `blank?` and `present?` return false if an element
|
8
|
+
yields nothing. To check for the existence of an element instance, use `nil?`.
|
9
|
+
- New: Elements now have access to their own name with the `_name` method.
|
10
|
+
|
1
11
|
# v1.1.0 - 2020-01-10
|
2
12
|
|
3
13
|
- New: Class method `attribute_default_group` makes it easy to set defaults for multiple attributes based on a single component argument. It's great for theming, where setting `theme: :notice` can set attributes for color, layout, etc.
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spark-component (1.1.
|
4
|
+
spark-component (1.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
erubi (~> 1.4)
|
43
43
|
rails-dom-testing (~> 2.0)
|
44
44
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
45
|
-
actionview-component (1.
|
45
|
+
actionview-component (1.7.0)
|
46
46
|
activejob (6.0.1)
|
47
47
|
activesupport (= 6.0.1)
|
48
48
|
globalid (>= 0.3.6)
|
@@ -10,7 +10,7 @@ module Spark
|
|
10
10
|
def self.included(base)
|
11
11
|
base.extend(Spark::Component::Element::ClassMethods)
|
12
12
|
|
13
|
-
%i[_parent _block view_context].each do |name|
|
13
|
+
%i[_name _parent _block view_context].each do |name|
|
14
14
|
base.define_method(:"#{name}=") { |val| instance_variable_set(:"@#{name}", val) }
|
15
15
|
base.define_method(:"#{name}") { instance_variable_get(:"@#{name}") }
|
16
16
|
end
|
@@ -25,6 +25,7 @@ module Spark
|
|
25
25
|
# - view_context, sets the view context for an element (in Rails)
|
26
26
|
#
|
27
27
|
unless attrs.nil? || attrs.empty?
|
28
|
+
@_name = attrs.delete(:_name)
|
28
29
|
@_parent = attrs.delete(:_parent)
|
29
30
|
@_block = attrs.delete(:_block)
|
30
31
|
@view_context = attrs.delete(:_view)
|
@@ -37,13 +38,18 @@ module Spark
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def render_self
|
40
|
-
return @content
|
41
|
+
return @content if rendered?
|
41
42
|
|
42
43
|
@content = render_block(@view_context, &_block)
|
43
44
|
validate! if defined?(ActiveModel::Validations)
|
45
|
+
@rendered = true
|
44
46
|
@content
|
45
47
|
end
|
46
48
|
|
49
|
+
def rendered?
|
50
|
+
@rendered == true
|
51
|
+
end
|
52
|
+
|
47
53
|
def render_block(view, &block)
|
48
54
|
block_given? ? view.capture(self, &block) : nil
|
49
55
|
end
|
@@ -53,7 +59,11 @@ module Spark
|
|
53
59
|
end
|
54
60
|
|
55
61
|
def present?
|
56
|
-
!
|
62
|
+
!blank?
|
63
|
+
end
|
64
|
+
|
65
|
+
def blank?
|
66
|
+
self.yield.nil? || self.yield.strip.empty?
|
57
67
|
end
|
58
68
|
|
59
69
|
private
|
@@ -169,15 +179,22 @@ module Spark
|
|
169
179
|
#
|
170
180
|
def define_element(name:, plural:, multiple:, klass:)
|
171
181
|
define_method_if_able(name) do |attributes = nil, &block|
|
172
|
-
|
182
|
+
# When initializing an element, blocks or arguments are passed.
|
183
|
+
# If an element is being referenced without these, it will return its instance
|
184
|
+
# This allows the elemnet method to initailize the object and return its instance
|
185
|
+
# for template rendering.
|
186
|
+
unless block || attributes
|
187
|
+
|
188
|
+
# If an element is called, it will only exist if its parent's block has been exectued
|
189
|
+
# Be sure the block has been executed so that sub elements are initialized
|
190
|
+
self.yield if is_a?(Spark::Component::Element::Base) && !rendered?
|
191
|
+
|
192
|
+
return get_element_variable(multiple ? plural : name)
|
193
|
+
end
|
173
194
|
|
174
195
|
attributes ||= {}
|
175
196
|
attributes = merge_element_attribute_default(name, attributes)
|
176
|
-
attributes.merge!(
|
177
|
-
_parent: self,
|
178
|
-
_block: block,
|
179
|
-
_view: view_context
|
180
|
-
)
|
197
|
+
attributes.merge!(_name: name, _parent: self, _block: block, _view: view_context)
|
181
198
|
|
182
199
|
element = klass.new(attributes)
|
183
200
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spark-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview-component
|