view_component 2.37.0 → 2.38.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 +4 -4
- data/docs/CHANGELOG.md +7 -0
- data/lib/rails/generators/abstract_generator.rb +19 -2
- data/lib/rails/generators/component/component_generator.rb +4 -0
- data/lib/rails/generators/component/templates/component.rb.tt +1 -1
- data/lib/rails/generators/erb/component_generator.rb +9 -0
- data/lib/rails/generators/erb/templates/component.html.erb.tt +1 -1
- data/lib/rails/generators/stimulus/component_generator.rb +26 -0
- data/lib/rails/generators/stimulus/templates/component_controller.js.tt +7 -0
- data/lib/view_component/base.rb +8 -0
- data/lib/view_component/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f5e17579fef222144f1b4566ee9061514f05879ac9a60fe405d5979624b1ae5
|
4
|
+
data.tar.gz: 40d115097a28b8340bef59b09f527357e3e2f8837178d268de0f43330be46cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407e8525abd5a6ef76f5a0178c837f855494565030cd46a5c076bcaa8b88f3888a3d6771e6d461c36a207481e547f6cf286eccc658b4667d13073f3b1ed8796d
|
7
|
+
data.tar.gz: 2f850ee69467621b7a3989f7045160efa5d342e520df04ba6f91044a5e48f6b8df58a573b1555aea8da0c3f4bf6a4a407ffecca92c46def9c906104473415d4f
|
data/docs/CHANGELOG.md
CHANGED
@@ -7,6 +7,13 @@ title: Changelog
|
|
7
7
|
|
8
8
|
## main
|
9
9
|
|
10
|
+
## 2.38.0
|
11
|
+
|
12
|
+
* Add `--stimulus` flag to the component generator. Generates a Stimulus controller alongside the component.
|
13
|
+
* Add config option `config.view_component.generate_stimulus_controller` to always generate a Stimulus controller.
|
14
|
+
|
15
|
+
*Sebastien Auriault*
|
16
|
+
|
10
17
|
## 2.37.0
|
11
18
|
|
12
19
|
* Clarify slots example in docs to reduce naming confusion.
|
@@ -11,13 +11,21 @@ module ViewComponent
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def destination
|
14
|
+
File.join(destination_directory, "#{destination_file_name}.html.#{engine_name}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def destination_directory
|
14
18
|
if options["sidecar"]
|
15
|
-
File.join(component_path, class_path,
|
19
|
+
File.join(component_path, class_path, destination_file_name)
|
16
20
|
else
|
17
|
-
File.join(component_path, class_path
|
21
|
+
File.join(component_path, class_path)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
25
|
+
def destination_file_name
|
26
|
+
"#{file_name}_component"
|
27
|
+
end
|
28
|
+
|
21
29
|
def file_name
|
22
30
|
@_file_name ||= super.sub(/_component\z/i, "")
|
23
31
|
end
|
@@ -25,5 +33,14 @@ module ViewComponent
|
|
25
33
|
def component_path
|
26
34
|
ViewComponent::Base.view_component_path
|
27
35
|
end
|
36
|
+
|
37
|
+
def stimulus_controller
|
38
|
+
if options["stimulus"]
|
39
|
+
File.join(destination_directory, destination_file_name).
|
40
|
+
sub("#{component_path}/", "").
|
41
|
+
gsub("_", "-").
|
42
|
+
gsub("/", "--")
|
43
|
+
end
|
44
|
+
end
|
28
45
|
end
|
29
46
|
end
|
@@ -12,6 +12,8 @@ module Rails
|
|
12
12
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
13
13
|
check_class_collision suffix: "Component"
|
14
14
|
class_option :inline, type: :boolean, default: false
|
15
|
+
class_option :stimulus, type: :boolean, default: ViewComponent::Base.generate_stimulus_controller
|
16
|
+
class_option :sidecar, type: :boolean, default: false
|
15
17
|
|
16
18
|
def create_component_file
|
17
19
|
template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
|
@@ -21,6 +23,8 @@ module Rails
|
|
21
23
|
|
22
24
|
hook_for :preview, type: :boolean
|
23
25
|
|
26
|
+
hook_for :stimulus, type: :boolean
|
27
|
+
|
24
28
|
hook_for :template_engine do |instance, template_engine|
|
25
29
|
instance.invoke template_engine, [instance.name]
|
26
30
|
end
|
@@ -8,7 +8,7 @@ class <%= class_name %>Component < <%= parent_class %>
|
|
8
8
|
<%- end -%>
|
9
9
|
<%- if initialize_call_method_for_inline? -%>
|
10
10
|
def call
|
11
|
-
content_tag :h1, "Hello world!"
|
11
|
+
content_tag :h1, "Hello world!"<%= ", data: { controller: \"#{stimulus_controller}\" }" if options["stimulus"] %>
|
12
12
|
end
|
13
13
|
<%- end -%>
|
14
14
|
|
@@ -11,6 +11,7 @@ module Erb
|
|
11
11
|
source_root File.expand_path("templates", __dir__)
|
12
12
|
class_option :sidecar, type: :boolean, default: false
|
13
13
|
class_option :inline, type: :boolean, default: false
|
14
|
+
class_option :stimulus, type: :boolean, default: false
|
14
15
|
|
15
16
|
def engine_name
|
16
17
|
"erb"
|
@@ -19,6 +20,14 @@ module Erb
|
|
19
20
|
def copy_view_file
|
20
21
|
super
|
21
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def data_attributes
|
27
|
+
if options["stimulus"]
|
28
|
+
" data-controller=\"#{stimulus_controller}\""
|
29
|
+
end
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
@@ -1 +1 @@
|
|
1
|
-
<div
|
1
|
+
<div<%= data_attributes %>>Add <%= class_name %> template here</div>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stimulus
|
4
|
+
module Generators
|
5
|
+
class ComponentGenerator < ::Rails::Generators::NamedBase
|
6
|
+
include ViewComponent::AbstractGenerator
|
7
|
+
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
class_option :sidecar, type: :boolean, default: false
|
10
|
+
|
11
|
+
def create_stimulus_controller
|
12
|
+
template "component_controller.js", destination
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def destination
|
18
|
+
if options["sidecar"]
|
19
|
+
File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component_controller.js")
|
20
|
+
else
|
21
|
+
File.join(component_path, class_path, "#{file_name}_component_controller.js")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/view_component/base.rb
CHANGED
@@ -278,6 +278,14 @@ module ViewComponent
|
|
278
278
|
#
|
279
279
|
mattr_accessor :show_previews_source, instance_writer: false, default: false
|
280
280
|
|
281
|
+
# Always generate a Stimulus controller alongside the component:
|
282
|
+
#
|
283
|
+
# config.view_component.generate_stimulus_controller = true
|
284
|
+
#
|
285
|
+
# Defaults to `false`.
|
286
|
+
#
|
287
|
+
mattr_accessor :generate_stimulus_controller, instance_writer: false, default: false
|
288
|
+
|
281
289
|
# Path for component files
|
282
290
|
#
|
283
291
|
# config.view_component.view_component_path = "app/my_components"
|
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.
|
4
|
+
version: 2.38.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: 2021-08-
|
11
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -287,6 +287,8 @@ files:
|
|
287
287
|
- lib/rails/generators/rspec/templates/component_spec.rb.tt
|
288
288
|
- lib/rails/generators/slim/component_generator.rb
|
289
289
|
- lib/rails/generators/slim/templates/component.html.slim.tt
|
290
|
+
- lib/rails/generators/stimulus/component_generator.rb
|
291
|
+
- lib/rails/generators/stimulus/templates/component_controller.js.tt
|
290
292
|
- lib/rails/generators/test_unit/component_generator.rb
|
291
293
|
- lib/rails/generators/test_unit/templates/component_test.rb.tt
|
292
294
|
- lib/view_component.rb
|
@@ -338,7 +340,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
338
340
|
- !ruby/object:Gem::Version
|
339
341
|
version: '0'
|
340
342
|
requirements: []
|
341
|
-
rubygems_version: 3.
|
343
|
+
rubygems_version: 3.2.22
|
342
344
|
signing_key:
|
343
345
|
specification_version: 4
|
344
346
|
summary: View components for Rails
|