view_component 2.19.0 → 2.22.1

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.

@@ -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.prepend do
91
- get options.preview_route, to: "view_components#index", as: :preview_view_components, internal: true
92
- get "#{options.preview_route}/*path", to: "view_components#previews", as: :preview_view_component, internal: true
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).relative_path_from(Pathname.new(preview_path)).to_s
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
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 19
7
- PATCH = 0
6
+ MINOR = 22
7
+ PATCH = 1
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  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.19.0
4
+ version: 2.22.1
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-09-14 00:00:00.000000000 Z
11
+ date: 2020-11-10 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: []