spark_components 1.0.0 → 1.1.0

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: 635a89fb74020c44aa354d88e39a317f09747b545b2f04a8a47091ba65e823e4
4
- data.tar.gz: eb77464a1a07270e1fabfef42bba3cd121790c92e01a9322203292cf266745cb
3
+ metadata.gz: 0ee310de39580a5277c2efa8351ee4c8bd0257a897ded6f29d8419d8a2d8eef6
4
+ data.tar.gz: 9bc0d4e762bb9eec2d19a87d898725a078d8223f903bd9ce5289cf2c835a1e95
5
5
  SHA512:
6
- metadata.gz: 9f6b10c0bef2d089d14ace1b0892db52d59a47b7999fa0e902f82d6158328ac61599e6890d34d221d86d04d400f8ad7048516e561b7ffb4651a6513edee43d88
7
- data.tar.gz: 45e75e4a5ef27ca91fbc0de782541f19fa8fe3b10807eb9b9d5eb6dbb48fb87b08bcfee02e70278bbc4cc4d5e3e44a201b00558563a3660d10576dba91f2534f
6
+ metadata.gz: dd88f5cf5ef27420d517848eb6f9e2030739594ecc6a78ab89c07985428cf4b1a42a7d84cb1d026ee4819340e780894e97ed0a486c608af1d3c10d29b6769529
7
+ data.tar.gz: bd66af4c627886efae22591eab90cfb87149b2c67a08fc69ab070816e346e5dbc0c3c6ca6380a2d83740782e4a1bad0a31ec0f92dd52e2a8bc4018d21372114d
@@ -4,7 +4,7 @@ module SparkComponents
4
4
  module ComponentHelper
5
5
  def component(name, attrs = nil, &block)
6
6
  comp = "#{name}_component".classify.constantize.new(self, attrs, &block)
7
- comp.pre_render
7
+ comp.before_render
8
8
  comp.render
9
9
  end
10
10
  end
@@ -95,7 +95,7 @@ module SparkComponents
95
95
  element.parent = self
96
96
 
97
97
  if element.respond_to?(:render)
98
- element.pre_render
98
+ element.before_render
99
99
  element.yield = element.render
100
100
  end
101
101
 
@@ -142,15 +142,15 @@ module SparkComponents
142
142
  assign_tag_attributes(attributes)
143
143
  initialize_attributes(attributes)
144
144
  initialize_elements
145
+ after_init
145
146
  @yield = block_given? ? @view.capture(self, &block) : nil
146
147
  validate!
147
- after_init
148
148
  end
149
149
 
150
- def pre_render; end
151
-
152
150
  def after_init; end
153
151
 
152
+ def before_render; end
153
+
154
154
  def parent=(obj)
155
155
  @parents = [obj.parents, obj].flatten.compact
156
156
  end
@@ -159,13 +159,6 @@ module SparkComponents
159
159
  @parents.last
160
160
  end
161
161
 
162
- # Set tag attribute values from from parameters
163
- def update_attr(name)
164
- %i[aria data tag].each do |el|
165
- @tag_attributes[el][name] = get_instance_variable(name) if @tag_attributes[el].key?(name)
166
- end
167
- end
168
-
169
162
  def classnames
170
163
  @tag_attributes[:class]
171
164
  end
@@ -206,28 +199,19 @@ module SparkComponents
206
199
  atr
207
200
  end
208
201
 
209
- def concat(*args, &block)
210
- @view.concat(*args, &block)
211
- end
212
-
213
- def content_tag(*args, &block)
214
- @view.content_tag(*args, &block)
215
- end
216
-
217
- def link_to(*args, &block)
218
- @view.link_to(*args, &block)
219
- end
220
-
221
- def component(*args, &block)
222
- @view.component(*args, &block)
223
- end
224
-
225
202
  def to_s
226
203
  @yield
227
204
  end
228
205
 
229
206
  protected
230
207
 
208
+ # Set tag attribute values from from parameters
209
+ def update_attr(name)
210
+ %i[aria data tag].each do |el|
211
+ @tag_attributes[el][name] = get_instance_variable(name) if @tag_attributes[el].key?(name)
212
+ end
213
+ end
214
+
231
215
  def render_partial(file)
232
216
  @view.render(partial: file, object: self)
233
217
  end
@@ -265,6 +249,21 @@ module SparkComponents
265
249
 
266
250
  private
267
251
 
252
+ # Define common view methods to "alias"
253
+ def view_methods
254
+ %i[tag content_tag image_tag concat content_for link_to component]
255
+ end
256
+
257
+ def extend_view_methods
258
+ view_methods.each do |name|
259
+ next unless @view.respond_to?(name)
260
+
261
+ self.class.define_method(name) do |*args, &block|
262
+ @view.send(name, *args, &block)
263
+ end
264
+ end
265
+ end
266
+
268
267
  def get_instance_variable(name)
269
268
  instance_variable_get(:"@#{name}")
270
269
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SparkComponents
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-10 00:00:00.000000000 Z
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails