view_component 2.15.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e01b3b2899158831379c51c72086d84ca838b829a9638eeaec381aa287fa8c8
4
- data.tar.gz: fab254768f2f88651ed2c89e9e09ef5fa7e50524dad061435e5abd4e7de1a4ae
3
+ metadata.gz: 9ccdcdb195fbc49953c3663294a7345eb012f88344d1375456a07c6ef781b1d8
4
+ data.tar.gz: b2cf7cb1139e318f2ca7712242e610c31a42c78448a5d3151db1550a41e00355
5
5
  SHA512:
6
- metadata.gz: b1ce90df482ab031bf57b808ec1cd0015774d3061733ae4e934d18a8b569e0aa6d22ac71107016ca0ab73f76acb720c7113d21daba2a74a5d313f53ae245e435
7
- data.tar.gz: 96e33d8a65235bf8831ce07aec2f13b5bec2617be30c2a11cca2fa969516d167be4eaf2390a6296db2f1e61f1523115e2fd53aa6af1e39a6d661f85a03baf626
6
+ metadata.gz: 72657816a14d62166791f37d2f83cfd81efe8f186678bcf21e40c50d38d64663fbc4e2b9fe881820ba26f2a7ea258d5d6c0cb47a73132d5443f66db3489d1921
7
+ data.tar.gz: e7abe1071862dfb3208e2615176fd352b0f6cd6e7ef947b1dfb4528e435682908cd01ab8091b33612b234eebf7121a7dd00e5cb8890bc6ae1160fdf5bcbdcd3f
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # 2.16.0
4
+
5
+ * Add `--sidecar` option to the erb, haml and slim generators. Places the generated template in the sidecar directory.
6
+
7
+ *Michael van Rooijen*
8
+
3
9
  # 2.15.0
4
10
 
5
11
  * Add support for templates as ViewComponent::Preview examples.
data/README.md CHANGED
@@ -341,15 +341,25 @@ As an alternative, views and other assets can be placed in a sidecar directory w
341
341
  ```
342
342
  app/components
343
343
  ├── ...
344
- ├── test_component.rb
345
- ├── test_component
346
- | ├── test_component.css
347
- | ├── test_component.html.erb
348
- | └── test_component.js
344
+ ├── example_component.rb
345
+ ├── example_component
346
+ | ├── example_component.css
347
+ | ├── example_component.html.erb
348
+ | └── example_component.js
349
349
  ├── ...
350
350
 
351
351
  ```
352
352
 
353
+ To generate a component with a sidecar directory, use the `--sidecar` flag:
354
+
355
+ ```
356
+ bin/rails generate component Example title content --sidecar
357
+ invoke test_unit
358
+ create test/components/example_component_test.rb
359
+ create app/components/example_component.rb
360
+ create app/components/example_component/example_component.html.erb
361
+ ```
362
+
353
363
  ### Conditional Rendering
354
364
 
355
365
  Components can implement a `#render?` method to be called after initialization to determine if the component should render.
@@ -980,10 +990,10 @@ ViewComponent is built by:
980
990
  |@maxbeizer|@franco|@tbroad-ramsey|@jensljungblad|@bbugh|
981
991
  |Nashville, TN|Switzerland|Spring Hill, TN|New York, NY|Austin, TX|
982
992
 
983
- |<img src="https://avatars.githubusercontent.com/johannesengl?s=256" alt="johannesengl" width="128" />|<img src="https://avatars.githubusercontent.com/czj?s=256" alt="czj" width="128" />|
984
- |:---:|:---:|
985
- |@johannesengl|@czj|
986
- |Berlin, Germany|Paris, France|
993
+ |<img src="https://avatars.githubusercontent.com/johannesengl?s=256" alt="johannesengl" width="128" />|<img src="https://avatars.githubusercontent.com/czj?s=256" alt="czj" width="128" />|<img src="https://avatars.githubusercontent.com/mrrooijen?s=256" alt="mrrooijen" width="128" />|
994
+ |:---:|:---:|:---:|
995
+ |@johannesengl|@czj|@mrrooijen|
996
+ |Berlin, Germany|Paris, France|The Netherlands|
987
997
 
988
998
  ## License
989
999
 
@@ -6,13 +6,22 @@ module Erb
6
6
  module Generators
7
7
  class ComponentGenerator < Base
8
8
  source_root File.expand_path("templates", __dir__)
9
+ class_option :sidecar, type: :boolean, default: false
9
10
 
10
11
  def copy_view_file
11
- template "component.html.erb", File.join("app/components", class_path, "#{file_name}_component.html.erb")
12
+ template "component.html.erb", destination
12
13
  end
13
14
 
14
15
  private
15
16
 
17
+ def destination
18
+ if options["sidecar"]
19
+ File.join("app/components", class_path, "#{file_name}_component", "#{file_name}_component.html.erb")
20
+ else
21
+ File.join("app/components", class_path, "#{file_name}_component.html.erb")
22
+ end
23
+ end
24
+
16
25
  def file_name
17
26
  @_file_name ||= super.sub(/_component\z/i, "")
18
27
  end
@@ -6,13 +6,22 @@ module Haml
6
6
  module Generators
7
7
  class ComponentGenerator < Erb::Generators::ComponentGenerator
8
8
  source_root File.expand_path("templates", __dir__)
9
+ class_option :sidecar, type: :boolean, default: false
9
10
 
10
11
  def copy_view_file
11
- template "component.html.haml", File.join("app/components", class_path, "#{file_name}_component.html.haml")
12
+ template "component.html.haml", destination
12
13
  end
13
14
 
14
15
  private
15
16
 
17
+ def destination
18
+ if options["sidecar"]
19
+ File.join("app/components", class_path, "#{file_name}_component", "#{file_name}_component.html.haml")
20
+ else
21
+ File.join("app/components", class_path, "#{file_name}_component.html.haml")
22
+ end
23
+ end
24
+
16
25
  def file_name
17
26
  @_file_name ||= super.sub(/_component\z/i, "")
18
27
  end
@@ -6,13 +6,22 @@ module Slim
6
6
  module Generators
7
7
  class ComponentGenerator < Erb::Generators::ComponentGenerator
8
8
  source_root File.expand_path("templates", __dir__)
9
+ class_option :sidecar, type: :boolean, default: false
9
10
 
10
11
  def copy_view_file
11
- template "component.html.slim", File.join("app/components", class_path, "#{file_name}_component.html.slim")
12
+ template "component.html.slim", destination
12
13
  end
13
14
 
14
15
  private
15
16
 
17
+ def destination
18
+ if options["sidecar"]
19
+ File.join("app/components", class_path, "#{file_name}_component", "#{file_name}_component.html.slim")
20
+ else
21
+ File.join("app/components", class_path, "#{file_name}_component.html.slim")
22
+ end
23
+ end
24
+
16
25
  def file_name
17
26
  @_file_name ||= super.sub(/_component\z/i, "")
18
27
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 15
6
+ MINOR = 16
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-13 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport