view_component 4.0.0.rc3 → 4.0.0.rc5
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 +4 -4
- data/docs/CHANGELOG.md +20 -0
- data/lib/generators/view_component/abstract_generator.rb +56 -0
- data/lib/generators/view_component/component/component_generator.rb +80 -0
- data/lib/generators/view_component/component/templates/component.rb.tt +21 -0
- data/lib/generators/view_component/erb/erb_generator.rb +34 -0
- data/lib/generators/view_component/erb/templates/component.html.erb.tt +1 -0
- data/lib/generators/view_component/haml/haml_generator.rb +22 -0
- data/lib/generators/view_component/haml/templates/component.html.haml.tt +1 -0
- data/lib/generators/view_component/locale/locale_generator.rb +46 -0
- data/lib/generators/view_component/preview/preview_generator.rb +39 -0
- data/lib/generators/view_component/preview/templates/component_preview.rb.tt +9 -0
- data/lib/generators/view_component/rspec/rspec_generator.rb +31 -0
- data/lib/generators/view_component/rspec/templates/component_spec.rb.tt +15 -0
- data/lib/generators/view_component/slim/slim_generator.rb +22 -0
- data/lib/generators/view_component/slim/templates/component.html.slim.tt +1 -0
- data/lib/generators/view_component/stimulus/stimulus_generator.rb +44 -0
- data/lib/generators/view_component/stimulus/templates/component_controller.js.tt +7 -0
- data/lib/generators/view_component/stimulus/templates/component_controller.ts.tt +9 -0
- data/lib/generators/view_component/tailwindcss/tailwindcss_generator.rb +11 -0
- data/lib/generators/view_component/tailwindcss/templates/component.html.erb.tt +1 -0
- data/lib/generators/view_component/test_unit/templates/component_test.rb.tt +12 -0
- data/lib/generators/view_component/test_unit/test_unit_generator.rb +20 -0
- data/lib/view_component/base.rb +0 -6
- data/lib/view_component/compiler.rb +0 -10
- data/lib/view_component/template.rb +2 -2
- data/lib/view_component/version.rb +1 -1
- metadata +22 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2022f4dafcbde4a0b374fc19399e58a9a7ff97ba64b3567de75ec24c9bb9e8eb
|
4
|
+
data.tar.gz: 2936979e68ecbe66cc0cc0b8a9ab77064265cb4d0763974daa6eb22c4b2a4e5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c124cc7b4de10d07896f5c1fd80a2533a606f29de5406836b6d63968261e1de54e1cbe682879a2e20fe66e3173f1178111ce5047177b9130ac359cbdb7b759d0
|
7
|
+
data.tar.gz: 228eee5270b9d0b6d2ac0395151255759fb73faea87365a79fc42b301b7d5ddac0f6d260f040a5801981a067f84f02735624236af86937ed5eee7a2080aad2c9
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,26 @@ nav_order: 6
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 4.0.0.rc5
|
14
|
+
|
15
|
+
* Revert change setting `#format`. In GitHub's codebase, the change led to hard-to-detect failures. For example, components rendered from controllers included layouts when they didn't before. In other cases, the response `content_type` changed, breaking downstream consumers. For cases where a specific content type is needed, use:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
respond_to do |f|
|
19
|
+
f.html_fragment do
|
20
|
+
render(MyComponent.new)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
*Joel Hawksley*
|
26
|
+
|
27
|
+
## 4.0.0.rc4
|
28
|
+
|
29
|
+
* Fix issue where generators were not included in published gem.
|
30
|
+
|
31
|
+
*Jean-Louis Giordano*
|
32
|
+
|
13
33
|
## 4.0.0.rc3
|
14
34
|
|
15
35
|
* Reformat the avatars section to arrange them in a grid.
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module AbstractGenerator
|
5
|
+
def copy_view_file
|
6
|
+
template("component.html.#{engine_name}", destination) unless options["inline"] || options["call"]
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def destination
|
12
|
+
File.join(destination_directory, "#{destination_file_name}.html.#{engine_name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def destination_directory
|
16
|
+
if sidecar?
|
17
|
+
File.join(component_path, class_path, destination_file_name)
|
18
|
+
else
|
19
|
+
File.join(component_path, class_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def destination_file_name
|
24
|
+
"#{file_name}_component"
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_name
|
28
|
+
@_file_name ||= super.sub(/_component\z/i, "")
|
29
|
+
end
|
30
|
+
|
31
|
+
def component_path
|
32
|
+
ViewComponent::Base.config.generate.path
|
33
|
+
end
|
34
|
+
|
35
|
+
def stimulus_controller
|
36
|
+
if stimulus?
|
37
|
+
File.join(destination_directory, destination_file_name)
|
38
|
+
.sub("#{component_path}/", "")
|
39
|
+
.tr("_", "-")
|
40
|
+
.gsub("/", "--")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def sidecar?
|
45
|
+
options["sidecar"] || ViewComponent::Base.config.generate.sidecar
|
46
|
+
end
|
47
|
+
|
48
|
+
def stimulus?
|
49
|
+
options["stimulus"] || ViewComponent::Base.config.generate.stimulus_controller
|
50
|
+
end
|
51
|
+
|
52
|
+
def typescript?
|
53
|
+
options["typescript"] || ViewComponent::Base.config.generate.typescript
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/abstract_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class ComponentGenerator < Rails::Generators::NamedBase
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
argument :attributes, type: :array, default: [], banner: "attribute"
|
13
|
+
check_class_collision suffix: "Component"
|
14
|
+
|
15
|
+
class_option :call, type: :boolean, default: false
|
16
|
+
class_option :inline, type: :boolean, default: false
|
17
|
+
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
|
18
|
+
class_option :parent, type: :string, desc: "The parent class for the generated component"
|
19
|
+
class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview
|
20
|
+
class_option :sidecar, type: :boolean, default: false
|
21
|
+
class_option :stimulus, type: :boolean,
|
22
|
+
default: ViewComponent::Base.config.generate.stimulus_controller
|
23
|
+
class_option :skip_suffix, type: :boolean, default: false
|
24
|
+
|
25
|
+
def create_component_file
|
26
|
+
template "component.rb", File.join(component_path, class_path, "#{file_name}#{options[:skip_suffix] ? "" : "_component"}.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
hook_for :test_framework
|
30
|
+
|
31
|
+
hook_for :preview, type: :boolean
|
32
|
+
|
33
|
+
hook_for :stimulus, type: :boolean
|
34
|
+
|
35
|
+
hook_for :locale, type: :boolean
|
36
|
+
|
37
|
+
hook_for :template_engine do |instance, template_engine|
|
38
|
+
instance.invoke template_engine, [instance.name]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def parent_class
|
44
|
+
return options[:parent] if options[:parent]
|
45
|
+
|
46
|
+
ViewComponent::Base.config.generate.parent_class || default_parent_class
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize_signature?
|
50
|
+
initialize_signature.present?
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize_signature
|
54
|
+
return if attributes.blank?
|
55
|
+
|
56
|
+
attributes.map { |attr| "#{attr.name}:" }.join(", ")
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize_body
|
60
|
+
attributes.map { |attr| "@#{attr.name} = #{attr.name}" }.join("\n ")
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize_call_method_for_inline?
|
64
|
+
options["call"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def inline_template?
|
68
|
+
options["inline"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def template_engine
|
72
|
+
options["template_engine"]
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_parent_class
|
76
|
+
defined?(ApplicationComponent) ? ApplicationComponent : ViewComponent::Base
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= class_name %><%= options[:skip_suffix] ? "" : "Component" %> < <%= parent_class %>
|
5
|
+
<%- if inline_template? -%>
|
6
|
+
<%= template_engine %>_template <<~<%= template_engine.upcase %>
|
7
|
+
<h1>Hello, World!</h1>
|
8
|
+
<%= template_engine.upcase %>
|
9
|
+
<%- end -%>
|
10
|
+
<%- if initialize_signature? -%>
|
11
|
+
def initialize(<%= initialize_signature %>)
|
12
|
+
<%= initialize_body %>
|
13
|
+
end
|
14
|
+
<%- end -%>
|
15
|
+
<%- if initialize_call_method_for_inline? -%>
|
16
|
+
def call
|
17
|
+
content_tag :h1, "Hello world!"<%= ", data: { controller: \"#{stimulus_controller}\" }" if options["stimulus"] %>
|
18
|
+
end
|
19
|
+
<%- end -%>
|
20
|
+
end
|
21
|
+
<% end -%>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/erb"
|
4
|
+
require "generators/view_component/abstract_generator"
|
5
|
+
|
6
|
+
module ViewComponent
|
7
|
+
module Generators
|
8
|
+
class ErbGenerator < Rails::Generators::NamedBase
|
9
|
+
include ViewComponent::AbstractGenerator
|
10
|
+
|
11
|
+
source_root File.expand_path("templates", __dir__)
|
12
|
+
class_option :sidecar, type: :boolean, default: false
|
13
|
+
class_option :inline, type: :boolean, default: false
|
14
|
+
class_option :call, type: :boolean, default: false
|
15
|
+
class_option :stimulus, type: :boolean, default: false
|
16
|
+
|
17
|
+
def engine_name
|
18
|
+
"erb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_view_file
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def data_attributes
|
28
|
+
if stimulus?
|
29
|
+
" data-controller=\"#{stimulus_controller}\""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div<%= data_attributes %>>Add <%= class_name %> template here</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/erb/erb_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class HamlGenerator < ViewComponent::Generators::ErbGenerator
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
class_option :sidecar, type: :boolean, default: false
|
12
|
+
|
13
|
+
def engine_name
|
14
|
+
"haml"
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_view_file
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
%div Add <%= class_name %> template here
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/abstract_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class LocaleGenerator < ::Rails::Generators::NamedBase
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
argument :attributes, type: :array, default: [], banner: "attribute"
|
12
|
+
class_option :sidecar, type: :boolean, default: false
|
13
|
+
|
14
|
+
def create_locale_file
|
15
|
+
if ViewComponent::Base.config.generate.distinct_locale_files
|
16
|
+
I18n.available_locales.each do |locale|
|
17
|
+
create_file destination(locale), translations_hash([locale]).to_yaml
|
18
|
+
end
|
19
|
+
else
|
20
|
+
create_file destination, translations_hash(I18n.available_locales).to_yaml
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def translations_hash(locales = [:en])
|
27
|
+
locales.map { |locale| [locale.to_s, translation_keys] }.to_h
|
28
|
+
end
|
29
|
+
|
30
|
+
def translation_keys
|
31
|
+
keys = attributes.map(&:name)
|
32
|
+
keys = %w[hello] if keys.empty?
|
33
|
+
keys.map { |name| [name, name.capitalize] }.to_h
|
34
|
+
end
|
35
|
+
|
36
|
+
def destination(locale = nil)
|
37
|
+
extension = ".#{locale}" if locale
|
38
|
+
if sidecar?
|
39
|
+
File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component#{extension}.yml")
|
40
|
+
else
|
41
|
+
File.join(component_path, class_path, "#{file_name}_component#{extension}.yml")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module Generators
|
5
|
+
class PreviewGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
class_option :preview_path, type: :string, desc: "Path for previews, required when multiple preview paths are configured", default: ViewComponent::Base.config.generate.preview_path
|
8
|
+
|
9
|
+
argument :attributes, type: :array, default: [], banner: "attribute"
|
10
|
+
check_class_collision suffix: "ComponentPreview"
|
11
|
+
|
12
|
+
def create_preview_file
|
13
|
+
preview_paths = ViewComponent::Base.config.previews.paths
|
14
|
+
optional_path = options[:preview_path]
|
15
|
+
return if preview_paths.count > 1 && optional_path.blank?
|
16
|
+
|
17
|
+
path_prefix = if optional_path.present?
|
18
|
+
optional_path
|
19
|
+
else
|
20
|
+
preview_paths.one? ? preview_paths.first : "test/components/previews"
|
21
|
+
end
|
22
|
+
|
23
|
+
template "component_preview.rb", File.join(path_prefix, class_path, "#{file_name}_component_preview.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def file_name
|
29
|
+
@_file_name ||= super.sub(/_component\z/i, "")
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_signature
|
33
|
+
return if attributes.blank?
|
34
|
+
|
35
|
+
attributes.map { |attr| %(#{attr.name}: "#{attr.name}") }.join(", ")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/abstract_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class RspecGenerator < ::Rails::Generators::NamedBase
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
def create_test_file
|
13
|
+
template "component_spec.rb", File.join(spec_component_path, class_path, "#{file_name}_component_spec.rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def spec_component_path
|
19
|
+
return "spec/components" unless ViewComponent::Base.config.generate.use_component_path_for_rspec_tests
|
20
|
+
|
21
|
+
configured_component_path = component_path
|
22
|
+
if configured_component_path.start_with?("app#{File::SEPARATOR}")
|
23
|
+
_app, *rest_of_path = Pathname.new(configured_component_path).each_filename.to_a
|
24
|
+
File.join("spec", *rest_of_path)
|
25
|
+
else
|
26
|
+
"spec/components"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
RSpec.describe <%= namespaced? ? "#{namespace.name}::" : '' %><%= class_name %>Component, type: :component do
|
6
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
7
|
+
|
8
|
+
# it "renders something useful" do
|
9
|
+
# expect(
|
10
|
+
# render_inline(described_class.new(attr: "value")) { "Hello, components!" }.css("p").to_html
|
11
|
+
# ).to include(
|
12
|
+
# "Hello, components!"
|
13
|
+
# )
|
14
|
+
# end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/erb/erb_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class SlimGenerator < ViewComponent::Generators::ErbGenerator
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
class_option :sidecar, type: :boolean, default: false
|
12
|
+
|
13
|
+
def engine_name
|
14
|
+
"slim"
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_view_file
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
div Add <%= class_name %> template here
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/abstract_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class StimulusGenerator < ::Rails::Generators::NamedBase
|
8
|
+
include ViewComponent::AbstractGenerator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
class_option :sidecar, type: :boolean, default: false
|
12
|
+
class_option :typescript, type: :boolean, default: false
|
13
|
+
|
14
|
+
def create_stimulus_controller
|
15
|
+
template "component_controller.#{filetype}", destination
|
16
|
+
end
|
17
|
+
|
18
|
+
def stimulus_module
|
19
|
+
return "stimulus" if legacy_stimulus?
|
20
|
+
|
21
|
+
"@hotwired/stimulus"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def filetype
|
27
|
+
typescript? ? "ts" : "js"
|
28
|
+
end
|
29
|
+
|
30
|
+
def destination
|
31
|
+
if sidecar?
|
32
|
+
File.join(component_path, class_path, "#{file_name}_component", "#{file_name}_component_controller.#{filetype}")
|
33
|
+
else
|
34
|
+
File.join(component_path, class_path, "#{file_name}_component_controller.#{filetype}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def legacy_stimulus?
|
39
|
+
package_json_pathname = Rails.root.join("package.json")
|
40
|
+
package_json_pathname.exist? && JSON.parse(package_json_pathname.read).dig("dependencies", "stimulus").present?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/view_component/erb/erb_generator"
|
4
|
+
|
5
|
+
module ViewComponent
|
6
|
+
module Generators
|
7
|
+
class TailwindcssGenerator < ViewComponent::Generators::ErbGenerator
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div<%= data_attributes %>>Add <%= class_name %> template here</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class <%= namespaced? ? "#{namespace.name}::" : '' %><%= class_name %>ComponentTest < ViewComponent::TestCase
|
6
|
+
def test_component_renders_something_useful
|
7
|
+
# assert_equal(
|
8
|
+
# %(<span>Hello, components!</span>),
|
9
|
+
# render_inline(<%= class_name %>Component.new(message: "Hello, components!")).css("span").to_html
|
10
|
+
# )
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module Generators
|
5
|
+
class TestUnitGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
check_class_collision suffix: "ComponentTest"
|
8
|
+
|
9
|
+
def create_test_file
|
10
|
+
template "component_test.rb", File.join("test/components", class_path, "#{file_name}_component_test.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def file_name
|
16
|
+
@_file_name ||= super.sub(/_component\z/i, "")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/view_component/base.rb
CHANGED
@@ -71,8 +71,6 @@ module ViewComponent
|
|
71
71
|
# Config option that strips trailing whitespace in templates before compiling them.
|
72
72
|
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false, default: false
|
73
73
|
|
74
|
-
class_attribute :__vc_response_format, instance_accessor: false, instance_predicate: false, default: nil
|
75
|
-
|
76
74
|
attr_accessor :__vc_original_view_context
|
77
75
|
attr_reader :current_template
|
78
76
|
|
@@ -356,10 +354,6 @@ module ViewComponent
|
|
356
354
|
__vc_render_in_block_provided? || __vc_content_set_by_with_content_defined?
|
357
355
|
end
|
358
356
|
|
359
|
-
def format
|
360
|
-
self.class.__vc_response_format
|
361
|
-
end
|
362
|
-
|
363
357
|
# @private
|
364
358
|
def with_original_virtual_path
|
365
359
|
@view_context.instance_variable_set(:@virtual_path, @old_virtual_path)
|
@@ -48,15 +48,6 @@ module ViewComponent
|
|
48
48
|
|
49
49
|
define_render_template_for
|
50
50
|
|
51
|
-
# Set the format if the component only responds to a single format.
|
52
|
-
# Unfortunately we cannot determine which format a multi-format
|
53
|
-
# component will respond to until render time, so those components
|
54
|
-
# will not set the response format.
|
55
|
-
#
|
56
|
-
# TODO: Investigate upstream changes necessary to support multi-format renderables
|
57
|
-
unique_formats = templates.map(&:format).uniq
|
58
|
-
@component.__vc_response_format = unique_formats.last if unique_formats.one?
|
59
|
-
|
60
51
|
@component.__vc_register_default_slots
|
61
52
|
@component.__vc_build_i18n_backend
|
62
53
|
|
@@ -118,7 +109,6 @@ module ViewComponent
|
|
118
109
|
errors << "Couldn't find a template file or inline render method for #{@component}." if @templates.empty?
|
119
110
|
|
120
111
|
@templates
|
121
|
-
.reject { |template| template.inline_call? && !template.defined_on_self? }
|
122
112
|
.map { |template| [template.variant, template.format] }
|
123
113
|
.tally
|
124
114
|
.select { |_, count| count > 1 }
|
@@ -43,7 +43,7 @@ module ViewComponent
|
|
43
43
|
attr_reader :source
|
44
44
|
|
45
45
|
def initialize(component:, inline_template:)
|
46
|
-
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym,
|
46
|
+
details = ActionView::TemplateDetails.new(nil, inline_template.language.to_sym, nil, nil)
|
47
47
|
|
48
48
|
super(
|
49
49
|
component: component,
|
@@ -63,7 +63,7 @@ module ViewComponent
|
|
63
63
|
class InlineCall < Template
|
64
64
|
def initialize(component:, method_name:, defined_on_self:)
|
65
65
|
variant = method_name.to_s.include?("call_") ? method_name.to_s.sub("call_", "").to_sym : nil
|
66
|
-
details = ActionView::TemplateDetails.new(nil, nil,
|
66
|
+
details = ActionView::TemplateDetails.new(nil, nil, nil, variant)
|
67
67
|
|
68
68
|
super(component: component, details: details)
|
69
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.rc5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
@@ -59,6 +59,27 @@ files:
|
|
59
59
|
- app/views/view_components/preview.html.erb
|
60
60
|
- app/views/view_components/previews.html.erb
|
61
61
|
- docs/CHANGELOG.md
|
62
|
+
- lib/generators/view_component/abstract_generator.rb
|
63
|
+
- lib/generators/view_component/component/component_generator.rb
|
64
|
+
- lib/generators/view_component/component/templates/component.rb.tt
|
65
|
+
- lib/generators/view_component/erb/erb_generator.rb
|
66
|
+
- lib/generators/view_component/erb/templates/component.html.erb.tt
|
67
|
+
- lib/generators/view_component/haml/haml_generator.rb
|
68
|
+
- lib/generators/view_component/haml/templates/component.html.haml.tt
|
69
|
+
- lib/generators/view_component/locale/locale_generator.rb
|
70
|
+
- lib/generators/view_component/preview/preview_generator.rb
|
71
|
+
- lib/generators/view_component/preview/templates/component_preview.rb.tt
|
72
|
+
- lib/generators/view_component/rspec/rspec_generator.rb
|
73
|
+
- lib/generators/view_component/rspec/templates/component_spec.rb.tt
|
74
|
+
- lib/generators/view_component/slim/slim_generator.rb
|
75
|
+
- lib/generators/view_component/slim/templates/component.html.slim.tt
|
76
|
+
- lib/generators/view_component/stimulus/stimulus_generator.rb
|
77
|
+
- lib/generators/view_component/stimulus/templates/component_controller.js.tt
|
78
|
+
- lib/generators/view_component/stimulus/templates/component_controller.ts.tt
|
79
|
+
- lib/generators/view_component/tailwindcss/tailwindcss_generator.rb
|
80
|
+
- lib/generators/view_component/tailwindcss/templates/component.html.erb.tt
|
81
|
+
- lib/generators/view_component/test_unit/templates/component_test.rb.tt
|
82
|
+
- lib/generators/view_component/test_unit/test_unit_generator.rb
|
62
83
|
- lib/view_component.rb
|
63
84
|
- lib/view_component/base.rb
|
64
85
|
- lib/view_component/collection.rb
|