view_component 2.18.2 → 2.22.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.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +127 -79
- data/README.md +5 -1023
- data/lib/rails/generators/test_unit/templates/component_test.rb.tt +1 -1
- data/lib/view_component.rb +1 -0
- data/lib/view_component/base.rb +22 -192
- data/lib/view_component/collection.rb +2 -0
- data/lib/view_component/compiler.rb +214 -0
- data/lib/view_component/engine.rb +10 -5
- data/lib/view_component/preview.rb +4 -1
- data/lib/view_component/previewable.rb +10 -0
- data/lib/view_component/version.rb +2 -2
- metadata +7 -6
@@ -14,9 +14,12 @@ module ViewComponent
|
|
14
14
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
15
15
|
options.show_previews = Rails.env.development? if options.show_previews.nil?
|
16
16
|
options.preview_route ||= ViewComponent::Base.preview_route
|
17
|
+
options.preview_controller ||= ViewComponent::Base.preview_controller
|
17
18
|
|
18
19
|
if options.show_previews
|
19
|
-
options.preview_paths << "#{Rails.root}/test/components/previews" if defined?(Rails.root)
|
20
|
+
options.preview_paths << "#{Rails.root}/test/components/previews" if defined?(Rails.root) && Dir.exist?(
|
21
|
+
"#{Rails.root}/test/components/previews"
|
22
|
+
)
|
20
23
|
|
21
24
|
if options.preview_path.present?
|
22
25
|
ActiveSupport::Deprecation.warn(
|
@@ -41,7 +44,7 @@ module ViewComponent
|
|
41
44
|
|
42
45
|
initializer "view_component.eager_load_actions" do
|
43
46
|
ActiveSupport.on_load(:after_initialize) do
|
44
|
-
ViewComponent::Base.descendants.each(&:compile)
|
47
|
+
ViewComponent::Base.descendants.each(&:compile) if Rails.application.config.eager_load
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -87,9 +90,11 @@ module ViewComponent
|
|
87
90
|
options = app.config.view_component
|
88
91
|
|
89
92
|
if options.show_previews
|
90
|
-
app.routes.
|
91
|
-
|
92
|
-
|
93
|
+
app.routes.append do
|
94
|
+
preview_controller = options.preview_controller.sub(/Controller$/, "").underscore
|
95
|
+
|
96
|
+
get options.preview_route, to: "#{preview_controller}#index", as: :preview_view_components, internal: true
|
97
|
+
get "#{options.preview_route}/*path", to: "#{preview_controller}#previews", as: :preview_view_component, internal: true
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
@@ -80,7 +80,10 @@ module ViewComponent # :nodoc:
|
|
80
80
|
end
|
81
81
|
|
82
82
|
path = Dir["#{preview_path}/#{preview_name}_preview/#{example}.html.*"].first
|
83
|
-
Pathname.new(path)
|
83
|
+
Pathname.new(path)
|
84
|
+
.relative_path_from(Pathname.new(preview_path))
|
85
|
+
.to_s
|
86
|
+
.sub(/\..*$/, "")
|
84
87
|
end
|
85
88
|
|
86
89
|
private
|
@@ -41,6 +41,16 @@ module ViewComponent # :nodoc:
|
|
41
41
|
mattr_accessor :preview_route, instance_writer: false do
|
42
42
|
"/rails/view_components"
|
43
43
|
end
|
44
|
+
|
45
|
+
# Set the controller to be used for previewing components through app configuration:
|
46
|
+
#
|
47
|
+
# config.view_component.preview_controller = "MyPreviewController"
|
48
|
+
#
|
49
|
+
# Defaults to the provided +ViewComponentsController+
|
50
|
+
#
|
51
|
+
mattr_accessor :preview_controller, instance_writer: false do
|
52
|
+
"ViewComponentsController"
|
53
|
+
end
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
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.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -184,7 +184,7 @@ dependencies:
|
|
184
184
|
- - "~>"
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: 0.7.2
|
187
|
-
description:
|
187
|
+
description:
|
188
188
|
email:
|
189
189
|
- opensource+view_component@github.com
|
190
190
|
executables: []
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/view_component/base.rb
|
216
216
|
- lib/view_component/collection.rb
|
217
217
|
- lib/view_component/compile_cache.rb
|
218
|
+
- lib/view_component/compiler.rb
|
218
219
|
- lib/view_component/engine.rb
|
219
220
|
- lib/view_component/preview.rb
|
220
221
|
- lib/view_component/preview_template_error.rb
|
@@ -236,7 +237,7 @@ licenses:
|
|
236
237
|
- MIT
|
237
238
|
metadata:
|
238
239
|
allowed_push_host: https://rubygems.org
|
239
|
-
post_install_message:
|
240
|
+
post_install_message:
|
240
241
|
rdoc_options: []
|
241
242
|
require_paths:
|
242
243
|
- lib
|
@@ -252,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
253
|
version: '0'
|
253
254
|
requirements: []
|
254
255
|
rubygems_version: 3.1.2
|
255
|
-
signing_key:
|
256
|
+
signing_key:
|
256
257
|
specification_version: 4
|
257
258
|
summary: View components for Rails
|
258
259
|
test_files: []
|