Commit Graph

2633 Commits

Author SHA1 Message Date
John Hawthorn
9e0c42b0bd Perform details matching on UnboundTemplates
In old versions of Rails, we would rely entirely on what was returned by
Dir.glob to determine the match and sorting of our templates.

Later we switched to building a regex on each search, which allowed us
to perform a much faster glob, find matching templates with the regex,
and then emulate the sort order based on captures from the regex.

Now we have PathParser, which can parse any template's details
accurately from just its filename (not depending on the query being
made).

This commit moves the matching to done on UnboundTemplates, effectively
using details found by the PathParser for both matching and sorting of
templates, and removing the dynamic regex for queries.

This should be faster at boot/after reloads as we're no longer building
a regex and additionally we only need to parse a template's path for
details one time (we can use the same details for matching/sorting in
future queries with different details).
2021-04-20 14:35:40 -07:00
John Hawthorn
bf9edcb8a3 Determine virtual path from file path
Previously, it was possible for these not to match due to providing
templates with .'s or using fallback templates.

There is now an exact 1:1 between templates on disk and virtual path.
2021-04-20 13:48:15 -07:00
John Hawthorn
2be8d3ebf8 Store details on unbound template
Previously we just stored handler, format, and variant and assigned a
default format if none existed.

Now we want to also store locale, and move the default format behaviour
into unbound template.
2021-04-20 13:48:12 -07:00
John Hawthorn
8944bef657 Add TemplateDetails 2021-04-20 13:47:48 -07:00
John Hawthorn
a7048ac9e2 Perform template glob and checks at same time
Previously we would check that our paths were safe and inside the app
right before building templates. Instead we can do this, and reject
directories at the same time as we perform the glob.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2021-04-19 16:40:35 -07:00
John Hawthorn
70470d7eed
Merge pull request #41998 from jhawthorn/template_cache_clear_lock
Don't clear view cache during concurrent requests
2021-04-19 15:46:35 -07:00
Adam Hess
f80038ae7d Improve did_you_mean partial name correction
Before this change did_you_mean shows partial paths like `animals/_partial`,
but adding that to your render call in a view like `<%= render 'animals/_partial' %>`
 will still be missing as rails will search for the template `animals/__partial`.
We can provide the user a easier copy/paste correction if we don't tell them about the underscore.

This also reduces the candidates to only return partials if you are
looking for a partial and only look for non-templates when you are not
looking for a template.
2021-04-19 15:01:00 -07:00
John Hawthorn
9a4c1e205e Don't clear view cache during concurrent requests
This updates ActionView::CacheExpiry to hold a lock while inside the
executor (ie. inside a request) and to only clear caches when that is
done.

This is done using Concurrent::ReadWriteLock. This allows any number
of parallel requests to hold the read lock, but once we detect a change
and begin to acquire the write lock, all future requests will be
blocked.
2021-04-19 09:36:38 -07:00
Zachary Scott
0d91d4aa07
Merge pull request #41984 from jbampton/fix-case-of-css-and-javascript
chore: fix case of CSS and JavaScript
2021-04-16 14:49:18 +09:00
John Hawthorn
33e054edbc Convert Template::Types.type_klass to instance ivar 2021-04-15 18:05:07 -07:00
John Bampton
eef63e05fb chore: fix case of CSS and JavaScript 2021-04-15 21:52:58 +10:00
John Bampton
de3b207aa6 chore: fix grammar and spelling 2021-04-15 16:57:01 +10:00
John Hawthorn
c70bd1345d Remove autoloads for removed classes 2021-04-14 11:27:12 -07:00
John Hawthorn
a2b1ea3e9d Remove FileSystemResolver's PATTERN
This is no longer used
2021-04-14 11:27:11 -07:00
John Hawthorn
a1de5ed3ed Merge FileSystemResolver and PathResolver 2021-04-14 11:27:11 -07:00
John Hawthorn
5789e827d0 Remove overridden methods from PathResolver 2021-04-14 11:27:11 -07:00
John Hawthorn
faac734387 Merge {Optimized,}FileSystemResolver 2021-04-14 11:27:11 -07:00
John Hawthorn
e144f098f1 Reimplement NullResolver on base resolver 2021-04-14 11:27:11 -07:00
John Hawthorn
85ecf6e409 Remove support for templates with "."
This was previously deprecated in Rails 6.1 (and never quite behaved
correctly)
2021-04-14 11:27:11 -07:00
Zachary Scott
43e29f0f5d
Merge pull request #41945 from jbampton/fix-grammar
chore: fix grammar, spelling and minor whitespace fix
2021-04-14 09:19:15 +09:00
John Hawthorn
997c76cf80 Resolve wildcards depends using all_template_paths
This switches wildcard dependencies from using its custom
find_all_with_query method to use all_template_paths, the same method
now used for DidYouMean template suggestions.

