lite-component 1.0.8 → 1.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42c871c9d4d37bbc347dc56f867e94cb7b0f79cdca1d59d19178b53efb0f5ac3
4
- data.tar.gz: 5344d77cc6ba9ca376de5109a1705482438ab41c249e4c94c674e6d51b0f4468
3
+ metadata.gz: fb7847b78bc4df9d5b25648f75500cc44b25f618a3c94a7d9ef63f300b5895dd
4
+ data.tar.gz: 92803d6916eaec8cea78e52ec90d3ff7fe9c8e84c28bb7c15cb9f6894e3c8d57
5
5
  SHA512:
6
- metadata.gz: 30378e2f2adc971d9254c7b861b83c1e0f6dcc088113fd5e48980ec99171659492b0c9400e6257719eb91b05bea0a0ea0f779ca7441d671b68a5b148372e04c4
7
- data.tar.gz: 3665e9afb7967818478bb7a8591e76c1eedf5ef70f07da03e2779322b99ab52dcfcfd930814eb31b46d78e10a349022cfb5716db68b9edbcc40b7ce6da48ac95
6
+ metadata.gz: ee11120c0cd193aacadfe3dfe67a4da98e92937c53cee918a8e84795acddeedc5b157aa7563262bdfa5dfdb14e9b170894e653b5839893e76ae3daaa00238ec9
7
+ data.tar.gz: 4ab99d6a718dcafa47fdd390456a1b175d6a0d845f65b130caa0aab723f4b13a590f1da9bd7e6d483d0dacf2b2b08ab7939b1dd532b2ddb9af043441a42f9e58
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.9] - 2020-01-08
10
+ ### Added
11
+ - Added block support to yield other components
12
+ ### Changed
13
+ - Changed how the helper generated the component
14
+
9
15
  ## [1.0.8] - 2019-12-26
10
16
  ### Added
11
17
  - Added `c` local variable to access the component
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-component (1.0.8)
4
+ lite-component (1.0.9)
5
5
  actionview
6
6
 
7
7
  GEM
@@ -39,7 +39,7 @@ GEM
39
39
  generator_spec (0.9.4)
40
40
  activesupport (>= 3.0.0)
41
41
  railties (>= 3.0.0)
42
- i18n (1.7.0)
42
+ i18n (1.7.1)
43
43
  concurrent-ruby (~> 1.0)
44
44
  jaro_winkler (1.5.4)
45
45
  loofah (2.4.0)
@@ -51,7 +51,7 @@ GEM
51
51
  nokogiri (1.10.7)
52
52
  mini_portile2 (~> 2.4.0)
53
53
  parallel (1.19.1)
54
- parser (2.7.0.0)
54
+ parser (2.7.0.2)
55
55
  ast (~> 2.4.0)
56
56
  rack (2.0.8)
57
57
  rack-test (1.1.0)
@@ -73,19 +73,19 @@ GEM
73
73
  rspec-core (~> 3.9.0)
74
74
  rspec-expectations (~> 3.9.0)
75
75
  rspec-mocks (~> 3.9.0)
76
- rspec-core (3.9.0)
77
- rspec-support (~> 3.9.0)
76
+ rspec-core (3.9.1)
77
+ rspec-support (~> 3.9.1)
78
78
  rspec-expectations (3.9.0)
79
79
  diff-lcs (>= 1.2.0, < 2.0)
80
80
  rspec-support (~> 3.9.0)
81
- rspec-mocks (3.9.0)
81
+ rspec-mocks (3.9.1)
82
82
  diff-lcs (>= 1.2.0, < 2.0)
83
83
  rspec-support (~> 3.9.0)
84
- rspec-support (3.9.0)
85
- rubocop (0.78.0)
84
+ rspec-support (3.9.2)
85
+ rubocop (0.79.0)
86
86
  jaro_winkler (~> 1.5.1)
87
87
  parallel (~> 1.10)
88
- parser (>= 2.6)
88
+ parser (>= 2.7.0.1)
89
89
  rainbow (>= 2.2.2, < 4.0)
90
90
  ruby-progressbar (~> 1.7)
91
91
  unicode-display_width (>= 1.4.0, < 1.7)
data/README.md CHANGED
@@ -262,6 +262,36 @@ class AlertComponent < Lite::Component::Base
262
262
  end
