actionview-component 1.8.0 → 1.11.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: ab99ff30cf5a1d5fad5d3f670936b813d8923b9e4e5a3db566c0c08fa8cb7550
4
- data.tar.gz: 7432ee39d40af863647a1cdf220b7775592bfef12c84bbc8a6175d741b88c2ff
3
+ metadata.gz: 2c64114f4ba9a12fb68d0157a9f10a9fc423d09dbc181f0fd9f403671b61a047
4
+ data.tar.gz: 3c6306682e37e6f9f4d9ed66564130a225f122aaa71caffdd3ab063ad70524c3
5
5
  SHA512:
6
- metadata.gz: 53a8dc19f3caa79baf1c2fc754ee0b715885b83eaae13a7a3b6f2f25fb574dd6a0b109cd61328444abaf93ef55ded12413d59a5343fc707c544baba766c14ae7
7
- data.tar.gz: a73449076c9d073052c97ad8cc0d58a88d40f8973a576221a41d7b9e7ed15aeecd0d3704694e4f78bf918fbe6f4d875df0f389f71381b81ad0fed7f8fb4720d3
6
+ metadata.gz: b92ca951edd213245c3d0b473fe87650e0c87f4130a89bd4f628d7df0636fab794853943c172f57c10b648b43a98d7dfcca228be05d4c8120930b0ad5fb06683
7
+ data.tar.gz: 12bac559a2d557e72bbec729ae8402fcc08a8cc2f3c38d57eea332aa32391df4018447954c0b2e644076683573b55b70f7b02868524353645eca663abae5609c
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  rails_version: [5.0.0, 5.2.3, 6.0.0, master]
11
- ruby_version: [2.4.x, 2.5.x, 2.6.x]
11
+ ruby_version: [2.5.x, 2.6.x, 2.7.x]
12
12
  exclude:
13
13
  - rails_version: master
14
14
  ruby_version: 2.4.x
@@ -22,7 +22,7 @@ jobs:
22
22
  ruby-version: ${{ matrix.ruby_version }}
23
23
  - name: Build and test with Rake
24
24
  run: |
25
- gem install bundler:1.14.0
25
+ gem install bundler:1.17.3
26
26
  bundle update
27
27
  bundle install --jobs 4 --retry 3
28
28
  bundle exec rake
@@ -1,3 +1,37 @@
1
+ # v1.11.1
2
+
3
+ * Relax Capybara requirement.
4
+
5
+ *Joel Hawksley*
6
+
7
+ # v1.11.0
8
+
9
+ * Add support for Capybara matchers.
10
+
11
+ *Joel Hawksley*
12
+
13
+ * Add erb, haml, & slim template generators
14
+
15
+ *Asger Behncke Jacobsen*
16
+
17
+ # v1.10.0
18
+
19
+ * Deprecate all `render` syntaxes except for `render(MyComponent.new(foo: :bar))`
20
+
21
+ *Joel Hawksley*
22
+
23
+ # v1.9.0
24
+
25
+ * Remove initializer requirement for Ruby 2.7+
26
+
27
+ *Dylan Clark*
28
+
29
+ # v1.8.1
30
+
31
+ * Run validation checks before calling `#render?`.
32
+
33
+ *Ash Wilson*
34
+
1
35
  # v1.8.0
2
36
 
3
37
  * Remove the unneeded ComponentExamplesController and simplify preview rendering.
@@ -34,7 +34,7 @@ Here are a few things you can do that will increase the likelihood of your pull
34
34
  If you are the current maintainer of this gem:
35
35
 
36
36
  1. Create a branch for the release: `git checkout -b release-vxx.xx.xx`
37
- 1. Bump gem version in `lib/action_view/component/version.rb`.
37
+ 1. Bump gem version in `lib/action_view/component/version.rb`. Try to adhere to SemVer.
38
38
  1. Add version heading/entries to `CHANGELOG.md`.
39
39
  1. Make sure your local dependencies are up to date: `bundle`
40
40
  1. Ensure that tests are green: `bundle exec rake`
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.8.0)
4
+ actionview-component (1.11.1)
5
+ capybara (>= 3)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -61,6 +62,8 @@ GEM
61
62
  minitest (~> 5.1)
62
63
  tzinfo (~> 1.1)
63
64
  zeitwerk (~> 2.1, >= 2.1.8)
