view_component 2.52.0 → 2.62.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eb8c14aae22e2977db7cde77cd64f9ff1d69f14c0f2c95b6b2ebf0fabf67f5a
4
- data.tar.gz: fe2c729ae013bf1dd2effb17143acfef756e915ea773dcb7eef84fd329c7e002
3
+ metadata.gz: e57d7d7eece678a577cf5f89f4b506fbe1026c79cc8b28d269e6984a01de29c7
4
+ data.tar.gz: e8fd167897e4bbcfaf0b4d657605acf26a5e1c6dc72e6fd5a868e0e0e76d232b
5
5
  SHA512:
6
- metadata.gz: 0e72fac02dd38cd39cfa7fe45bc57617a8088d2016add0c769df9075393dc8fde66ea44c96d466019354585da3754b1db2099e9207a46418b011e6ef8765b816
7
- data.tar.gz: 6ec82473f583cd484e9ee4042683d7d605131279ef855a199f1a89292967dd971c6ed8a43f8ad7fc9d519bae02fb4f2e5cf8d14f4876ffa1b524ad41ce25ea20
6
+ metadata.gz: a6bae85903899c93cb78e11a49082c4e6c2393605c9b3e94cca98ecff1e790a97dd7acda4c5e13b11ad4e4591384d0d30e62d86831998577531b595378f9fcb7
7
+ data.tar.gz: 814913871cc0d5b4865a6864a0585f06d6c26088cdbab888e4c4d33787f7ab2e74c9dafffd52fe726999d03b9a453186b3f495afc1c0c9da5207b5edb3a89480
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module PreviewActions
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ prepend_view_path File.expand_path("../../../views", __dir__)
9
+
10
+ around_action :set_locale, only: :previews
11
+ before_action :require_local!, unless: :show_previews?
12
+
13
+ if respond_to?(:content_security_policy)
14
+ content_security_policy(false)
15
+ end
16
+ end
17
+
18
+ def index
19
+ @previews = ViewComponent::Preview.all
20
+ @page_title = "Component Previews"
21
+ render "view_components/index", **determine_layout
22
+ end
23
+
24
+ def previews
25
+ find_preview
26
+
27
+ if params[:path] == @preview.preview_name
28
+ @page_title = "Component Previews for #{@preview.preview_name}"
29
+ render "view_components/previews", **determine_layout
30
+ else
31
+ prepend_application_view_paths
32
+ prepend_preview_examples_view_path
33
+ @example_name = File.basename(params[:path])
34
+ @render_args = @preview.render_args(@example_name, params: params.permit!)
35
+ layout = determine_layout(@render_args[:layout], prepend_views: false)[:layout]
36
+ locals = @render_args[:locals]
37
+ opts = {}
38
+ opts[:layout] = layout if layout.present? || layout == false
39
+ opts[:locals] = locals if locals.present?
40
+ render "view_components/preview", opts
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ # :doc:
47
+ def default_preview_layout
48
+ ViewComponent::Base.default_preview_layout
49
+ end
50
+
51
+ # :doc:
52
+ def show_previews?
53
+ ViewComponent::Base.show_previews
54
+ end
55
+
56
+ # :doc:
57
+ def find_preview
58
+ candidates = []
59
+ params[:path].to_s.scan(%r{/|$}) { candidates << $` }
60
+ preview = candidates.detect { |candidate| ViewComponent::Preview.exists?(candidate) }
61
+
62
+ if preview
63
+ @preview = ViewComponent::Preview.find(preview)
64
+ else
65
+ raise AbstractController::ActionNotFound, "Component preview '#{params[:path]}' not found."
66
+ end
67
+ end
68
+
69
+ def set_locale
70
+ I18n.with_locale(params[:locale] || I18n.default_locale) do
71
+ yield
72
+ end
73
+ end
74
+
75
+ # Returns either {} or {layout: value} depending on configuration
76
+ def determine_layout(layout_override = nil, prepend_views: true)
77
+ return {} unless defined?(Rails.root)
78
+
79
+ layout_declaration = {}
80
+
81
+ if !layout_override.nil?
82
+ # Allow component-level override, even if false (thus no layout rendered)
83
+ layout_declaration[:layout] = layout_override
84
+ elsif default_preview_layout.present?
85
+ layout_declaration[:layout] = default_preview_layout
86
+ end
87
+
88
+ prepend_application_view_paths if layout_declaration[:layout].present? && prepend_views
89
+
90
+ layout_declaration
91
+ end
92
+
93
+ def prepend_application_view_paths
94
+ prepend_view_path Rails.root.join("app/views") if defined?(Rails.root)
95
+ end
96
+
97
+ def prepend_preview_examples_view_path
98
+ prepend_view_path(ViewComponent::Base.preview_paths)
99
+ end
100
+ end
101
+ end
@@ -3,91 +3,5 @@
3
3
  require "rails/application_controller"
4
4
 
5
5
  class ViewComponentsController < Rails::ApplicationController # :nodoc:
6
- prepend_view_path File.expand_path("../views", __dir__)
7
-
8
- around_action :set_locale, only: :previews
9
- before_action :find_preview, only: :previews
10
- before_action :require_local!, unless: :show_previews?
11
-
12
- if respond_to?(:content_security_policy)
13
- content_security_policy(false)
14
- end
15
-
16
- def index
17
- @previews = ViewComponent::Preview.all
18
- @page_title = "Component Previews"
19
- render "view_components/index", **determine_layout
20
- end
21
-
22
- def previews
23
- if params[:path] == @preview.preview_name
24
- @page_title = "Component Previews for #{@preview.preview_name}"
25
- render "view_components/previews", **determine_layout
26
- else
27
- prepend_application_view_paths
28
- prepend_preview_examples_view_path
29
- @example_name = File.basename(params[:path])
30
- @render_args = @preview.render_args(@example_name, params: params.permit!)
31
- layout = determine_layout(@render_args[:layout], prepend_views: false)[:layout]
32
- locals = @render_args[:locals]
33
- opts = {}
34
- opts[:layout] = layout if layout.present? || layout == false
35
- opts[:locals] = locals if locals.present?
36
- render "view_components/preview", opts # rubocop:disable GitHub/RailsControllerRenderLiteral
37
- end
38
- end
39
-
40
- private
41
-
42
- def default_preview_layout # :doc:
43
- ViewComponent::Base.default_preview_layout
44
- end
45
-
46
- def show_previews? # :doc:
47
- ViewComponent::Base.show_previews
48
- end
49
-
50
- def find_preview # :doc:
51
- candidates = []
52
- params[:path].to_s.scan(%r{/|$}) { candidates << $` }
53
- preview = candidates.detect { |candidate| ViewComponent::Preview.exists?(candidate) }
54
-
55
- if preview
56
- @preview = ViewComponent::Preview.find(preview)
57
- else
58
- raise AbstractController::ActionNotFound, "Component preview '#{params[:path]}' not found."
59
- end
60
- end
61
-
62
- def set_locale
63
- I18n.with_locale(params[:locale] || I18n.default_locale) do
64
- yield
65
- end
66
- end
67
-
68
- # Returns either {} or {layout: value} depending on configuration
69
- def determine_layout(layout_override = nil, prepend_views: true)
70
- return {} unless defined?(Rails.root)
71
-
72
- layout_declaration = {}
73
-
74
- if !layout_override.nil?
75
- # Allow component-level override, even if false (thus no layout rendered)
76
- layout_declaration[:layout] = layout_override
77
- elsif default_preview_layout.present?
78
- layout_declaration[:layout] = default_preview_layout
79
- end
80
-
81
- prepend_application_view_paths if layout_declaration[:layout].present? && prepend_views
82
-
83
- layout_declaration
84
- end
85
-
86
- def prepend_application_view_paths
87
- prepend_view_path Rails.root.join("app/views") if defined?(Rails.root)
88
- end
89
-
90
- def prepend_preview_examples_view_path
91
- prepend_view_path(ViewComponent::Base.preview_paths)
92
- end
6
+ include ViewComponent::PreviewActions
93
7
  end
