view_component 2.18.0 → 2.20.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 +129 -77
- data/README.md +161 -40
- data/app/views/view_components/preview.html.erb +5 -1
- 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 +17 -185
- data/lib/view_component/collection.rb +2 -0
- data/lib/view_component/compiler.rb +214 -0
- data/lib/view_component/engine.rb +9 -4
- data/lib/view_component/preview.rb +6 -15
- data/lib/view_component/previewable.rb +10 -0
- data/lib/view_component/test_helpers.rb +4 -0
- data/lib/view_component/version.rb +1 -1
- metadata +20 -5
@@ -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(
|
@@ -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
|
|
@@ -24,6 +24,8 @@ module ViewComponent # :nodoc:
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
+
alias_method :render_component, :render
|
28
|
+
|
27
29
|
class << self
|
28
30
|
# Returns all component preview classes.
|
29
31
|
def all
|
@@ -42,21 +44,11 @@ module ViewComponent # :nodoc:
|
|
42
44
|
result.merge(layout: @layout)
|
43
45
|
end
|
44
46
|
|
45
|
-
# Returns the component object class associated to the preview.
|
46
|
-
def component
|
47
|
-
name.chomp("Preview").constantize
|
48
|
-
end
|
49
|
-
|
50
47
|
# Returns all of the available examples for the component preview.
|
51
48
|
def examples
|
52
49
|
public_instance_methods(false).map(&:to_s).sort
|
53
50
|
end
|
54
51
|
|
55
|
-
# Returns +true+ if the example of the component preview exists.
|
56
|
-
def example_exists?(example)
|
57
|
-
examples.include?(example)
|
58
|
-
end
|
59
|
-
|
60
52
|
# Returns +true+ if the preview exists.
|
61
53
|
def exists?(preview)
|
62
54
|
all.any? { |p| p.preview_name == preview }
|
@@ -88,7 +80,10 @@ module ViewComponent # :nodoc:
|
|
88
80
|
end
|
89
81
|
|
90
82
|
path = Dir["#{preview_path}/#{preview_name}_preview/#{example}.html.*"].first
|
91
|
-
Pathname.new(path)
|
83
|
+
Pathname.new(path)
|
84
|
+
.relative_path_from(Pathname.new(preview_path))
|
85
|
+
.to_s
|
86
|
+
.sub(/\..*$/, "")
|
92
87
|
end
|
93
88
|
|
94
89
|
private
|
@@ -102,10 +97,6 @@ module ViewComponent # :nodoc:
|
|
102
97
|
def preview_paths
|
103
98
|
Base.preview_paths
|
104
99
|
end
|
105
|
-
|
106
|
-
def show_previews
|
107
|
-
Base.show_previews
|
108
|
-
end
|
109
100
|
end
|
110
101
|
end
|
111
102
|
end
|
@@ -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
|
@@ -14,7 +14,11 @@ module ViewComponent
|
|
14
14
|
assert_no_selector("body")
|
15
15
|
end
|
16
16
|
rescue LoadError
|
17
|
+
# We don't have a test case for running an application without capybara installed.
|
18
|
+
# It's probably fine to leave this without coverage.
|
19
|
+
# :nocov:
|
17
20
|
warn "WARNING in `ViewComponent::TestHelpers`: You must add `capybara` to your Gemfile to use Capybara assertions." if ENV["DEBUG"]
|
21
|
+
# :nocov:
|
18
22
|
end
|
19
23
|
|
20
24
|
attr_reader :rendered_component
|
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.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: benchmark-ips
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.8.2
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.8.2
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: bundler
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,19 +171,19 @@ dependencies:
|
|
157
171
|
- !ruby/object:Gem::Version
|
158
172
|
version: 0.18.0
|
159
173
|
- !ruby/object:Gem::Dependency
|
160
|
-
name: simplecov-
|
174
|
+
name: simplecov-console
|
161
175
|
requirement: !ruby/object:Gem::Requirement
|
162
176
|
requirements:
|
163
177
|
- - "~>"
|
164
178
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
179
|
+
version: 0.7.2
|
166
180
|
type: :development
|
167
181
|
prerelease: false
|
168
182
|
version_requirements: !ruby/object:Gem::Requirement
|
169
183
|
requirements:
|
170
184
|
- - "~>"
|
171
185
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
186
|
+
version: 0.7.2
|
173
187
|
description:
|
174
188
|
email:
|
175
189
|
- opensource+view_component@github.com
|
@@ -201,6 +215,7 @@ files:
|
|
201
215
|
- lib/view_component/base.rb
|
202
216
|
- lib/view_component/collection.rb
|
203
217
|
- lib/view_component/compile_cache.rb
|
218
|
+
- lib/view_component/compiler.rb
|
204
219
|
- lib/view_component/engine.rb
|
205
220
|
- lib/view_component/preview.rb
|
206
221
|
- lib/view_component/preview_template_error.rb
|