65
+ addressable (2.7.0)
66
+ public_suffix (>= 2.0.2, < 5.0)
64
67
  ast (2.4.0)
65
68
  better_html (1.0.14)
66
69
  actionview (>= 4.0)
@@ -71,6 +74,14 @@ GEM
71
74
  parser (>= 2.4)
72
75
  smart_properties
73
76
  builder (3.2.3)
77
+ capybara (3.31.0)
78
+ addressable
79
+ mini_mime (>= 0.1.3)
80
+ nokogiri (~> 1.8)
81
+ rack (>= 1.6.0)
82
+ rack-test (>= 0.6.3)
83
+ regexp_parser (~> 1.5)
84
+ xpath (~> 3.2)
74
85
  concurrent-ruby (1.1.5)
75
86
  crass (1.0.5)
76
87
  erubi (1.8.0)
@@ -101,6 +112,7 @@ GEM
101
112
  parallel (1.17.0)
102
113
  parser (2.6.3.0)
103
114
  ast (~> 2.4.0)
115
+ public_suffix (4.0.3)
104
116
  rack (2.0.8)
105
117
  rack-test (1.1.0)
106
118
  rack (>= 1.0, < 3)
@@ -132,6 +144,7 @@ GEM
132
144
  thor (>= 0.20.3, < 2.0)
133
145
  rainbow (3.0.0)
134
146
  rake (10.5.0)
147
+ regexp_parser (1.6.0)
135
148
  rubocop (0.74.0)
136
149
  jaro_winkler (~> 1.5.1)
137
150
  parallel (~> 1.10)
@@ -166,6 +179,8 @@ GEM
166
179
  websocket-driver (0.7.1)
167
180
  websocket-extensions (>= 0.1.0)
168
181
  websocket-extensions (0.1.4)
182
+ xpath (3.2.0)
183
+ nokogiri (~> 1.8)
169
184
  zeitwerk (2.1.10)
170
185
 
171
186
  PLATFORMS
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ _Note: This gem is in the process of a name / API change, see https://github.com/github/actionview-component/issues/206_
2
+
1
3
  # ActionView::Component
2
4
  `ActionView::Component` is a framework for building view components in Rails.
3
5
 
@@ -15,7 +17,7 @@ As the goal of this gem is to be upstreamed into Rails, it is designed to integr
15
17
 
16
18
  ## Compatibility
17
19
 
18
- `actionview-component` is tested for compatibility with combinations of Ruby `2.4`/`2.5`/`2.6` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`6.1.0.alpha`.
20
+ `actionview-component` is tested for compatibility with combinations of Ruby `2.5`/`2.6`/`2.7` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`6.1.0.alpha`.
19
21
 
20
22
  ## Installation
21
23
  Add this line to your application's Gemfile:
@@ -117,6 +119,18 @@ bin/rails generate component Example title content
117
119
  create app/components/example_component.html.erb
118
120
  ```
119
121
 
122
+ `ActionView::Component` includes template generators for the `erb`, `haml`, and `slim` template engines and will use the template engine specified in your Rails config (`config.generators.template_engine`) by default.
123
+
124
+ If you want to override this behavior, you can pass the template engine as an option to the generator:
125
+
126
+ ```bash
127
+ bin/rails generate component Example title content --template-engine slim
128
+ invoke test_unit
129
+ create test/components/example_component_test.rb
130
+ create app/components/example_component.rb
131
+ create app/components/example_component.html.slim
132
+ ```
133
+
120
134
  #### Implementation
121
135
 
122
136
  An `ActionView::Component` is a Ruby file and corresponding template file (in any format supported by Rails) with the same base name:
@@ -144,7 +158,7 @@ end
144
158
  We can render it in a view as:
145
159
 
146
160
  ```erb
147
- <%= render(TestComponent, title: "my title") do %>
161
+ <%= render(TestComponent.new(title: "my title")) do %>
148
162
  Hello, World!
149
163
  <% end %>
150
164
  ```
@@ -155,42 +169,12 @@ Which returns:
155
169
  <span title="my title">Hello, World!</span>
156
170
  ```
157
171
 