@@ -7,14 +7,14 @@ module PreviewHelper
7
7
  def preview_source
8
8
  return if @render_args.nil?
9
9
 
10
- render "preview_source" # rubocop:disable GitHub/RailsViewRenderPathsExist
10
+ render "preview_source"
11
11
  end
12
12
 
13
13
  def find_template_data(lookup_context:, template_identifier:)
14
14
  template = lookup_context.find_template(template_identifier)
15
15
 
16
16
  if Rails.version.to_f >= 6.1 || template.source.present?
17
- return {
17
+ {
18
18
  source: template.source,
19
19
  prism_language_name: prism_language_name_by_template(template: template)
20
20
  }
@@ -40,7 +40,7 @@ module PreviewHelper
40
40
  template_source = File.read(template_file_path)
41
41
  prism_language_name = prism_language_name_by_template_path(template_file_path: template_file_path)
42
42
 
43
- return {
43
+ {
44
44
  source: template_source,
45
45
  prism_language_name: prism_language_name
46
46
  }
data/docs/CHANGELOG.md CHANGED
@@ -3,10 +3,290 @@ layout: default
3
3
  title: Changelog
4
4
  ---
5
5
 
6
+ <!-- Add unreleased changes under the "main" heading. -->
7
+
6
8
  # Changelog
7
9
 
8
10
  ## main
9
11
 
12
+ ## 2.62.0
13
+
14
+ * Remove the experimental global output buffer feature.
15
+ * Restore functionality that used to attempt to compile templates on each call to `#render_in`.
16
+ * Un-pin `rails` `main` dependency.
17
+
18
+ *Cameron Dutro*
19
+
20
+ * Add blank space between "in" and "ViewComponent" in a deprecation warning.
21
+
22
+ *Vikram Dighe*
23
+
24
+ * Add HappyCo to list of companies using ViewComponent.
25
+
26
+ *Josh Clayton*
27
+
28
+ ## 2.61.1
29
+
30
+ * Revert `Expose Capybara DSL methods directly inside tests.` This change unintentionally broke other Capybara methods and thus introduced a regression. We aren't confident that we can fail forward so we have decided to revert this change.
31
+
32
+ *Joel Hawksley*, *Blake Williams*
33
+
34
+ * Revert change making content evaluation consistent.
35
+
36
+ *Blake Williams*
37
+
38
+ * Pin `rails` `main` dependency due to incompatibility with Global Output Buffer.
39
+
40
+ *Joel Hawksley*
41
+
42
+ ## 2.61.0
43
+
44
+ * Ensure side-effects in `content` are consistently evaluated before components are rendered. This change effectively means that `content` is evaluated for every component render where `render?` returns true. As a result, code that is passed to a component via a block/content will now always be evaluated, before `#call`, which can reveal bugs in existing components.
45
+
46
+ *Blake Williams*
47
+
48
+ ## 2.60.0
49
+
50
+ * Add support for `render_preview` in RSpec tests.
51
+
52
+ *Thomas Hutterer*
53
+
54
+ ## 2.59.0
55
+
56
+ * Expose Capybara DSL methods directly inside tests.
57
+
58
+ The following Capybara methods are now available directly without having to use the `page` method:
59
+
60
+ * [`all`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FFinders:all)
61
+ * [`first`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FFinders:first)
62
+ * [`text`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FSimple:text)
63
+ * [`find`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find)
64
+ * [`find_all`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_all)
65
+ * [`find_button`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_button)
66
+ * [`find_by_id`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_by_id)
67
+ * [`find_field`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_field)
68
+ * [`find_link`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_link)
69
+ * [`has_content?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_content%3F)
70
+ * [`has_text?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_text%3F)
71
+ * [`has_css?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_css%3F)
72
+ * [`has_no_content?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_content%3F)
73
+ * [`has_no_text?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_text%3F)
74
+ * [`has_no_css?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_css%3F)
75
+ * [`has_no_xpath?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_xpath%3F)
76
+ * [`has_xpath?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_xpath%3F)
77
+ * [`has_link?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_link%3F)
78
+ * [`has_no_link?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_link%3F)
79
+ * [`has_button?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_button%3F)
80
+ * [`has_no_button?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_button%3F)
81
+ * [`has_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_field%3F)
82
+ * [`has_no_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_field%3F)
83
+ * [`has_checked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_checked_field%3F)
84
+ * [`has_unchecked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_unchecked_field%3F)
85
+ * [`has_no_table?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_table%3F)
86
+ * [`has_table?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_table%3F)
87
+ * [`has_select?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_select%3F)
88
+ * [`has_no_select?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_select%3F)
89
+ * [`has_selector?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_selector%3F)
90
+ * [`has_no_selector?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_selector%3F)
91
+ * [`has_no_checked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_checked_field%3F)
92
+ * [`has_no_unchecked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_unchecked_field%3F)
93
+
94
+ * Add support for `within*` Capybara DLS methods:
95
+
96
+ * [`within`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within)
97
+ * [`within_element`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within)
98
+ * [`within_fieldset`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within_fieldset)
99
+ * [`within_table`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within_table)
100
+
101
+ *Jacob Carlborg*
102
+
103
+ ## 2.58.0
104
+
105
+ * Switch to `standardrb`.
106
+
107
+ *Joel Hawksley*
108
+
109
+ * Add BootrAils article to resources.
110
+
111
+ *Joel Hawksley*
112
+
113
+ * Add @boardfish and @spone as maintainers.
114
+
115
+ *Joel Hawksley*, *Cameron Dutro*, *Blake Williams*
116
+
117
+ * Re-compile updated, inherited templates when class caching is disabled.
118
+
119
+ *Patrick Arnett*
120
+
121
+ * Add the latest version to the docs index.
122
+ * Improve the docs: add the versions various features were introduced in.
123
+
124
+ *Hans Lemuet*
125
+
126
+ * Update docs to reflect lack of block content support in controllers.
127
+
128
+ *Joel Hawksley*
129
+
130
+ * Prevent adding duplicates to `autoload_paths`.
131
+
132
+ *Thomas Hutterer*
133
+
134
+ * Add FreeAgent to list of companies using ViewComponent.
135
+
136
+ *Simon Fish*
137
+
138
+ * Include polymorphic slots in `ViewComponent::Base` by default.
139
+
140
+ *Cameron Dutro*
141
+
142
+ * Add per-component config option for stripping newlines from templates before compilation.
143
+
144
+ *Cameron Dutro*
145
+
146
+ * Add link to article by Matouš Borák.
147
+
148
+ *Joel Hawksley*
149
+
150
+ ## 2.57.1
151
+
152
+ * Fix issue causing `NoMethodError`s when calling helper methods from components rendered as part of a collection.
153
+ * Fix syntax error in the ERB example in the polymorphic slots docs.
154
+
155
+ *Cameron Dutro*
156
+
157
+ ## 2.57.0
158
+
159
+ * Add missing `require` for `Translatable` module in `Base`.
160
+
161
+ *Hans Lemuet*
162
+
163
+ * Allow anything that responds to `#render_in` to be rendered in the parent component's view context.
164
+
165
+ *Cameron Dutro*
166
+
167
+ * Fix script/release so it honors semver.
168
+
169
+ *Cameron Dutro*
170
+
171
+ ## 2.56.2
172
+
173
+ * Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
174
+
175
+ *Tyson Gach*, *Richard Macklin*, *Joel Hawksley*
176
+
177
+ ## 2.56.1
178
+
179
+ * Rename private accessor `rendered_component` to `rendered_content`.
180
+
181
+ *Yoshiyuki Hirano*, *Simon Dawson*
182
+
183
+ ## 2.56.0
184
+
185
+ * Introduce experimental `render_preview` test helper. Note: `@rendered_component` in `TestHelpers` has been renamed to `@rendered_content`.
186
+
187
+ *Joel Hawksley*
188
+
189
+ * Move framework tests into sandbox application.
190
+
191
+ *Joel Hawksley*
192
+
193
+ * Add G2 to list of companies that use ViewComponent.
194
+
195
+ *Jack Shuff*
196
+
197
+ * Add Within3 to list of companies that use ViewComponent.
198
+
199
+ *Drew Bragg*
200
+
201
+ * Add Mission Met to list of companies that use ViewComponent.
202
+
203
+ *Nick Smith*
204
+
205
+ * Fix `#with_request_url` test helper not parsing nested query parameters into nested hashes.
206
+
207
+ *Richard Marbach*
208
+
209
+ ## 2.55.0
210
+
211
+ * Add `render_parent` convenience method to avoid confusion between `<%= super %>` and `<% super %>` in template code.
212
+
213
+ *Cameron Dutro*
214
+
215
+ * Add note about discouraging inheritance.
216
+
217
+ *Joel Hawksley*
218
+
219
+ * Clean up grammar in documentation.
220
+
221
+ *Joel Hawksley*
222
+
223
+ * The ViewComponent team at GitHub is hiring! We're looking for a Rails engineer with accessibility experience: [https://boards.greenhouse.io/github/jobs/4020166](https://boards.greenhouse.io/github/jobs/4020166). Reach out to joelhawksley@github.com with any questions!
224
+
225
+ * The ViewComponent team is hosting a happy hour at RailsConf. Join us for snacks, drinks, and stickers: [https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427](https://www.eventbrite.com/e/viewcomponent-happy-hour-tickets-304168585427)
226
+
227
+ ## 2.54.1
228
+
229
+ * Update docs dependencies.
230
+
231
+ *Joel Hawksley*
232
+
233
+ * Resolve warning in slots API.
234
+ * Raise in the test environment when ViewComponent code emits a warning.
235
+
236
+ *Blake Williams*
237
+
238
+ ## 2.54.0
239
+
240
+ * Add `with_*` slot API for defining slots. Note: we plan to deprecate the non `with_*` API for slots in an upcoming release.
241
+
242
+ *Blake Williams*
243
+
244
+ * Add QuickNode to list of companies that use ViewComponent.
245
+
246
+ *Luc Castera*
247
+
248
+ * Include the `Translatable` module by default.
249
+
250
+ *Elia Schito*
251
+
252
+ * Update docs dependencies.
253
+
254
+ *Joel Hawksley*
255
+
256
+ ## 2.53.0
257
+
258
+ * Add support for relative I18n scopes to translations.
259
+
260
+ *Elia Schito*
261
+
262
+ * Update CI configuration to use latest Rails 7.0.
263
+
264
+ *Hans Lemuet*
265
+
266
+ * Document how to use blocks with lambda slots.
267
+
268
+ *Sam Partington*
269
+
270
+ * Skip Rails 5.2 in local test environment if using incompatible Ruby version.
271
+
272
+ *Cameron Dutro*, *Blake Williams*, *Joel Hawksley*
273
+
274
+ * Improve landing page documentation.
275
+
276
+ *Jason Swett*
277
+
278
+ * Add Bearer to list of companies that use ViewComponent.
279
+
280
+ *Yaroslav Shmarov*
281
+
282
+ * Add articles to resources page.
283
+
284
+ *Joel Hawksley*
285
+
286
+ * Enable rendering arbitrary block contents in the view context in tests.
287
+
288
+ *Cameron Dutro*
289
+
10
290
  ## 2.52.0
11
291
 
12
292
  * Add ADR for separate slot getter/setter API.
@@ -124,10 +404,14 @@ title: Changelog
124
404
 
125
405
  *Joel Hawksley*
126
406
 
127
- * Add Ruby 3.1 and Rails 7.0 to CI
407
+ * Add Ruby 3.1 and Rails 7.0 to CI.
128
408
 
129
409
  *Peter Goldstein*
130
410
 
411
+ * Move preview logic to module for easier app integration.
412
+
413
+ *Sammy Henningsson*
414
+
131
415
  ## 2.48.0
132
416
 
133
417
  * Correct path in example test command in Contributing docs.
@@ -36,10 +36,10 @@ module ViewComponent
36
36
 
37
37
  def stimulus_controller
38
38
  if options["stimulus"]
39
- File.join(destination_directory, destination_file_name).
40
- sub("#{component_path}/", "").
41
- gsub("_", "-").
42
- gsub("/", "--")
39
+ File.join(destination_directory, destination_file_name)
40
+ .sub("#{component_path}/", "")
41
+ .tr("_", "-")
42
+ .gsub("/", "--")
43
43
  end
44
44
  end
45
45