This also removes related cache for wildcard queries. Since it was only
used during digesting, the digest cache should be sufficient.
2021-04-13 15:04:17 -07:00
John Hawthorn
6d11711042 Refactor suggestions into all_template_paths 2021-04-13 15:04:16 -07:00
John Bampton
4075b5b884
Fix spelling in FixtureResolverTest 2021-04-13 10:46:09 -04:00
John Bampton
54e526e473 chore: fix grammar, spelling and minor whitespace fix 2021-04-13 21:35:50 +10:00
Rafael Mendonça França
4354e3ae49
Don't define methods using the method modifier in the same line as the method
Our style guide use block method modifiers, not inline method modifiers.
2021-04-12 18:49:54 +00:00
John Bampton
44c32c1605 chore: remove redundant MIME type from HTML script tag
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
2021-04-12 06:57:03 +10:00
Jean Boussier
3f59640016 Stop checking if ruby2_keywords is defined 2021-04-11 13:42:02 +02:00
Ryuta Kamizono
3b1fae47db
Merge pull request #41886 from jacobherrington/add-example-for-params-button-to-doc
Add example of params to button_to docs [ci skip]
2021-04-09 11:09:17 +09:00
Jacob Herrington
4bfc35a4f9
Add example of params to button_to docs [ci skip]
Also, this commit updates the output in the examples to include the
authenticity token because it is rendered in all of the examples.
2021-04-08 14:19:56 -05:00
John Hawthorn
6fa9cd88b9 Add DidYouMean suggestions for missing templates
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2021-04-07 09:18:12 -07:00
John Hawthorn
fb6b0a51b3 Remove FallbackFileSystemResolver
This removes FallbackFileSystemResolver, LookupContext#with_fallbacks,
and LookupContext.fallbacks.

These used to exist to support `render file:`, and rendering templates
outside of the defined view paths. `render file:` has since been changed
to not use template resolution, and to only render absolute paths.

These were no longer callable through any public API.
2021-04-06 14:20:48 -07:00
Ryuta Kamizono
c7a036c2b6 Revert "Passing in a Hash instance as non-kwargs parameters has to be curly braced now"
This reverts commit d2f4541f126001e029078cc48a3a481e23ae3ed9.

It should work without curly braces.

See also: #41198, #41206, 81d90d81d0ee1fc1a649ab705119a71f2d04c8a2.
2021-03-22 11:21:33 +09:00
Ryuta Kamizono
81d90d81d0 Allow both current_page?(url_hash) and current_page?(**url_hash) on Ruby 2.7
Keyword argument warnings are caused by #41206 to allow both
`current_page?(url_hash)` and `current_page?(**url_hash)` on Ruby 3.0.

Unfortunately it is super hard to support that for both Ruby 2.7 and 3.0
with the same method signature.

Closes #41710.
2021-03-22 10:57:45 +09:00
Máximo Mussini
1598ad5c4b
Ensure modules are preloaded correctly using rel=modulepreload.
Prior to this change, javascript_include_tag was sending a hint using
rel="preload" for all scripts, including those of type="module".

This causes the browser to make a request to preload the script, but
because the rel is incorrect, it won't be able to reuse it.

When passing type="module", it should use rel=modulepreload instead.