158
- ##### Supported `render` syntaxes
159
-
160
- Components can be rendered via:
161
-
162
- `render(TestComponent, foo: :bar)`
163
-
164
- `render(component: TestComponent, locals: { foo: :bar })`
165
-
166
- **Rendering components through models**
167
-
168
- Passing model instances will cause `render` to look for its respective component class.
169
-
170
- The component is instantiated with the rendered model instance.
171
-
172
- Example for a `Post` model:
173
-
174
- `render(@post)`
175
-
176
- ```ruby
177
- class PostComponent < ActionView::Component::Base
178
- def initialize(post)
179
- @post = post
180
- end
181
- end
182
- ```
183
-
184
- The following syntax has been deprecated and will be removed in v2.0.0:
185
-
186
- `render(TestComponent.new(foo: :bar))`
187
-
188
172
  #### Error case
189
173
 
190
174
  If the component is rendered with a blank title:
191
175
 
192
176
  ```erb
193
- <%= render(TestComponent, title: "") do %>
177
+ <%= render(TestComponent.new(title: "")) do %>
194
178
  Hello, World!
195
179
  <% end %>
196
180
  ```
@@ -227,7 +211,7 @@ end
227
211
  We can render it in a view as:
228
212
 
229
213
  ```erb
230
- <%= render(ModalComponent, user: {name: 'Jane'}) do |component| %>
214
+ <%= render(ModalComponent.new(user: {name: 'Jane'})) do |component| %>
231
215
  <% component.with(:header) do %>
232
216
  Hello <%= user[:name] %>
233
217
  <% end %>
@@ -265,7 +249,7 @@ end
265
249
  ```
266
250
 
267
251
  ```erb
268
- <%= render(ModalComponent, header: "Hi!") do |component| %>
252
+ <%= render(ModalComponent.new(header: "Hi!")) do |component| %>
269
253
  <% help_enabled? && component.with(:header) do %>
270
254
  <span class="help_icon"><%= component.header %></span>
271
255
  <% end %>
@@ -292,7 +276,7 @@ end
292
276
 
293
277
  `app/views/render_arg.html.erb`:
294
278
  ```erb
295
- <%= render(ModalComponent, header: "Hi!") do |component| %>
279
+ <%= render(ModalComponent.new(header: "Hi!")) do |component| %>
296
280
  <% component.with(:body) do %>
297
281
  <p>Have a great day.</p>
298
282
  <% end %>
@@ -338,7 +322,7 @@ end
338
322
 
339
323
  `app/views/render_arg.html.erb`:
340
324
  ```erb
341
- <%= render(ModalComponent, header: "Hi!") do |component| %>
325
+ <%= render(ModalComponent.new(header: "Hi!")) do |component| %>
342
326
  <% component.with(:body) do %>
343
327
  <p>Have a great day.</p>
344
328
  <% end %>
@@ -347,7 +331,7 @@ end
347
331
 
348
332
  `app/views/with_block.html.erb`:
349
333
  ```erb
350
- <%= render(ModalComponent) do |component| %>
334
+ <%= render(ModalComponent.new) do |component| %>
351
335
  <% component.with(:header) do %>
352
336
  <span class="help_icon">Hello</span>
353
337
  <% end %>
@@ -359,7 +343,7 @@ end
359
343
 
360
344
  `app/views/no_header.html.erb`:
361
345
  ```erb
362
- <%= render(ModalComponent) do |component| %>
346
+ <%= render(ModalComponent.new) do |component| %>
363
347
  <% component.with(:body) do %>
364
348
  <p>Have a great day.</p>
365
349
  <% end %>
@@ -386,7 +370,7 @@ or the view that renders the component:
386
370
  ```erb
387
371
  <!-- app/views/_banners.html.erb -->
388
372
  <% if current_user.requires_confirmation? %>
389
- <%= render(ConfirmEmailComponent, user: current_user) %>
373
+ <%= render(ConfirmEmailComponent.new(user: current_user)) %>
390
374
  <% end %>
391
375
  ```
392
376
 
@@ -414,22 +398,21 @@ end
414
398
 
415
399
  ```erb
416
400
  <!-- app/views/_banners.html.erb -->
417
- <%= render(ConfirmEmailComponent, user: current_user) %>
401
+ <%= render(ConfirmEmailComponent.new(user: current_user)) %>
418
402
  ```
419
403
 
420
404
  ### Testing
421
405
 
422
- Components are unit tested directly. The `render_inline` test helper wraps the result in `Nokogiri.HTML`, allowing us to test the component above as:
406
+ Components are unit tested directly. The `render_inline` test helper is compatible with Capybara matchers, allowing us to test the component above as:
423
407
 
424
408
  ```ruby
425
409
  require "action_view/component/test_case"
426
410
 
427
411
  class MyComponentTest < ActionView::Component::TestCase
428
412
  test "render component" do
429
- assert_equal(
430
- %(<span title="my title">Hello, World!</span>),
431
- render_inline(TestComponent, title: "my title") { "Hello, World!" }.to_html
432
- )
413
+ render_inline(TestComponent.new(title: "my title")) { "Hello, World!" }
414
+
415
+ assert_selector("span[title='my title']", "Hello, World!")
433
416
  end
434
417
  end
435
418
  ```
@@ -443,10 +426,9 @@ To test a specific variant you can wrap your test with the `with_variant` helper
443
426
  ```ruby
444
427
  test "render component for tablet" do
445
428
  with_variant :tablet do
446
- assert_equal(
447
- %(<span title="my title">Hello, tablets!</span>),
448
- render_inline(TestComponent, title: "my title") { "Hello, tablets!" }.css("span").to_html
449
- )
429
+ render_inline(TestComponent.new(title: "my title")) { "Hello, tablets!" }
430
+
431
+ assert_selector("span[title='my title']", "Hello, tablets!")
450
432
  end
451
433
  end
452
434
  ```
@@ -462,11 +444,11 @@ You can define as many examples as you want:
462
444
 
463
445
  class TestComponentPreview < ActionView::Component::Preview
464
446
  def with_default_title
465
- render(TestComponent, title: "Test component default")
447
+ render(TestComponent.new(title: "Test component default"))
466
448
  end
467
449
 
468
450
  def with_long_title
469
- render(TestComponent, title: "This is a really long title to see how the component renders this")
451
+ render(TestComponent.new(title: "This is a really long title to see how the component renders this"))
470
452
  end
471
453
  end
472
454
  ```
@@ -528,6 +510,11 @@ To use component previews, set the following in `config/application.rb`:
528
510
  config.action_view_component.preview_path = "#{Rails.root}/spec/components/previews"
529
511
  ```
530
512
 
513
+ ### Initializer requirement
514
+
515
+ In Ruby 2.6.x and below, ActionView::Component requires the presence of an `initialize` method in each component.
516
+ However, `initialize` is no longer required for projects using 2.7.x and above.
517
+
531
518
  ## Frequently Asked Questions
532
519
 
533
520
  ### Can I use other templating languages besides ERB?
@@ -583,10 +570,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github
583
570
  |@elia|@cesariouy|@spdawson|@rmacklin|@michaelem|
584
571
  |Milan||United Kingdom||Berlin|
585
572
 
586
- |<img src="https://avatars.githubusercontent.com/mellowfish?s=256" alt="mellowfish" width="128" />|<img src="https://avatars.githubusercontent.com/horacio?s=256" alt="horacio" width="128" />|<img src="https://avatars.githubusercontent.com/dukex?s=256" alt="dukex" width="128" />|<img src="https://avatars.githubusercontent.com/dark-panda?s=256" alt="dark-panda" width="128" />|
587
- |:---:|:---:|:---:|:---:|
588
- |@mellowfish|@horacio|@dukex|@dark-panda|
589
- |Spring Hill, TN|Buenos Aires|São Paulo||
573
+ |<img src="https://avatars.githubusercontent.com/mellowfish?s=256" alt="mellowfish" width="128" />|<img src="https://avatars.githubusercontent.com/horacio?s=256" alt="horacio" width="128" />|<img src="https://avatars.githubusercontent.com/dukex?s=256" alt="dukex" width="128" />|<img src="https://avatars.githubusercontent.com/dark-panda?s=256" alt="dark-panda" width="128" />|<img src="https://avatars.githubusercontent.com/smashwilson?s=256" alt="smashwilson" width="128" />|
574
+ |:---:|:---:|:---:|:---:|:---:|
575
+ |@mellowfish|@horacio|@dukex|@dark-panda|@smashwilson|
576
+ |Spring Hill, TN|Buenos Aires|São Paulo||Gambrills, MD|
590
577
 
591
578
  ## License
592
579
 
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  spec.required_ruby_version = ">= 2.3.0"
36
36
 
37
+ spec.add_runtime_dependency "capybara", ">= 3"
37
38
  spec.add_development_dependency "bundler", ">= 1.14"
38
39
  spec.add_development_dependency "rake", "~> 10.0"
39
40
  spec.add_development_dependency "minitest", "= 5.1.0"
@@ -48,8 +48,6 @@ module ActionView
48
48
  @virtual_path ||= virtual_path
49
49
  @variant = @lookup_context.variants.first
50
50
 
51
- return "" unless render?
52
-
53
51
  old_current_template = @current_template
54
52
  @current_template = self
55
53
 
@@ -57,6 +55,8 @@ module ActionView
57
55
 
58
56
  validate!
59
57
 
58
+ return "" unless render?
59
+
60
60
  send(self.class.call_method_name(@variant))
61
61
  ensure
62
62
  @current_template = old_current_template
@@ -142,15 +142,11 @@ module ActionView
142
142
 
143
143
  def source_location
144
144
  @source_location ||=
145
- begin
146
- # Require #initialize to be defined so that we can use
147
- # method#source_location to look up the file name
148
- # of the component.
149
- #
150
- # If we were able to only support Ruby 2.7+,
151
- # We could just use Module#const_source_location,
152
- # rendering this unnecessary.
153
- #
145
+ if const_source_location_supported?
146
+ const_source_location(self.name)[0]
147
+ else
148
+ # Require `#initialize` to be defined so that we can use `method#source_location`
149
+ # to look up the filename of the component.
154
150
  initialize_method = instance_method(:initialize)