263
263
  ```
264
264
 
265
+ To add components as part of another component build a `block` and `yield` it in the component's view.
266
+
267
+ ```erb
268
+ <%# app/views/components/_sidebar.html.erb %>
269
+
270
+ <div class="sidebar">
271
+ <%= component("sidebar/navigation", locals: { class_name: "js-nav-links" }) do |c| %>
272
+ <% c.add("sidebar/navigation/link", locals: { text: "Link: 1", path: "/home", active: false }) %>
273
+ <% c.add("sidebar/navigation/link", locals: { text: "Link: 2", path: "/about", active: true }) %>
274
+ <% c.add("sidebar/navigation/link", locals: { text: "Link: 3", path: "/help", active: false }) do |n_c| %>
275
+ <% n_c.add("sidebar/something", locals: { test: "something" }) %>
276
+ <% end %>
277
+ <% end %>
278
+ </div>
279
+ ```
280
+
281
+ ```erb
282
+ <%# app/views/components/sidebar/_navigation.html.erb %>
283
+
284
+ <div class="sidebar-navigation">
285
+ <%= c.yield %>
286
+ </div>
287
+ ```
288
+
289
+ ```erb
290
+ <%# app/views/components/sidebar/navigation/_link.html.erb %>
291
+
292
+ <%= link_to(text, path, class: ("active" if l.active)) %>
293
+ ```
294
+
265
295
  ## Development
266
296
 
267
297
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -4,9 +4,9 @@ module Lite
4
4
  module Component
5
5
  module ComponentHelper
6
6
 
7
- def component(name, options = {})
8
- name = name.component_path if name.respond_to?(:component_path)
9
- "#{name}_component".classify.constantize.render(self, options)
7
+ def component(name, options = {}, &block)
8
+ klass = Lite::Component::Base.build(name)
9
+ klass.render(self, options, &block)
10
10
  end
11
11
 
12
12
  end
@@ -7,13 +7,20 @@ module Lite
7
7
  include ActionView::Context
8
8
  include ActionView::Helpers
9
9
 
10
+ attr_accessor :components
10
11
  attr_reader :context, :options
11
12
  attr_writer :iteration
12
13
 
13
- def initialize(context, options = {})
14
+ # rubocop:disable Lint/UnusedMethodArgument
15
+ def initialize(context, options = {}, &block)
14
16
  @context = context
15
17
  @options = default_options.deep_merge(options)
18
+
19
+ @components = []
20
+
21
+ yield(self) if block_given?
16
22
  end
23
+ # rubocop:enable Lint/UnusedMethodArgument
17
24
 
18
25
  alias helpers context
19
26
  alias c context
@@ -21,6 +28,12 @@ module Lite
21
28
 
22
29
  class << self
23
30
 
31
+ def build(name)
32
+ return name if name.respond_to?(:component_path)
33
+
34
+ "#{name}_component".classify.constantize
35
+ end
36
+
24
37
  def component_name
25
38
  component_path.split('/').last
26
39
  end
@@ -29,13 +42,17 @@ module Lite
29
42
  name.underscore.sub('_component', '')
30
43
  end
31
44
 
32
- def render(context, options = {})
33
- klass = new(context, options)
45
+ def render(context, options = {}, &block)
46
+ klass = new(context, options, &block)
34
47
  klass.render
35
48
  end
36
49
 
37
50
  end
38
51
 
52
+ def add(name, options = {}, &block)
53
+ components << [name, options, block]
54
+ end
55
+
39
56
  def iteration
40
57
  @iteration ||= Lite::Component::Iteration.new(1, 0)
41
58
  end
@@ -67,6 +84,10 @@ module Lite
67
84
  "components/#{self.class.component_path}"
68
85
  end
69
86
 
87
+ def yield
88
+ context.safe_join(yield_content)
89
+ end
90
+
70
91
  private
71
92
 
72
93
  def default_options
@@ -82,6 +103,13 @@ module Lite
82
103
  }
83
104
  end
84
105
 
106
+ def yield_content
107
+ components.map do |name, options, block|
108
+ klass = self.class.build(name)
109
+ klass.render(context, options, &block)
110
+ end
111
+ end
112
+
85
113
  end
86
114
  end
87
115
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Component
5
5
 
6
- VERSION ||= '1.0.8'
6
+ VERSION ||= '1.0.9'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-26 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  requirements: []
194
- rubygems_version: 3.1.1
194
+ rubygems_version: 3.1.2
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Generate component from collections of data points