view_component 2.66.0 → 2.68.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/LICENSE.txt +1 -1
- data/app/controllers/concerns/view_component/preview_actions.rb +2 -2
- data/app/helpers/preview_helper.rb +1 -1
- data/app/views/view_components/preview.html.erb +2 -2
- data/docs/CHANGELOG.md +28 -0
- data/lib/rails/generators/abstract_generator.rb +2 -2
- data/lib/rails/generators/component/component_generator.rb +4 -4
- data/lib/rails/generators/locale/component_generator.rb +1 -1
- data/lib/rails/generators/preview/component_generator.rb +1 -1
- data/lib/view_component/base.rb +3 -2
- data/lib/view_component/engine.rb +1 -1
- data/lib/view_component/test_helpers.rb +44 -4
- data/lib/view_component/version.rb +1 -1
- metadata +14 -15
- data/lib/view_component/render_preview_helper.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc70b125c7bf45480588c0161df7993d19ce3f3c67f9303c2e7c09d836bc3b5e
|
4
|
+
data.tar.gz: 7cbaec3b7b25d762cfc8068f932520135c4e989a549754cdb9733d6c356853f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5afca6dd4a94bf0ee395fa72d577a7ce0031f590b6d6cd4c1fd7625422d71c5ebe6cce52111f9350b66803d3421cf504c694f8b35229fc726e2bd1d32dd414db
|
7
|
+
data.tar.gz: 185329894deb2a89735087da12093040e08a2009ba8b9fe934b83731539f93c479d130e2cd3a7d112895ad489b268167f0c8c71712ef42582921975e729eb59d
|
data/LICENSE.txt
CHANGED
@@ -43,12 +43,12 @@ module ViewComponent
|
|
43
43
|
|
44
44
|
# :doc:
|
45
45
|
def default_preview_layout
|
46
|
-
|
46
|
+
ViewComponent::Base.config.default_preview_layout
|
47
47
|
end
|
48
48
|
|
49
49
|
# :doc:
|
50
50
|
def show_previews?
|
51
|
-
|
51
|
+
ViewComponent::Base.config.show_previews
|
52
52
|
end
|
53
53
|
|
54
54
|
# :doc:
|
@@ -22,7 +22,7 @@ module PreviewHelper
|
|
22
22
|
# Fetch template source via finding it through preview paths
|
23
23
|
# to accomodate source view when exclusively using templates
|
24
24
|
# for previews for Rails < 6.1.
|
25
|
-
all_template_paths =
|
25
|
+
all_template_paths = ViewComponent::Base.config.preview_paths.map do |preview_path|
|
26
26
|
Dir.glob("#{preview_path}/**/*")
|
27
27
|
end.flatten
|
28
28
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if @render_args[:component] %>
|
2
|
-
<% if
|
2
|
+
<% if ViewComponent::Base.config.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
|
3
3
|
<%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
|
4
4
|
<% else %>
|
5
5
|
<%= render_component(@render_args[:component], &@render_args[:block]) %>
|
@@ -8,6 +8,6 @@
|
|
8
8
|
<%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>
|
9
9
|
<% end %>
|
10
10
|
|
11
|
-
<% if
|
11
|
+
<% if ViewComponent::Base.config.show_previews_source %>
|
12
12
|
<%= preview_source %>
|
13
13
|
<% end %>
|
data/docs/CHANGELOG.md
CHANGED
@@ -9,6 +9,34 @@ title: Changelog
|
|
9
9
|
|
10
10
|
## main
|
11
11
|
|
12
|
+
## 2.68.0
|
13
|
+
|
14
|
+
* Update `gemspec` author to be ViewComponent team.
|
15
|
+
|
16
|
+
*Joel Hawksley*
|
17
|
+
|
18
|
+
* Fix bug where `ViewComponent::Compiler` wasn't required.
|
19
|
+
|
20
|
+
*Joel Hawksley*
|
21
|
+
|
22
|
+
## 2.67.0
|
23
|
+
|
24
|
+
* Use ViewComponent::Base.config as the internal endpoint for config.
|
25
|
+
|
26
|
+
*Simon Fish*
|
27
|
+
|
28
|
+
* Fix bug where `#with_request_url`, when used with query string, set the incorrect `request.path` and `request.fullpath`.
|
29
|
+
|
30
|
+
*Franz Liedke*
|
31
|
+
|
32
|
+
* Add link to [ViewComponentAttributes](https://github.com/amba-Health/view_component_attributes) in Resources section of docs.
|
33
|
+
|
34
|
+
*Romaric Pascal*
|
35
|
+
|
36
|
+
* `render_preview` test helper is available by default. It is no longer necessary to include `ViewComponent::RenderPreviewHelper`.
|
37
|
+
|
38
|
+
*Joel Hawksley*
|
39
|
+
|
12
40
|
## 2.66.0
|
13
41
|
|
14
42
|
* Add missing `generate.sidecar`, `generate.stimulus_controller`, `generate.locale`, `generate.distinct_locale_files`, `generate.preview` config options to `config.view_component`.
|
@@ -29,7 +29,7 @@ module ViewComponent
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def component_path
|
32
|
-
|
32
|
+
ViewComponent::Base.config.view_component_path
|
33
33
|
end
|
34
34
|
|
35
35
|
def stimulus_controller
|
@@ -42,7 +42,7 @@ module ViewComponent
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def sidecar?
|
45
|
-
options["sidecar"] ||
|
45
|
+
options["sidecar"] || ViewComponent::Base.config.generate.sidecar
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -13,12 +13,12 @@ module Rails
|
|
13
13
|
check_class_collision suffix: "Component"
|
14
14
|
|
15
15
|
class_option :inline, type: :boolean, default: false
|
16
|
-
class_option :locale, type: :boolean, default:
|
16
|
+
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
|
17
17
|
class_option :parent, type: :string, desc: "The parent class for the generated component"
|
18
|
-
class_option :preview, type: :boolean, default:
|
18
|
+
class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview
|
19
19
|
class_option :sidecar, type: :boolean, default: false
|
20
20
|
class_option :stimulus, type: :boolean,
|
21
|
-
default:
|
21
|
+
default: ViewComponent::Base.config.generate.stimulus_controller
|
22
22
|
|
23
23
|
def create_component_file
|
24
24
|
template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
|
@@ -41,7 +41,7 @@ module Rails
|
|
41
41
|
def parent_class
|
42
42
|
return options[:parent] if options[:parent]
|
43
43
|
|
44
|
-
|
44
|
+
ViewComponent::Base.config.component_parent_class || default_parent_class
|
45
45
|
end
|
46
46
|
|
47
47
|
def initialize_signature
|
@@ -12,7 +12,7 @@ module Locale
|
|
12
12
|
class_option :sidecar, type: :boolean, default: false
|
13
13
|
|
14
14
|
def create_locale_file
|
15
|
-
if
|
15
|
+
if ViewComponent::Base.config.generate.distinct_locale_files
|
16
16
|
I18n.available_locales.each do |locale|
|
17
17
|
create_file destination(locale), translations_hash([locale]).to_yaml
|
18
18
|
end
|
@@ -9,7 +9,7 @@ module Preview
|
|
9
9
|
check_class_collision suffix: "ComponentPreview"
|
10
10
|
|
11
11
|
def create_preview_file
|
12
|
-
preview_paths =
|
12
|
+
preview_paths = ViewComponent::Base.config.preview_paths
|
13
13
|
return if preview_paths.count > 1
|
14
14
|
|
15
15
|
path_prefix = preview_paths.one? ? preview_paths.first : "test/components/previews"
|
data/lib/view_component/base.rb
CHANGED
@@ -4,6 +4,7 @@ require "action_view"
|
|
4
4
|
require "active_support/configurable"
|
5
5
|
require "view_component/collection"
|
6
6
|
require "view_component/compile_cache"
|
7
|
+
require "view_component/compiler"
|
7
8
|
require "view_component/config"
|
8
9
|
require "view_component/content_areas"
|
9
10
|
require "view_component/polymorphic_slots"
|
@@ -18,7 +19,7 @@ module ViewComponent
|
|
18
19
|
delegate(*ViewComponent::Config.defaults.keys, to: :config)
|
19
20
|
|
20
21
|
def config
|
21
|
-
|
22
|
+
@config ||= ViewComponent::Config.defaults
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -496,7 +497,7 @@ module ViewComponent
|
|
496
497
|
|
497
498
|
# Removes the first part of the path and the extension.
|
498
499
|
child.virtual_path = child.source_location.gsub(
|
499
|
-
/(.*#{Regexp.quote(
|
500
|
+
/(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
|
500
501
|
)
|
501
502
|
|
502
503
|
# Set collection parameter to the extended component
|
@@ -5,7 +5,7 @@ require "view_component/base"
|
|
5
5
|
|
6
6
|
module ViewComponent
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
8
|
-
config.view_component = ViewComponent::
|
8
|
+
config.view_component = ViewComponent::Base.config
|
9
9
|
|
10
10
|
rake_tasks do
|
11
11
|
load "view_component/rails/tasks/view_component.rake"
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "view_component/render_preview_helper"
|
4
|
-
|
5
3
|
module ViewComponent
|
6
4
|
module TestHelpers
|
7
5
|
begin
|
@@ -67,6 +65,47 @@ module ViewComponent
|
|
67
65
|
Nokogiri::HTML.fragment(@rendered_content)
|
68
66
|
end
|
69
67
|
|
68
|
+
# Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
69
|
+
# allowing for Capybara assertions to be used:
|
70
|
+
#
|
71
|
+
# ```ruby
|
72
|
+
# render_preview(:default)
|
73
|
+
# assert_text("Hello, World!")
|
74
|
+
# ```
|
75
|
+
#
|
76
|
+
# Note: `#rendered_preview` expects a preview to be defined with the same class
|
77
|
+
# name as the calling test, but with `Test` replaced with `Preview`:
|
78
|
+
#
|
79
|
+
# MyComponentTest -> MyComponentPreview etc.
|
80
|
+
#
|
81
|
+
# In RSpec, `Preview` is appended to `described_class`.
|
82
|
+
#
|
83
|
+
# @param preview [String] The name of the preview to be rendered.
|
84
|
+
# @return [Nokogiri::HTML]
|
85
|
+
def render_preview(name)
|
86
|
+
begin
|
87
|
+
preview_klass = if respond_to?(:described_class)
|
88
|
+
raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
|
89
|
+
|
90
|
+
"#{described_class}Preview"
|
91
|
+
else
|
92
|
+
self.class.name.gsub("Test", "Preview")
|
93
|
+
end
|
94
|
+
preview_klass = preview_klass.constantize
|
95
|
+
rescue NameError
|
96
|
+
raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
|
97
|
+
end
|
98
|
+
|
99
|
+
previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
|
100
|
+
previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
|
101
|
+
previews_controller.response = ActionDispatch::Response.new
|
102
|
+
result = previews_controller.previews
|
103
|
+
|
104
|
+
@rendered_content = result
|
105
|
+
|
106
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
107
|
+
end
|
108
|
+
|
70
109
|
# Execute the given block in the view context. Internally sets `page` to be a
|
71
110
|
# `Capybara::Node::Simple`, allowing for Capybara assertions to be used:
|
72
111
|
#
|
@@ -151,10 +190,11 @@ module ViewComponent
|
|
151
190
|
old_request_query_string = request.query_string
|
152
191
|
old_controller = defined?(@controller) && @controller
|
153
192
|
|
193
|
+
path, query = path.split("?", 2)
|
154
194
|
request.path_info = path
|
155
195
|
request.path_parameters = Rails.application.routes.recognize_path(path)
|
156
|
-
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(
|
157
|
-
request.set_header(Rack::QUERY_STRING,
|
196
|
+
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
|
197
|
+
request.set_header(Rack::QUERY_STRING, query)
|
158
198
|
yield
|
159
199
|
ensure
|
160
200
|
request.path_info = old_request_path_info
|
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.68.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -104,16 +104,16 @@ dependencies:
|
|
104
104
|
name: bundler
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- - "
|
107
|
+
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: '2'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - "
|
114
|
+
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
116
|
+
version: '2'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: erb_lint
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -300,19 +300,18 @@ dependencies:
|
|
300
300
|
name: yard-activesupport-concern
|
301
301
|
requirement: !ruby/object:Gem::Requirement
|
302
302
|
requirements:
|
303
|
-
- - "
|
303
|
+
- - "~>"
|
304
304
|
- !ruby/object:Gem::Version
|
305
|
-
version:
|
305
|
+
version: 0.0.1
|
306
306
|
type: :development
|
307
307
|
prerelease: false
|
308
308
|
version_requirements: !ruby/object:Gem::Requirement
|
309
309
|
requirements:
|
310
|
-
- - "
|
310
|
+
- - "~>"
|
311
311
|
- !ruby/object:Gem::Version
|
312
|
-
version:
|
312
|
+
version: 0.0.1
|
313
313
|
description:
|
314
314
|
email:
|
315
|
-
- opensource+view_component@github.com
|
316
315
|
executables: []
|
317
316
|
extensions: []
|
318
317
|
extra_rdoc_files: []
|
@@ -371,7 +370,6 @@ files:
|
|
371
370
|
- lib/view_component/render_component_helper.rb
|
372
371
|
- lib/view_component/render_component_to_string_helper.rb
|
373
372
|
- lib/view_component/render_monkey_patch.rb
|
374
|
-
- lib/view_component/render_preview_helper.rb
|
375
373
|
- lib/view_component/render_to_string_monkey_patch.rb
|
376
374
|
- lib/view_component/rendering_component_helper.rb
|
377
375
|
- lib/view_component/rendering_monkey_patch.rb
|
@@ -386,7 +384,7 @@ files:
|
|
386
384
|
- lib/view_component/version.rb
|
387
385
|
- lib/view_component/with_content_helper.rb
|
388
386
|
- lib/yard/mattr_accessor_handler.rb
|
389
|
-
homepage: https://
|
387
|
+
homepage: https://viewcomponent.org
|
390
388
|
licenses:
|
391
389
|
- MIT
|
392
390
|
metadata:
|
@@ -409,5 +407,6 @@ requirements: []
|
|
409
407
|
rubygems_version: 3.2.32
|
410
408
|
signing_key:
|
411
409
|
specification_version: 4
|
412
|
-
summary:
|
410
|
+
summary: A framework for building reusable, testable & encapsulated view components
|
411
|
+
in Ruby on Rails.
|
413
412
|
test_files: []
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ViewComponent
|
4
|
-
module RenderPreviewHelper
|
5
|
-
# Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
6
|
-
# allowing for Capybara assertions to be used:
|
7
|
-
#
|
8
|
-
# ```ruby
|
9
|
-
# render_preview(:default)
|
10
|
-
# assert_text("Hello, World!")
|
11
|
-
# ```
|
12
|
-
#
|
13
|
-
# Note: `#rendered_preview` expects a preview to be defined with the same class
|
14
|
-
# name as the calling test, but with `Test` replaced with `Preview`:
|
15
|
-
#
|
16
|
-
# MyComponentTest -> MyComponentPreview etc.
|
17
|
-
#
|
18
|
-
# In RSpec, `Preview` is appended to `described_class`.
|
19
|
-
#
|
20
|
-
# @param preview [String] The name of the preview to be rendered.
|
21
|
-
# @return [Nokogiri::HTML]
|
22
|
-
def render_preview(name)
|
23
|
-
begin
|
24
|
-
preview_klass = if respond_to?(:described_class)
|
25
|
-
raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
|
26
|
-
|
27
|
-
"#{described_class}Preview"
|
28
|
-
else
|
29
|
-
self.class.name.gsub("Test", "Preview")
|
30
|
-
end
|
31
|
-
preview_klass = preview_klass.constantize
|
32
|
-
rescue NameError
|
33
|
-
raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
|
34
|
-
end
|
35
|
-
|
36
|
-
previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
|
37
|
-
previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
|
38
|
-
previews_controller.response = ActionDispatch::Response.new
|
39
|
-
result = previews_controller.previews
|
40
|
-
|
41
|
-
@rendered_content = result
|
42
|
-
|
43
|
-
Nokogiri::HTML.fragment(@rendered_content)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|