155
151
  initialize_method.source_location[0] if initialize_method.owner == self
156
152
  end
@@ -210,6 +206,10 @@ module ActionView
210
206
 
211
207
  private
212
208
 
209
+ def const_source_location_supported?
210
+ respond_to? :const_source_location # introduced in Ruby 2.7
211
+ end
212
+
213
213
  def matching_views_in_source_location
214
214
  return [] unless source_location
215
215
  (Dir["#{source_location.chomp(File.extname(source_location))}.*{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [source_location])
@@ -232,7 +232,12 @@ module ActionView
232
232
  @template_errors ||=
233
233
  begin
234
234
  errors = []
235
- errors << "#{self} must implement #initialize." if source_location.nil?
235
+ if source_location.nil? && !const_source_location_supported?
236
+ # Require `#initialize` to be defined so that we can use `method#source_location`
237
+ # to look up the filename of the component.
238
+ errors << "#{self} must implement #initialize."
239
+ end
240
+
236
241
  errors << "Could not find a template file for #{self}." if templates.empty?
237
242
 
238
243
  if templates.count { |template| template[:variant].nil? } > 1
@@ -1,24 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Monkey patch ActionView::Base#render to support ActionView::Component
4
- #
5
- # A version of this monkey patch was upstreamed in https://github.com/rails/rails/pull/36388
6
- # We'll need to upstream an updated version of this eventually.
7
4
  module ActionView
8
5
  module Component
9
6
  module RenderMonkeyPatch # :nodoc:
10
7
  def render(options = {}, args = {}, &block)
11
8
  if options.respond_to?(:render_in)
9
+ options.render_in(self, &block)
10
+ elsif options.is_a?(Class) && options < ActionView::Component::Base
12
11
  ActiveSupport::Deprecation.warn(
13
- "passing component instances (`render MyComponent.new(foo: :bar)`) has been deprecated and will be removed in v2.0.0. Use `render MyComponent, foo: :bar` instead."
12
+ "`render MyComponent, foo: :bar` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
14
13
  )
15
14
 
16
- options.render_in(self, &block)
17
- elsif options.is_a?(Class) && options < ActionView::Component::Base
18
15
  options.new(args).render_in(self, &block)
19
16
  elsif options.is_a?(Hash) && options.has_key?(:component)
17
+ ActiveSupport::Deprecation.warn(
18
+ "`render component: MyComponent, locals: { foo: :bar }` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
19
+ )
20
+
20
21
  options[:component].new(options[:locals]).render_in(self, &block)
21
22
  elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil?
23
+ ActiveSupport::Deprecation.warn(
24
+ "rendering objects that respond_to `to_component_class` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead."
25
+ )
26
+
22
27
  options.to_component_class.new(options).render_in(self, &block)
23
28
  else
24
29
  super
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "capybara/minitest"
4
+
3
5
  module ActionView
4
6
  module Component
5
7
  module TestHelpers
8
+ include Capybara::Minitest::Assertions
9
+
10
+ def page
11
+ Capybara::Node::Simple.new(@raw)
12
+ end
13
+
6
14
  def render_inline(component, **args, &block)
7
- Nokogiri::HTML.fragment(controller.view_context.render(component, args, &block))
15
+ @raw = controller.view_context.render(component, args, &block)
16
+
17
+ Nokogiri::HTML.fragment(@raw)
8
18
  end
9
19
 
10
20
  def controller
@@ -4,8 +4,8 @@ module ActionView
4
4
  module Component
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 8
8
- PATCH = 0
7
+ MINOR = 11
8
+ PATCH = 1
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -6,15 +6,18 @@ module Rails
6
6
  source_root File.expand_path("templates", __dir__)
7
7
 
8
8
  argument :attributes, type: :array, default: [], banner: "attribute"
9
- hook_for :test_framework
10
9
  check_class_collision suffix: "Component"
11
10
 
11
+ class_option :require_content, type: :boolean, default: false
12
+
12
13
  def create_component_file
13
14
  template "component.rb", File.join("app/components", class_path, "#{file_name}_component.rb")
14
15
  end
15
16
 
16
- def create_template_file
17
- template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
17
+ hook_for :test_framework
18
+
19
+ hook_for :template_engine do |instance, template_engine|
20
+ instance.invoke template_engine, [instance.name], require_content: instance.send(:requires_content?)
18
21
  end
19
22
 
20
23
  private
@@ -24,6 +27,7 @@ module Rails
24
27
  end
25
28
 
26
29
  def requires_content?
30
+ return if behavior == :revoke
27
31
  return @requires_content if @asked
28
32
 
29
33
  @asked = true
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb"
4
+
5
+ module Erb
6
+ module Generators
7
+ class ComponentGenerator < Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb/component_generator"
4
+
5
+ module Haml
6
+ module Generators
7
+ class ComponentGenerator < Erb::Generators::ComponentGenerator
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.haml", File.join("app/components", class_path, "#{file_name}_component.html.haml")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ <%- if requires_content? -%>
2
+ <%= "= content" %>
3
+ <%- else -%>
4
+ %div Add <%= class_name %> template here
5
+ <%- end -%>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb/component_generator"
4
+
5
+ module Slim
6
+ module Generators
7
+ class ComponentGenerator < Erb::Generators::ComponentGenerator
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :require_content, type: :boolean, default: false
11
+
12
+ def copy_view_file
13
+ template "component.html.slim", File.join("app/components", class_path, "#{file_name}_component.html.slim")
14
+ end
15
+
16
+ private
17
+
18
+ def requires_content?
19
+ options["require_content"]
20
+ end
21
+
22
+ def file_name
23
+ @_file_name ||= super.sub(/_component\z/i, "")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ <%- if requires_content? -%>
2
+ = content
3
+ <%- else -%>
4
+ div Add <%= class_name %> template here
5
+ <%- end -%>
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -156,10 +170,15 @@ files:
156
170
  - lib/action_view/component/version.rb
157
171
  - lib/rails/generators/component/USAGE
158
172
  - lib/rails/generators/component/component_generator.rb
159
- - lib/rails/generators/component/templates/component.html.erb.tt
160
173
  - lib/rails/generators/component/templates/component.rb.tt
174
+ - lib/rails/generators/erb/component_generator.rb
175
+ - lib/rails/generators/erb/templates/component.html.erb.tt
176
+ - lib/rails/generators/haml/component_generator.rb
177
+ - lib/rails/generators/haml/templates/component.html.haml.tt
161
178
  - lib/rails/generators/rspec/component_generator.rb
162
179
  - lib/rails/generators/rspec/templates/component_spec.rb.tt
180
+ - lib/rails/generators/slim/component_generator.rb
181
+ - lib/rails/generators/slim/templates/component.html.slim
163
182
  - lib/rails/generators/test_unit/component_generator.rb
164
183
  - lib/rails/generators/test_unit/templates/component_test.rb.tt
165
184
  - lib/railties/lib/rails.rb