[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
2021-03-19 13:22:22 -04:00
Alex Ghiculescu
0fba70c082 Clarify when enctype="multipart/form-data" gets added to forms [docs]
As noted in https://github.com/rails/rails/issues/41632 the docs for this are incorrect. The `enctype` attribute is automatically added anytime you make a form with a `file_field`.

Resolves https://github.com/rails/rails/issues/41632

Update actionview/lib/action_view/helpers/form_helper.rb

Co-authored-by: Petrik de Heus <petrik@deheus.net>
2021-03-10 13:09:46 -06:00
Sohaib Talaat Bhatti
3f3f7af9e8 Fix phone_to API documentation sample output 2021-03-05 17:05:24 +05:00
Austen Madden
986cdba7d2 Clarify button_to html_options documentation
Further explain how html_options can be used in button_to. Specifically
with regard to html_options passed to the button (form submit) element.
2021-03-01 09:54:25 -05:00
Carlos Antonio da Silva
3875e07f3c Simplify formmethod checks on button_to for non-GET/POST handling
* Check for the presence of `formmethod` first before checking against
  the GET/POST verbs;
* Use `match?` to avoid creating unnecessary match objects;
* Remove capture groups from the verb regexp.
2021-02-22 10:08:48 -03:00
Rafael França
89b52a8dd3
Merge pull request #41472 from Shopify/stylesheet-duplicated-media
Fix the duplicated media attribute in stylesheet_link_tag
2021-02-17 10:09:48 -05:00
Jean Boussier
1b70109aee Fix the duplicated media attribute in stylesheet_link_tag 2021-02-17 11:34:39 +01:00
Petrik
9ecae8336f Update Rails version in depraction and add non-deprecated code
Passing instance variables to `render` will be deprecated in the next
version, which is Rails 7.1.
Also add the non-deprecated implementation, which removes `@?` from the
Regexp, to make removal of the deprecation easier.
2021-02-17 09:41:37 +01:00
Rafael França
fe912cb1a7
Merge pull request #41464 from p8/deprecate-ivars-locals-in-render-partial
Deprecate render locals to be assigned to instance variables
2021-02-16 14:24:59 -05:00
Petrik
96d72d9b25 Deprecate render locals to be assigned to instance variables
Rails partial rendering allows assigning instance variables.
For example:

  render 'partial', :@name => "Maceo"

This sets @name to "Maceo" on the ActionView::Base object.

The allowed instance variables aren't restricted to the user's defined
instance variables but can also override private Rails variables like
@_assigns, @output_buffer, @_config, and @_default_form_builder.
2021-02-16 20:06:59 +01:00
Rafael França
a642b7c02b
Merge pull request #41450 from jonathanhefner/sms_to-improve-api-doc
Improve sms_to API documentation [ci-skip]
2021-02-15 18:52:18 -05:00
Rafael França
3c63f57a5c
Merge pull request #41451 from jonathanhefner/mail_to-support-options-when-no-name
Support mail_to options when name not specified
2021-02-15 18:51:51 -05:00
Rafael França
6834102840
Merge pull request #41449 from jonathanhefner/sms_to-support-options-when-no-name
Support sms_to options when name not specified
2021-02-15 18:51:32 -05:00
Jonathan Hefner
5b8fee1be1 Improve sms_to API documentation [ci-skip]
This tightens the prose a bit.
2021-02-15 11:42:12 -06:00
Jonathan Hefner
96106d80aa
Merge pull request #41444 from jonathanhefner/phone_to-improve-api-doc
Improve phone_to API documentation [ci-skip]
2021-02-15 11:18:17 -06:00
Jonathan Hefner
4f1f63b98a
Merge pull request #41441 from jonathanhefner/apidocs-inline-code-markup
Fix inline code markup [ci-skip]
2021-02-15 11:16:44 -06:00
Jonathan Hefner
63edd5cd2f Improve phone_to API documentation [ci-skip]
This tightens the prose, and fixes grammar, typos, and code markup.
2021-02-15 11:07:22 -06:00