lite-component 1.0.11 → 1.2.2

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: 6d80713505881c685b68cc3a8a5cb9442bec310351d4225b151f759770c12e5e
4
- data.tar.gz: 87a603392431946bed13580336860d07a750cac9af35e27a087fc4402b506572
3
+ metadata.gz: 4ffbec5ceb0f3be9a15613babd594ab2153ae669fe8a13438617952b5fe448d2
4
+ data.tar.gz: 4646a428fd1e4ae7fc3387b436182324e3a6b1f39cf9da91b1d604cfb6addd63
5
5
  SHA512:
6
- metadata.gz: a91cf54a2dbeff070e6a671cf59a1006d037666ea3552c8aa4ab68f943fa1e2cbc597399dcf5c959267a729c10abe4f3e5229e18fe8364e4603ca6222c42ad1e
7
- data.tar.gz: a32a1cf7dad38912c7b54cd80b4dbb4635c2a794216f98395f229045e210e2f2f0d021cde47cf2b856ef6f66ad59d32ed322320308c20a071cec83280b6ebc24
6
+ metadata.gz: 7a802961e847f6aa81e3c4cf637a35f426c8a78b32dd01bf86f3d37e3ac77ddb0b27d7b522522eac06e2ebae79fcfd803a7a3772419ee1377949535316e58016
7
+ data.tar.gz: 841ca0916d33d105e0a194b903b54133bfd2d0a80a7015491950f96d43b45d2bb3d5bb5a4ca34e95d6c85085cb6165d0112bff576138cb84a8417e5bbf83fbaa
data/.rubocop.yml CHANGED
@@ -1,10 +1,16 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-rake
3
4
  - rubocop-rspec
4
5
  AllCops:
5
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 3.0
6
7
  DisplayCopNames: true
7
8
  DisplayStyleGuide: true
9
+ NewCops: enable
10
+ Gemspec/RequiredRubyVersion:
11
+ Enabled: false
12
+ Layout/EmptyLinesAroundAttributeAccessor:
13
+ Enabled: true
8
14
  Layout/EmptyLinesAroundBlockBody:
9
15
  Exclude:
10
16
  - 'spec/**/**/*'
@@ -32,6 +38,8 @@ RSpec/ExampleLength:
32
38
  Enabled: false
33
39
  RSpec/MultipleExpectations:
34
40
  Enabled: false
41
+ Style/ArgumentsForwarding:
42
+ Enabled: false
35
43
  Style/Documentation:
36
44
  Enabled: false
37
45
  Style/ExpandPathArguments:
@@ -44,3 +52,5 @@ Style/HashTransformKeys:
44
52
  Enabled: true
45
53
  Style/HashTransformValues:
46
54
  Enabled: true
55
+ Style/SlicingWithRange:
56
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.2] - 2021-07-21
10
+ ### Changed
11
+ - Improved setup
12
+
13
+ ## [1.2.1] - 2021-07-21
14
+ ### Changed
15
+ - Improved Railtie support
16
+
17
+ ## [1.2.0] - 2021-07-19
18
+ ### Added
19
+ - Added Ruby 3.0 support
20
+
21
+ ## [1.1.0] - 2021-01-20
22
+ ### Added
23
+ - Add improved collection rendering
24
+ ### Removed
25
+ - Collection class is no longer needed
26
+
9
27
  ## [1.0.11] - 2020-04-24
10
28
  ### Added
11
29
  - Added `to_h` and `to_hash` aliases for dumping locals
data/Gemfile.lock CHANGED
@@ -1,59 +1,60 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-component (1.0.11)
4
+ lite-component (1.2.2)
5
5
  actionview
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (6.0.2.2)
11
- actionview (= 6.0.2.2)
12
- activesupport (= 6.0.2.2)
13
- rack (~> 2.0, >= 2.0.8)
10
+ actionpack (6.1.4)
11
+ actionview (= 6.1.4)
12
+ activesupport (= 6.1.4)
13
+ rack (~> 2.0, >= 2.0.9)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (6.0.2.2)
18
- activesupport (= 6.0.2.2)
17
+ actionview (6.1.4)
18
+ activesupport (= 6.1.4)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activesupport (6.0.2.2)
23
+ activesupport (6.1.4)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
- i18n (>= 0.7, < 2)
26
- minitest (~> 5.1)
27
- tzinfo (~> 1.1)
28
- zeitwerk (~> 2.2)
29
- ast (2.4.0)
25
+ i18n (>= 1.6, < 2)
26
+ minitest (>= 5.1)
27
+ tzinfo (~> 2.0)
28
+ zeitwerk (~> 2.3)
29
+ ast (2.4.2)
30
30
  builder (3.2.4)
