view_component 3.23.2 → 4.12.0
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/app/controllers/concerns/view_component/preview_actions.rb +11 -14
- data/app/controllers/view_components_system_test_controller.rb +25 -19
- data/app/views/test_mailer/test_asset_email.html.erb +1 -0
- data/app/views/test_mailer/test_url_email.html.erb +1 -0
- data/app/views/view_components/preview.html.erb +1 -9
- data/docs/CHANGELOG.md +612 -108
- data/lib/{rails/generators → generators/view_component}/abstract_generator.rb +2 -2
- data/lib/{rails/generators → generators/view_component}/component/component_generator.rb +17 -4
- data/lib/{rails/generators → generators/view_component}/component/templates/component.rb.tt +6 -1
- data/lib/{rails/generators/erb/component_generator.rb → generators/view_component/erb/erb_generator.rb} +4 -3
- data/lib/{rails/generators/haml/component_generator.rb → generators/view_component/haml/haml_generator.rb} +3 -3
- data/lib/{rails/generators/locale/component_generator.rb → generators/view_component/locale/locale_generator.rb} +3 -3
- data/lib/{rails/generators/preview/component_generator.rb → generators/view_component/preview/preview_generator.rb} +3 -3
- data/lib/{rails/generators/rspec/component_generator.rb → generators/view_component/rspec/rspec_generator.rb} +3 -3
- data/lib/{rails/generators/slim/component_generator.rb → generators/view_component/slim/slim_generator.rb} +3 -3
- data/lib/{rails/generators/stimulus/component_generator.rb → generators/view_component/stimulus/stimulus_generator.rb} +3 -3
- data/lib/generators/view_component/tailwindcss/tailwindcss_generator.rb +11 -0
- data/lib/{rails/generators/test_unit/component_generator.rb → generators/view_component/test_unit/test_unit_generator.rb} +2 -2
- data/lib/view_component/base.rb +252 -163
- data/lib/view_component/collection.rb +33 -35
- data/lib/view_component/compiler.rb +55 -80
- data/lib/view_component/config.rb +55 -85
- data/lib/view_component/configurable.rb +19 -3
- data/lib/view_component/deprecation.rb +1 -1
- data/lib/view_component/engine.rb +46 -106
- data/lib/view_component/errors.rb +16 -34
- data/lib/view_component/inline_template.rb +4 -4
- data/lib/view_component/instrumentation.rb +21 -14
- data/lib/view_component/preview.rb +7 -12
- data/lib/view_component/request_details.rb +30 -0
- data/lib/view_component/slot.rb +7 -15
- data/lib/view_component/slotable.rb +94 -80
- data/lib/view_component/system_spec_helpers.rb +11 -0
- data/lib/view_component/system_test_helpers.rb +2 -2
- data/lib/view_component/template.rb +159 -83
- data/lib/view_component/test_helpers.rb +67 -50
- data/lib/view_component/translatable.rb +33 -32
- data/lib/view_component/version.rb +3 -3
- data/lib/view_component.rb +9 -6
- metadata +36 -556
- data/app/assets/vendor/prism.css +0 -4
- data/app/assets/vendor/prism.min.js +0 -12
- data/app/helpers/preview_helper.rb +0 -85
- data/app/views/view_components/_preview_source.html.erb +0 -17
- data/lib/rails/generators/tailwindcss/component_generator.rb +0 -11
- data/lib/view_component/capture_compatibility.rb +0 -44
- data/lib/view_component/component_error.rb +0 -6
- data/lib/view_component/rails/tasks/view_component.rake +0 -20
- data/lib/view_component/render_component_helper.rb +0 -10
- data/lib/view_component/render_component_to_string_helper.rb +0 -9
- data/lib/view_component/render_monkey_patch.rb +0 -13
- data/lib/view_component/render_to_string_monkey_patch.rb +0 -13
- data/lib/view_component/rendering_component_helper.rb +0 -9
- data/lib/view_component/rendering_monkey_patch.rb +0 -13
- data/lib/view_component/slotable_default.rb +0 -20
- data/lib/view_component/use_helpers.rb +0 -42
- /data/lib/{rails/generators → generators/view_component}/erb/templates/component.html.erb.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/haml/templates/component.html.haml.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/preview/templates/component_preview.rb.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/rspec/templates/component_spec.rb.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/slim/templates/component.html.slim.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/stimulus/templates/component_controller.js.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/stimulus/templates/component_controller.ts.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/tailwindcss/templates/component.html.erb.tt +0 -0
- /data/lib/{rails/generators → generators/view_component}/test_unit/templates/component_test.rb.tt +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ViewComponent
|
|
4
4
|
module AbstractGenerator
|
|
5
5
|
def copy_view_file
|
|
6
|
-
template
|
|
6
|
+
template("component.html.#{engine_name}", destination) unless options["inline"] || options["call"]
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
private
|
|
@@ -29,7 +29,7 @@ module ViewComponent
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def component_path
|
|
32
|
-
ViewComponent::Base.config.
|
|
32
|
+
ViewComponent::Base.config.generate.path
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def stimulus_controller
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
7
|
class ComponentGenerator < Rails::Generators::NamedBase
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
@@ -12,6 +12,7 @@ module Rails
|
|
|
12
12
|
argument :attributes, type: :array, default: [], banner: "attribute"
|
|
13
13
|
check_class_collision suffix: "Component"
|
|
14
14
|
|
|
15
|
+
class_option :call, type: :boolean, default: false
|
|
15
16
|
class_option :inline, type: :boolean, default: false
|
|
16
17
|
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
|
|
17
18
|
class_option :parent, type: :string, desc: "The parent class for the generated component"
|
|
@@ -22,7 +23,7 @@ module Rails
|
|
|
22
23
|
class_option :skip_suffix, type: :boolean, default: false
|
|
23
24
|
|
|
24
25
|
def create_component_file
|
|
25
|
-
template "component.rb", File.join(component_path, class_path, "#{file_name}#{options[:skip_suffix]
|
|
26
|
+
template "component.rb", File.join(component_path, class_path, "#{file_name}#{"_component" unless options[:skip_suffix]}.rb")
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
hook_for :test_framework
|
|
@@ -42,7 +43,11 @@ module Rails
|
|
|
42
43
|
def parent_class
|
|
43
44
|
return options[:parent] if options[:parent]
|
|
44
45
|
|
|
45
|
-
ViewComponent::Base.config.
|
|
46
|
+
ViewComponent::Base.config.generate.parent_class || default_parent_class
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def initialize_signature?
|
|
50
|
+
initialize_signature.present?
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
def initialize_signature
|
|
@@ -56,9 +61,17 @@ module Rails
|
|
|
56
61
|
end
|
|
57
62
|
|
|
58
63
|
def initialize_call_method_for_inline?
|
|
64
|
+
options["call"]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def inline_template?
|
|
59
68
|
options["inline"]
|
|
60
69
|
end
|
|
61
70
|
|
|
71
|
+
def template_engine
|
|
72
|
+
options["template_engine"]
|
|
73
|
+
end
|
|
74
|
+
|
|
62
75
|
def default_parent_class
|
|
63
76
|
defined?(ApplicationComponent) ? ApplicationComponent : ViewComponent::Base
|
|
64
77
|
end
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<% module_namespacing do -%>
|
|
4
4
|
class <%= class_name %><%= options[:skip_suffix] ? "" : "Component" %> < <%= parent_class %>
|
|
5
|
-
<%- if
|
|
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? -%>
|
|
6
11
|
def initialize(<%= initialize_signature %>)
|
|
7
12
|
<%= initialize_body %>
|
|
8
13
|
end
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rails/generators/erb"
|
|
4
|
-
require "
|
|
4
|
+
require "generators/view_component/abstract_generator"
|
|
5
5
|
|
|
6
|
-
module
|
|
6
|
+
module ViewComponent
|
|
7
7
|
module Generators
|
|
8
|
-
class
|
|
8
|
+
class ErbGenerator < Rails::Generators::NamedBase
|
|
9
9
|
include ViewComponent::AbstractGenerator
|
|
10
10
|
|
|
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 :call, type: :boolean, default: false
|
|
14
15
|
class_option :stimulus, type: :boolean, default: false
|
|
15
16
|
|
|
16
17
|
def engine_name
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/erb/erb_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
|
-
class
|
|
7
|
+
class HamlGenerator < ViewComponent::Generators::ErbGenerator
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
|
-
class
|
|
7
|
+
class LocaleGenerator < ::Rails::Generators::NamedBase
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
3
|
+
module ViewComponent
|
|
4
4
|
module Generators
|
|
5
|
-
class
|
|
5
|
+
class PreviewGenerator < ::Rails::Generators::NamedBase
|
|
6
6
|
source_root File.expand_path("templates", __dir__)
|
|
7
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
8
|
|
|
@@ -10,7 +10,7 @@ module Preview
|
|
|
10
10
|
check_class_collision suffix: "ComponentPreview"
|
|
11
11
|
|
|
12
12
|
def create_preview_file
|
|
13
|
-
preview_paths = ViewComponent::Base.config.
|
|
13
|
+
preview_paths = ViewComponent::Base.config.previews.paths
|
|
14
14
|
optional_path = options[:preview_path]
|
|
15
15
|
return if preview_paths.count > 1 && optional_path.blank?
|
|
16
16
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
|
-
class
|
|
7
|
+
class RspecGenerator < ::Rails::Generators::NamedBase
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/erb/erb_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
|
-
class
|
|
7
|
+
class SlimGenerator < ViewComponent::Generators::ErbGenerator
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "generators/view_component/abstract_generator"
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module ViewComponent
|
|
6
6
|
module Generators
|
|
7
|
-
class
|
|
7
|
+
class StimulusGenerator < ::Rails::Generators::NamedBase
|
|
8
8
|
include ViewComponent::AbstractGenerator
|
|
9
9
|
|
|
10
10
|
source_root File.expand_path("templates", __dir__)
|
|
@@ -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
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module
|
|
3
|
+
module ViewComponent
|
|
4
4
|
module Generators
|
|
5
|
-
class
|
|
5
|
+
class TestUnitGenerator < ::Rails::Generators::NamedBase
|
|
6
6
|
source_root File.expand_path("templates", __dir__)
|
|
7
7
|
check_class_collision suffix: "ComponentTest"
|
|
8
8
|
|