spark-component 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1be4ebc3a6ecf66978f87558cbc83f349fcf41e15b4aff6aa9e5609d88b12a5f
4
- data.tar.gz: 4a94a2bf74570d0f9cc7b531bb4d815c2e068c92162390d9da08e0885f3e6576
3
+ metadata.gz: 76d73723f8423e6333f1ff46727f363096ad11cb3dc526c531ddbc8e8c30f0eb
4
+ data.tar.gz: e302e38f303eb1d0c5ed8d8f591583b591dec48cf006d196194f014236a2899c
5
5
  SHA512:
6
- metadata.gz: 699b6ed45fd2c908648bdd7a78c09dcb916e1289e414181dbc0efef84b766eae81dd1694511e3ef499e0ae1b9ccb500e3e0154d9ffbd5695847436bd8e59557e
7
- data.tar.gz: f588d817b0a446b3dff251c0b8687c6c712131aa50f9d652e0a63199b4a2a1f08ecc06d34678fc6072c28d7c8b966758e30e01568f72b54637376b6f8e826cf3
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.0)
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.6.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 unless @content.nil?
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
- !self.yield.nil?
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
- return get_element_variable(multiple ? plural : name) unless block || attributes
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Spark
4
4
  module Component
5
- VERSION = "1.1.0"
5
+ VERSION = "1.1.1"
6
6
  end
7
7
  end
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.0
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-10 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview-component