31
31
  colorize (0.8.1)
32
- concurrent-ruby (1.1.6)
32
+ concurrent-ruby (1.1.9)
33
33
  crass (1.0.6)
34
- diff-lcs (1.3)
35
- erubi (1.9.0)
36
- fasterer (0.8.3)
34
+ diff-lcs (1.4.4)
35
+ erubi (1.10.0)
36
+ fasterer (0.9.0)
37
37
  colorize (~> 0.7)
38
38
  ruby_parser (>= 3.14.1)
39
39
  generator_spec (0.9.4)
40
40
  activesupport (>= 3.0.0)
41
41
  railties (>= 3.0.0)
42
- i18n (1.8.2)
42
+ i18n (1.8.10)
43
43
  concurrent-ruby (~> 1.0)
44
- jaro_winkler (1.5.4)
45
- loofah (2.5.0)
44
+ loofah (2.10.0)
46
45
  crass (~> 1.0.2)
47
46
  nokogiri (>= 1.5.9)
48
47
  method_source (1.0.0)
49
- mini_portile2 (2.4.0)
50
- minitest (5.14.0)
51
- nokogiri (1.10.9)
52
- mini_portile2 (~> 2.4.0)
53
- parallel (1.19.1)
54
- parser (2.7.1.1)
55
- ast (~> 2.4.0)
56
- rack (2.2.2)
48
+ mini_portile2 (2.5.3)
49
+ minitest (5.14.4)
50
+ nokogiri (1.11.7)
51
+ mini_portile2 (~> 2.5.0)
52
+ racc (~> 1.4)
53
+ parallel (1.20.1)
54
+ parser (3.0.2.0)
55
+ ast (~> 2.4.1)
56
+ racc (1.5.2)
57
+ rack (2.2.3)
57
58
  rack-test (1.1.0)
58
59
  rack (>= 1.0, < 3)
59
60
  rails-dom-testing (2.0.3)
@@ -61,50 +62,57 @@ GEM
61
62
  nokogiri (>= 1.6)
62
63
  rails-html-sanitizer (1.3.0)
63
64
  loofah (~> 2.3)
64
- railties (6.0.2.2)
65
- actionpack (= 6.0.2.2)
66
- activesupport (= 6.0.2.2)
65
+ railties (6.1.4)
66
+ actionpack (= 6.1.4)
67
+ activesupport (= 6.1.4)
67
68
  method_source
68
- rake (>= 0.8.7)
69
- thor (>= 0.20.3, < 2.0)
69
+ rake (>= 0.13)
70
+ thor (~> 1.0)
70
71
  rainbow (3.0.0)
71
- rake (13.0.1)
72
- rexml (3.2.4)
73
- rspec (3.9.0)
74
- rspec-core (~> 3.9.0)
75
- rspec-expectations (~> 3.9.0)
76
- rspec-mocks (~> 3.9.0)
77
- rspec-core (3.9.1)
78
- rspec-support (~> 3.9.1)
79
- rspec-expectations (3.9.1)
72
+ rake (13.0.6)
73
+ regexp_parser (2.1.1)
74
+ rexml (3.2.5)
75
+ rspec (3.10.0)
76
+ rspec-core (~> 3.10.0)
77
+ rspec-expectations (~> 3.10.0)
78
+ rspec-mocks (~> 3.10.0)
79
+ rspec-core (3.10.1)
80
+ rspec-support (~> 3.10.0)
81
+ rspec-expectations (3.10.1)
80
82
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.9.0)
82
- rspec-mocks (3.9.1)
83
+ rspec-support (~> 3.10.0)
84
+ rspec-mocks (3.10.2)
83
85
  diff-lcs (>= 1.2.0, < 2.0)
84
- rspec-support (~> 3.9.0)
85
- rspec-support (3.9.2)
86
- rubocop (0.82.0)
87
- jaro_winkler (~> 1.5.1)
86
+ rspec-support (~> 3.10.0)
87
+ rspec-support (3.10.2)
88
+ rubocop (1.18.3)
88
89
  parallel (~> 1.10)
89
- parser (>= 2.7.0.1)
90
+ parser (>= 3.0.0.0)
90
91
  rainbow (>= 2.2.2, < 4.0)
92
+ regexp_parser (>= 1.8, < 3.0)
91
93
  rexml
94
+ rubocop-ast (>= 1.7.0, < 2.0)
92
95
  ruby-progressbar (~> 1.7)
93
- unicode-display_width (>= 1.4.0, < 2.0)
94
- rubocop-performance (1.5.2)
95
- rubocop (>= 0.71.0)
96
- rubocop-rspec (1.38.1)
97
- rubocop (>= 0.68.1)
98
- ruby-progressbar (1.10.1)
99
- ruby_parser (3.14.2)
100
- sexp_processor (~> 4.9)
101
- sexp_processor (4.14.1)
102
- thor (1.0.1)
103
- thread_safe (0.3.6)
104
- tzinfo (1.2.7)
105
- thread_safe (~> 0.1)
106
- unicode-display_width (1.7.0)
107
- zeitwerk (2.3.0)
96
+ unicode-display_width (>= 1.4.0, < 3.0)
97
+ rubocop-ast (1.8.0)
98
+ parser (>= 3.0.1.1)
99
+ rubocop-performance (1.11.4)
100
+ rubocop (>= 1.7.0, < 2.0)
101
+ rubocop-ast (>= 0.4.0)
102
+ rubocop-rake (0.6.0)
103
+ rubocop (~> 1.0)
104
+ rubocop-rspec (2.4.0)
105
+ rubocop (~> 1.0)
106
+ rubocop-ast (>= 1.1.0)
107
+ ruby-progressbar (1.11.0)
108
+ ruby_parser (3.16.0)
109
+ sexp_processor (~> 4.15, >= 4.15.1)
110
+ sexp_processor (4.15.3)
111
+ thor (1.1.0)
112
+ tzinfo (2.0.4)
113
+ concurrent-ruby (~> 1.0)
114
+ unicode-display_width (2.0.0)
115
+ zeitwerk (2.4.2)
108
116
 
109
117
  PLATFORMS
110
118
  ruby
@@ -118,7 +126,8 @@ DEPENDENCIES
118
126
  rspec
119
127
  rubocop
120
128
  rubocop-performance
129
+ rubocop-rake
121
130
  rubocop-rspec
122
131
 
123
132
  BUNDLED WITH
124
- 2.1.4
133
+ 2.2.24
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
-
5
3
  module Rails
6
4
  class ComponentGenerator < Rails::Generators::NamedBase
7
5
 
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
3
+ require 'action_view' unless defined?(ActionView)
4
4
 
5
- %w[version engine iteration collection locals base].each do |filename|
6
- require "lite/component/#{filename}"
7
- end
5
+ require 'generators/rails/component_generator' if defined?(Rails::Generators)
8
6
 
9
- require 'generators/rails/component_generator'
7
+ require "lite/component/engine" if defined?(Rails::Engine)
8
+ require "lite/component/version"
9
+ require "lite/component/iteration"
10
+ require "lite/component/locals"
11
+ require "lite/component/base"
@@ -8,23 +8,24 @@ module Lite
8
8
  include ActionView::Helpers
9
9
 
10
10
  attr_accessor :components
11
- attr_reader :context, :options
12
- attr_writer :iteration
11
+ attr_reader :context, :iteration, :options
13
12
 
14
- # rubocop:disable Lint/UnusedMethodArgument
13
+ # rubocop:disable Layout/LineLength
15
14
  def initialize(context, options = {}, &block)
15
+ @components = []
16
+ @iteration = (options[:locals] || {}).delete(:iteration) || Lite::Component::Iteration.new(1, 0)
17
+
16
18
  @context = context
17
19
  @options = default_options.deep_merge(options)
18
20
 
19
- @components = []
20
-
21
- yield(self) if block_given?
21
+ yield(self) if block
22
22
  end
23
- # rubocop:enable Lint/UnusedMethodArgument
23
+ # rubocop:enable Layout/LineLength
24
24
 
25
25
  alias helpers context
26
26
  alias c context
27
27
  alias h helpers
28
+ alias i iteration
28
29
 
29
30
  class << self
30
31
 
@@ -53,12 +54,6 @@ module Lite
53
54
  components << [name, options, block]
54
55
  end
55
56
 
56
- def iteration
57
- @iteration ||= Lite::Component::Iteration.new(1, 0)
58
- end
59
-
60
- alias i iteration
61
-
62
57
  def locals
63
58
  @locals ||= Lite::Component::Locals.new(options[:locals])
64
59
  end
@@ -69,13 +64,9 @@ module Lite
69
64
  return unless render?
70
65
 
71
66
  collection = options.delete(:collection)
72
- return render_content if collection.nil? || !collection.respond_to?(:each)
67
+ return render_collection(collection) if collection.respond_to?(:each)
73
68
 
74
- Lite::Component::Collection.render(
75
- collection,
76
- component: self,
77
- spacer_template: options.delete(:spacer_template)
78
- )
69
+ render_content
79
70
  end
80
71
 
81
72
  def render?
@@ -109,6 +100,22 @@ module Lite
109
100
  }
110
101
  end
111
102
 
103
+ # rubocop:disable Metrics/AbcSize
104
+ def render_collection(collection)
105
+ collection_size = collection.size
106
+ spacer_template = options.delete(:spacer_template)
107
+
108
+ results = collection.each_with_object([]).with_index do |(item, array), index|
109
+ array << context.render(spacer_template) if index.positive? && spacer_template
110
+ iteration = Lite::Component::Iteration.new(collection_size, index)
111
+ instance = self.class.new(context, locals: { object: item, iteration: iteration })
112
+ array << instance.render
113
+ end
114
+
115
+ context.safe_join(results)
116
+ end
117
+ # rubocop:enable Metrics/AbcSize
118
+
112
119
  def yield_content
113
120
  components.map do |name, options, block|
114
121
  klass = self.class.build(name)
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/engine'
4
-
5
3
  module Lite
6
4
  module Component
7
- class Engine < ::Rails::Engine
5
+ class Engine < Rails::Engine
8
6
 
9
7
  initializer('lite-component.setup', group: :all) do |app|
10
8
  app.paths['config'] << File.join(config.root, 'app')
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Component
5
5
 
6
- VERSION ||= '1.0.11'
6
+ VERSION = '1.2.2'
7
7
 
8
8
  end
9
9
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  )
26
26
  else
27
27
  raise 'RubyGems 2.0 or newer is required to protect against ' \
28
- 'public gem pushes.'
28
+ 'public gem pushes.'
29
29
  end
30
30
 
31
31
  # Specify which files should be added to the gem when it is released.
@@ -46,5 +46,6 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency 'rspec'
47
47
  spec.add_development_dependency 'rubocop'
48
48
  spec.add_development_dependency 'rubocop-performance'
49
+ spec.add_development_dependency 'rubocop-rake'
49
50
  spec.add_development_dependency 'rubocop-rspec'
50
51
  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.11
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rubocop-rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +150,7 @@ dependencies:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
- description:
153
+ description:
140
154
  email:
141
155
  - j.gomez@drexed.com
142
156
  executables: []
@@ -166,7 +180,6 @@ files:
166
180
  - lib/generators/rails/templates/component.scss
167
181
  - lib/lite/component.rb
168
182
  - lib/lite/component/base.rb
169
- - lib/lite/component/collection.rb
170
183
  - lib/lite/component/engine.rb
171
184
  - lib/lite/component/iteration.rb
172
185
  - lib/lite/component/locals.rb
@@ -176,7 +189,7 @@ homepage: http://drexed.github.io/lite-component
176
189
  licenses:
177
190
  - MIT
178
191
  metadata: {}
179
- post_install_message:
192
+ post_install_message:
180
193
  rdoc_options: []
181
194
  require_paths:
182
195
  - lib
@@ -191,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
204
  - !ruby/object:Gem::Version
192
205
  version: '0'
193
206
  requirements: []
194
- rubygems_version: 3.1.2
195
- signing_key:
207
+ rubygems_version: 3.2.24
208
+ signing_key:
196
209
  specification_version: 4
197
210
  summary: Generate component from collections of data points
198
211
  test_files: []
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Component
5
- class Collection
6
-
7
- attr_reader :collection, :component, :spacer_template
8
-
9
- def initialize(collection, component:, spacer_template: nil)
10
- @collection = collection
11
- @component = component
12
- @spacer_template = spacer_template
13
- end
14
-
15
- class << self
16
-
17
- def render(collection, component)
18
- klass = new(collection, component)
19
- klass.render
20
- end
21
-
22
- end
23
-
24
- def render
25
- component.context.safe_join(iterated_collection)
26
- end
27
-
28
- private
29
-
30
- def collection_size
31
- @collection_size ||= begin
32
- if collection.respond_to?(:size)
33
- collection.size
34
- elsif collection.respond_to?(:to_a)
35
- collection.to_a.size
36
- elsif collection.respond_to?(:to_hash)
37
- collection.to_hash.size
38
- end
39
- end
40
- end
41
-
42
- # rubocop:disable Metrics/AbcSize
43
- def iterated_collection
44
- collection.each_with_object([]).with_index do |(object, array), index|
45
- component.iteration = Lite::Component::Iteration.new(collection_size, index)
46
- component.options.deep_merge!(locals: { object: object, iteration: component.iteration })
47
- content = component.render_content
48
- next if content.nil?
49
-
50
- array << content
51
- next unless spacer_template && !component.iteration.last?
52
-
53
- array << component.context.render(spacer_template)
54
- end
55
- end
56
- # rubocop:enable Metrics/AbcSize
57
-
58
- end
59
- end
60
- end