Commit Graph

2854 Commits

Author SHA1 Message Date
Rafael Mendonça França 2a55e3432c
Merge pull request #43886 from seanpdoyle/form-builder-button-method-name-id
Generate `[id]` for `FormBuilder#button` called with method name
2021-12-15 18:12:47 -05:00
Sean Doyle c6c138ef86 Generate `[id]` for `FormBuilder#button` called with method name
Follow-up to [rails/rails#43411][] (merged in [15f6113][])

By default, when generating a `<button>` element through a Form Builder
instance, the element's `[name]` attribute is populated by calling the
`FormBuilder#field_name` method. This commit assigns a matching default
`[id]` attribute generated by `FormBuilder#field_id`.

Additionally, it adds test coverage to ensure that calls that provide
their own `name:` and `id:` options are not overridden by the default
values.

[rails/rails#43411]: https://github.com/rails/rails/pull/43411
[15f6113]: 15f6113622
2021-12-15 17:49:28 -05:00
Alexandru-Emil Lupu fad2c430ed Fix exception when loading stylesheets in actionmailer templates 2021-12-16 00:42:23 +02:00
Rafael Mendonça França 68f4fbc7cf
Merge pull request #43850 from hachi8833/fix_favicon_link_tag
Remove "shortcut" link type from favicon_link_tag method
2021-12-14 20:37:34 -05:00
Rafael Mendonça França dae7e46db4
Remove CHANGELOG entry that is already in 7-0-stable 2021-12-15 00:55:18 +00:00
Sean Doyle 4f191b9754 ActiveStorage: support empty attachments submits
The background
---

Configuration for replacing a collection was introduced in
[rails/rails#36716][].

However, since [rails/rails#42596][] has been merged, Rails 7.1 and
beyond will default to _replacing_ an Active Storage `has_many_attached`
relationship, as opposed to _appending to it_.

The problem
---

With replacement as the established precedent, it's currently a
challenge to replace an existing collection with an empty one.

The solution
---

This commit makes two changes.

The first is to Action View and its form building helpers. The change
draws inspiration from how an `<input type="checkbox">` field (or
collection of fields) is paired with an `<input type="hidden">` field to
represent the unchecked value. The change pairs any `<input type="file"
multiple="multiple">` elements with an `<input type="hidden">` element
to represent an empty collection. Like the [check_box][] form builder
method, the `file_field`  method accepts an `include_hidden:` option to
skip the creation of the hidden element.

The second is to how Active Storage generates attribute assignment
methods through `has_many_attached`. With the possibility of an `<input
type="file">` field being paired with an `<input type="hidden"
value="">` field, the backing models need to be able to coerce an
"empty-ish" value into an empty list. For example:

```ruby
@user.highlights = [""]
@user.highlights        # => []
```

When combined, these changes enable consumer applications to submit
"empty" collections to blank out existing attachments.

Support is configured through the
`config.active_storage.multiple_file_field_include_hidden` configuration
value, which defaults to `false`.

[check_box]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box
[rails/rails#36716]: https://github.com/rails/rails/pull/36716
[rails/rails#42596]: https://github.com/rails/rails/pull/42596
2021-12-14 18:40:35 -05:00
Sean Doyle 0b8dde0078 FormBuilder#field_id: prepend `namespace:` option
When constructing the field's `[id]` attribute, the current
`FormBuilder#field_id` implementation (introduced in [59ca21c][])
ignores the `namespace:` option.

This commit incorporates any namespace by prepending it to the
`@object_name`.

[59ca21c]: 59ca21c011

Re-use template.field_id
---

Thread options[:namespace] down through the FormBuilder instance to the
`Tags::Base#tag_id` and `#add_default_name_and_id` methods
2021-12-14 18:00:01 -05:00
Pedro Moreira 3edada28fa
Fix rubocop issue of single- vs double- quotes (+1 squashed commit)
Squashed commits:
[49cb03a3ce] Fix missing return from ActionView::Helpers::NumberHelper#parse_float, fixes #43853
Add test case for number helpers not raising exception when `raise: true` is passed and input is valid
2021-12-13 16:48:53 +00:00
hachi8833 240c1ace76 Remove "shortcut" link type from favicon_link_tag method
Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types
Ref: https://mathiasbynens.be/notes/rel-shortcut-icon

Update layout.html.erb for Guides

Remove "shortcut" from welcome page
2021-12-13 13:49:43 +09:00
Rafael Mendonça França 7160f46a9e
Merge pull request #43368 from FestaLab/render-hash-syntax
Replaces the hash rocket operator in favor of the newer Ruby syntax on render
2021-12-08 18:13:44 -05:00
Rafael Mendonça França 83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Rafael Mendonça França c2e12e0191
Use `to_formatted_s(:db)` instead of `to_s(:db)` internally
Ruby 3.1 introduced an optimization to string interpolation for some
core classes in b08dacfea3.

But since we override `to_s` in some of those core classes to add behavior
like `to_s(:db)`, all Rails applications will not be able to take advantage
of that improvement.

Since we can use the `to_formatted_s` alias for the Rails specific behavior
it is best for us to deprecate the `to_s` core extension and allow Rails
applications to get the proformace improvement.

This commit starts removing all the `to_s(:db)` calls inside the framework
so we can deprecate the core extension in the next commit.
2021-12-06 19:22:04 +00:00
Zhongying Qiao c92ac83fe6
In #4342, part of the functionalities of form_for was delegated to form_with, this could potentially cause some regress, as the condition to send polymorphic_path(record, {}) instead of polymorphic_path(record, format: options.delete(:format)) is removed and when format is not passed, this causes issues if the caller is not expecting an extra arg format:nil. This PR adds back the condition inside for with and add a test to make sure it doesn't break for_with 2021-12-02 13:29:38 -08:00
Jean Boussier 6dc9e3309f Action View: allow to compile ERB templates with `# frozen_string_literal: true`
This can save a significant amount of string allocation in some scenarios
and is more consistent with modern Ruby code where `frozen_string_literal`
is enabled most of the time.
2021-11-29 10:38:51 +01:00
Jean Boussier b4eae47bbe Eliminate internal uses of `PerThreadRegistry` and deprecate it
This module has been soft deprecated for a long time, but since
it was used internally it wasn't throwing deprecation warnings.

Now we can throw a deprecation warning.
2021-11-22 09:53:16 +01:00
Sean Doyle 4997cc7f86 Implement `form_for` by delegating to `form_with`
Improve the parity between `form_for` and `form_with` by implementing
`form_for` in terms of `form_with`.

Replaces `html_options` transformations with coercion of data into the
shape it needs to be in order to delegate to `form_with`.

In the same spirit, this commit also implements `fields_for` in terms of
`fields`.
2021-11-19 16:22:01 -05:00
Sean Doyle bcb6c359f6 Call `#html_options_for_form` within `form_with`
The private [FormTagHelper#html_options_for_form][] helper covers the
same logic as [FormHelper#html_options_for_form_with][].

This commit replaces the re-implementation within `#form_with` with a
call to `#html_options_for_form`. In order to pass along the data in a
correct shape, keep the `#html_options_for_form_with` method and use it
to coerce the options.

[FormTagHelper#html_options_for_form]: fb1ab3460a/actionview/lib/action_view/helpers/form_tag_helper.rb (L873-L894)
[FormHelper#html_options_for_form_with]: fb1ab3460a/actionview/lib/action_view/helpers/form_helper.rb (L1552-L1579)
2021-11-19 11:37:51 -05:00
Rafael Mendonça França 884c97fad0
Remove deprecated support concat errors to `ActiveModel::Errors#messages` 2021-11-17 21:51:25 +00:00
Rafael Mendonça França d4ad739454
Remove deprecated `Rails.config.action_view.raise_on_missing_translations` 2021-11-17 21:51:16 +00:00
Rafael Mendonça França 1a06f5dc09
Fix typo in the documentation 2021-11-15 23:24:00 +00:00
Rafael Mendonça França 41e41360bb
Remove code duplication by extracting the _object_for_form_builder private method 2021-11-15 23:23:44 +00:00
Rafael Mendonça França 846f9e9595
Merge PR #43416 2021-11-15 22:55:37 +00:00
Rafael Mendonça França 033822117b
Merge PR #43413 2021-11-15 22:35:01 +00:00
Rafael Mendonça França 39a25ba57e
Fix typo in the documentation
Fixes #43651
2021-11-15 22:26:22 +00:00
Sean Doyle 15f6113622 Support name Symbol to `FormBuilder#button`
Since `<button>` elements translate their `[name]` and `[value]`
attributes to the resulting `<form>` element submission, and are encoded
into the resulting `URLSearchParams` or `FormData` instance, Action View
`FormBuilder` instances should support encoding a method name the same
way it does for other fields.

For instance, consider this HTML:

```html
<button>Publish</button>
<button name="post[draft]" value="true">Save as draft</button>
```

Clicking the "Publish" button would submit the form without encoding any
additional `[name]` and `[value]` pairs.

Clicking the "Save as draft" button would submit the form and encode
`post[draft]=true` into the submission.

This commit changes the `FormBuilder#button` method to interpret a
`Symbol` as the first argument as a method name argument, and encodes
its value based on the form's `model:` or `scope:` value:

```erb
<%= form.button :draft, value: true do %>
  Save as draft
<% end %>
end
<%# =>  <button name="post[draft]" value="true" type="submit">  %>
<%#       Save as draft                                         %>
<%#     </button>                                               %>
```

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2021-11-15 21:40:06 +00:00
Rafael Mendonça França 876d2ff904
Merge PR #43409 2021-11-15 21:20:34 +00:00
Rafael Mendonça França 27d24e9caa
Merge PR #42755 2021-11-15 21:11:59 +00:00
Rafael Mendonça França 1fde031e89 Fix gemspec 2021-11-15 21:06:21 +00:00
Rafael Mendonça França 9195b7fd0a
Require MFA to release rails 2021-11-15 20:37:42 +00:00
Ryuta Kamizono 26e89c7f95 Add missing # [ci skip] 2021-11-15 14:23:12 +09:00
Ryuta Kamizono ab60159bc2 Fix broken rdoc for form_with [ci skip] 2021-11-15 14:08:36 +09:00
Gannon McGibbon fb36712781
Merge pull request #38957 from DmitryTsepelev/store-per-attachment-direct-upload
Pass service_name param to DirectUploadsController
2021-11-15 00:06:17 -05:00
Guillermo Iguaran b667e48b22
Merge branch 'main' into button-to-authenticity-token 2021-11-14 11:36:48 -08:00
Guillermo Iguaran e0076e4c68
Merge pull request #42051 from seanpdoyle/form-empty-action
Support `<form>` elements without `[action]`
2021-11-14 11:29:29 -08:00
DmitryTsepelev 193289dbbe Support direct uploads to multiple services 2021-11-14 11:49:06 +03:00
Sean Doyle 4765698951 Document `tag.attributes` helper
The `tag.attributes` helper introduced in [#40657][] is implemented on a
`:nodoc:`-private `TagBuilder` class, so the documentation for the
method is omitted when generating the API Guides HTML pages.

This commit extends the `ActionView::Helpers::TagHelper` module
documentation comment to mention the new attribute building
capabilities, along with some examples.

[#40657]: https://github.com/rails/rails/pull/40657
2021-11-09 12:13:19 -05:00
Sean Doyle 3dae4469af Support `<form>` elements without `[action]`
Some background
---

By default, when a `<form>` is declared without an `[action]` attribute,
browsers will encode a `<form>`'s fields into the _current_ URL.

This can be useful for a `<form method="get">` that operates on the
current page. For example, when filtering search results, a form that
sorts:

```html
<form method="get">
  <button name="sort" value="desc">Most to least</button>
  <button name="sort" value="asc">Least to most</button>
</form>
```

can operate on a page that is filtered in another way by merging the
`?sort=asc` or `?sort=desc` values _into_ the existing page, which might
have the `?q=...` string set elsewhere.

The problem
---

Prior to this commit, none of the `<form>` construction variations
supported declaring a `<form>` without an `[action]` attribute.
`form_with`, `form_for`, and `form_tag` all default to `url_for({})`
when a `url:` or `action:` option is omitted.

The solution
---

Treat `url: false`, or `action: false` as an escape hatch to signal to
Action View that we don't need to transform the `model:` option or
argument into a Rails route.

Similarly, when calling `button_to` with `false` as the URL options
arguments will construct a `<form>` element without an `[action]`
attribute.
2021-10-29 10:08:47 -04:00
Sean Doyle 9c86593caa Execute `field_error_proc` within view
Instead of treating it as an anonymous block, execute the
`ActionView::Base.field_error_proc` within the context of the
`ActionView::Base` instance.

This enables consumer applications to continue to override the proc as
they see fit, but frees them from declaring templating logic within a
`config/initializers/*.rb`, `config/environments/*.rb` or
`config/application.rb` file.

This makes it possible to replace something like:

```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
  <<~HTML.html_safe
    #{html_tag}
    <span class="errors">#{instance.error_message.to_sentence}</span>
  HTML
end
```

With inline calls to Action View helpers like:

```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
  safe_join [ html_tag, tag.span(instance.error_message.to_sentence, class: "errors") ]
end
```

Or with a view partial rendering, like:

```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
  render partial: "application/field_with_errors", locals: { html_tag: html_tag, instance: instance }
end
```

Then, elsewhere in `app/views/application/field_with_errors.html.erb`:

```erb
<%= html_tag %>
<span class="errors"><%= instance.error_message.to_sentence %></span>
```
2021-10-29 10:07:04 -04:00
Sean Doyle 71fb8eb833 button_to: Support `authenticity_token:` option
Match support for passing `authenticity_token:` in `form_with` and
`form_for` calls.

```ruby
button_to "Create", Post.new, authenticity_token: false
  # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button></form>

button_to "Create", Post.new, authenticity_token: true
  # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button><input type="hidden" name="form_token" value="abc123..." autocomplete="off" /></form>

button_to "Create", Post.new, authenticity_token: "secret"
  # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button><input type="hidden" name="form_token" value="secret" autocomplete="off" /></form>
```
2021-10-29 10:02:22 -04:00
Sean Doyle 46175a036a Action View: Support `fields model: [...]`
Support `fields model: [@nested, @model]` the same way as `form_with
model: [@nested, @model]`.

After this change, the `fields` helper matches the precedent established
by [fields_for][], [form_for][], and [form_with][].

[fields_for]: 5e1a039a1d/actionview/lib/action_view/helpers/form_helper.rb (L2235)
[form_with]: 5e1a039a1d/actionview/lib/action_view/helpers/form_helper.rb (L749)
[form_for]: 5e1a039a1d/actionview/lib/action_view/helpers/form_helper.rb (L436)
2021-10-29 10:01:51 -04:00
Sean Doyle 7d2be2e011 Make `button_to` more model-aware
Infer HTTP verb `[method]` from a model or Array with model as the first
argument to `button_to` when combined with a block:

```ruby
button_to(Workshop.find(1)){ "Update" }
  #=> <form method="post" action="/workshops/1" class="button_to">
  #=>   <input type="hidden" name="_method" value="patch" autocomplete="off" />
  #=>   <button type="submit">Update</button>
  #=> </form>

button_to([ Workshop.find(1), Session.find(1) ]) { "Update" }
  #=> <form method="post" action="/workshops/1/sessions/1" class="button_to">
  #=>   <input type="hidden" name="_method" value="patch" autocomplete="off" />
  #=>   <button type="submit">Update</button>
  #=> </form>
```

Prior to this change, the constructed `<form>` was always submitted with
a `[method="post"]` and _always_ omitted the `<input type="hidden"
name="_method" value="...">` field, regardless of the return value of
the "model" argument's `#persisted?` predicate.
2021-10-29 10:01:20 -04:00
Sean Doyle 37081bf507 Introduce `field_name` view helper
The `field_name` helper and corresponding `FormBuilder#field_name`
method provide an Action View-compliant way of overriding a form field
element's `[name]` attribute (similar to `field_id` and
`FormBuilder#field_id` introduced in rails/rails#40127[][]).

```ruby
text_field_tag :post, :title, name: field_name(:post, :title, :subtitle)
  # => <input type="text" name="post[title][subtitle]">

text_field_tag :post, :tag, name: field_name(:post, :tag, multiple: true)
  # => <input type="text" name="post[tag][]">

form_for @post do |f|
  f.field_tag :tag, name: f.field_name(:tag, multiple: true)
  # => <input type="text" name="post[tag][]">
end
```

[rails/rails#40127]: https://github.com/rails/rails/pull/40127
2021-10-29 10:00:15 -04:00
Ryuta Kamizono 394dbac0b3
Merge pull request #43567 from shunichi/date-select-day-format
Add :day_format option to date_select
2021-10-29 16:59:45 +09:00
Jean Boussier 7b5096947e Call Executor#wrap around each test
It's `Rails.application.executor.wrap` that is responsible for
clearing request/job local state such as `CurrentAttributes`.

Instead of including an ad hoc helper to clear `CurrentAttributes` it's
better to run the executor so we properly clear other states as well.

However it means all executor hooks now need to be re-entrant.
2021-10-28 15:18:29 +02:00
Shunichi Ikegami e9fa24fca5 Add :day_format option to date_select
date_select("article", "written_on", day_format: ->(day) { day.ordinalize })

generates day options like

  <option value="1">1st</option>\n<option value="2">2nd</option>...
2021-10-28 13:51:20 +09:00
Rafael Mendonça França fee61e3abc
Merge pull request #43415 from rails/rm-translate-on-controllers
Treat html suffix in controller translation
2021-10-12 14:19:21 -04:00
Rafael Mendonça França 28bc4f87fd
Extract common behavior of html safe translation to a module
This module will be a private module in Active Support, this way
if we need to change the behavior of translate in controllers or
views don't forget to change in the other one.
2021-10-12 18:03:46 +00:00
David Heinemeier Hansson fb1ab3460a
Make Sprockets more optional, offer Propshaft as alternative (#43261)
* Make Sprockets more optional, offer Propshaft as alternative

* Whups, local reference

* No longer used

* Spacing

* Need explicit sprockets-rails inclusion now

* Manually require the sprockets railtie

* Don't need these changes right now

* Kick off another build

* Fix tests

* DRY up test

* Require railtie when using sprockets

* Introduce option to skip asset pipeline

* No longer relevant

* Always have to return

* Gone

* Add helper for skip_sprockets?

* Fix guard statement

* Use latest gems

* Include propshaft

* fix tests for #43261 (#43277)

* help fix tests for #43261

skip_sprockets? should not be called on options

:skip_sprockets is no longer a value in the option hash, so
skip_sprockets? should not be called on it

move --asset-pipeline to shared generator

skip_sprockets? is defined on app_base, and used in the plugin
generator to determine whether to add the engine's assets to the dummy
sprockets manifest, so I believe it makes sense to include in both
generators

Because of this change, I also changed the shared test back to testing
against non-sprockets

add skip_sprockets to Gemfile template vars

Mocking skip_sprockets? in app_base generator

fix more generator tests

* use skip_sprockets? everywhere

* Use latest propshaft

* Update `AssetUrlHelper` docs to list both asset pipeline gems (#43328)

* Update to latest Propshaft

* Bump Propshaft again

* Ask for latest

* Use latest propshaft

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Richard Macklin <1863540+rmacklin@users.noreply.github.com>
2021-10-09 17:03:05 +02:00
Daniel Colson ccb3cb573b
Replace ableist language
The word "Crazy" has long been associated with mental illness. While
there may be other dictionary definitions, it's difficult for some of us
to separate the word from the stigmatization, gaslighting, and bullying
that often comes along with it.

This commit replaces instances of the word with various alternatives. I
find most of these more focused and descriptive than what we had before.
2021-10-05 22:27:09 -04:00
Liuri Loami d3e5833459 Replaces the "hash rocket" operator in favor of the newer Ruby syntax when rendering on render 2021-10-03 23:33:56 -03:00
Jonathan Hefner 03bb5c1dc2
Merge pull request #43323 from muraken-ken/hotfix
Fix wrong API document for form_with helper method [ci-skip]
2021-09-28 10:08:22 -05:00
muraken-ken 0a3b1ebf6a Fix wrong RDoc 2021-09-28 20:33:35 +09:00
Eike S 9b36864595 Improves ActionView FormHelper check_box documentation
The ActionView::Helpers::Tags::CheckBox class accepts the `checked` and `include_hidden` options. The documentation for these options is added to the `check_box` methods in the ActionView::Helpers::FormHelper class where they are exposed.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2021-09-28 10:16:04 +02:00
Rafael França aa449a89df
Merge pull request #43280 from ryanfb/hidden_autocomplete_off
Add autocomplete="off" to all generated hidden fields (fixes #42610)
2021-09-22 18:20:52 -04:00
Rafael Mendonça França 8e86e87219
Merge PR #42234 2021-09-21 18:54:48 -04:00
Ryan Baumann 168170ff14 Add autocomplete="off" to all generated hidden fields (fixes #42610) 2021-09-21 15:57:56 -04:00
Rafael Mendonça França 040e22b104
Fix CHANGELOG [ci skip] 2021-09-20 17:35:12 -04:00
Rafael França 6e2247e976
Merge pull request #43232 from le0pard/fix_use_tag
Support svg unpaired tags in tag helper
2021-09-20 17:34:28 -04:00
Drew Bragg 451c55e312 Add `beginning_of_week` option to `weekday_options_for_select`
Change `begin_on_monday` to `beginning_of_week`

Change `begin_on_monday` to `beginning_of_week`

Better handle ignored day

Remove inaccurate tests

Improve docs and use DAYS_INTO_WEEK to calc rotation

Remove inaccurate docs
2021-09-17 19:39:07 -04:00
Alexey Vasiliev 6b7ff4f933
Support svg unpaired tags in tag helper 2021-09-16 21:50:54 +03:00
Rafael Mendonça França d177551c30
Preparing for 7.0.0.alpha2 release 2021-09-15 18:22:51 -04:00
Rafael Mendonça França 9b7be48212
Preparing for 7.0.0.alpha1 release 2021-09-15 17:55:08 -04:00
Jean Boussier c91c266872 Enable `Style/ExplicitBlockArgument` cop
This reduce the stack size which is beneficial for
exceptions performance.

See: https://gist.github.com/byroot/cb3bcadcc3701c2518d002fb8d3a4e7a

However the cop is unsafe because it might change the block arity,
so it can run into some false positives.
2021-09-05 17:06:19 +02:00
Jean Boussier 4d3a2c09c8
Merge pull request #43106 from flavorjones/flavorjones-activesupport-number-converter-valid-float
Avoid use of exceptions to detect invalid floats
2021-08-26 15:41:10 +02:00
David Heinemeier Hansson 4214a8d229
Document that @rails/ujs is deprecated (#43112)
Recommended replacements: Turbo + Stimulus.
2021-08-26 14:25:30 +02:00
Mike Dalessio 900ce92c9d
Avoid use of exceptions to detect invalid floats
Use Kernel::Float(..., exceptions:false) instead of a rescue block in
ActionView::Helpers::NumberHelper and
ActiveSupport::NumberHelper::NumberConverter to slightly improve
performance.

Also remove documentation that incorrectly states
ActiveSupport::NumberHelper supports the `raise:` option.
2021-08-25 21:44:45 -04:00
Kasper Timm Hansen 94e80269e3
[ci skip] Fully qualify attributes (we're in docs) and move them above the class so it's not confused with the belongs_to's 2021-08-25 16:59:02 +02:00
Kasper Timm Hansen 163466467e
[ci skip] Use more consistent spacing; trim some ending newlines 2021-08-25 16:58:17 +02:00
Kasper Timm Hansen 1ade156d3c
[ci skip] Use more modern tag.x call structure 2021-08-25 16:56:22 +02:00
Kasper Timm Hansen ccad4b0886
[ci skip] Modernize example; make it consistent with the example at the top documentation 2021-08-25 16:55:47 +02:00
Kasper Timm Hansen 6faf60b158
[ci skip] Fix some links that didn't link but now should, you get me? 2021-08-25 16:55:00 +02:00
Kasper Timm Hansen ea5397e708
[ci skip] Use symbols and double quoted strings more consistently in these docs 2021-08-25 16:54:22 +02:00
Kasper Timm Hansen 915b9cdbb7
Clear up `resolve_link_as`
Swaps to case/when to highlight the 3 branches better and uses `presence_in`
to cut down on the else branch noise.

`resolve_link_as` added in: eb90b8bc86
Most recent other commit: 46bfd082b0

Made a decision to tweak this as core, don't send cosmetic PRs.
2021-08-24 22:38:40 +02:00
Nate Berkopec 46bfd082b0
Make preload_link_tag work with images 2021-08-24 13:49:02 -06:00
John Hawthorn 2daef106af
Merge pull request #42945 from jhawthorn/hash_match
Remove details_key-based Template cache
2021-08-23 10:47:58 -07:00
Olivier Lacan 1e9629e8a9 Allow url_for to infer the name of the link from Model#to_s 2021-08-17 12:17:04 -04:00
Koichi ITO 65af100ddd Tweak unreachable assertion tests in the block of `assert_raises`
I found an unexpected use of assertion in the block of `assert_raise`
when I implemented https://github.com/rubocop/rubocop-minitest/pull/137.
It is expected to be asserted after an exception is raised in
`assert_raise` block, but in actually it is not asserted after an
exception is raised. Therefore, this PR removes or updates assertions
that have not been asserted after an exception has raised.

This PR will add `rubocop-minitest` and enable
`Minitest/UnreachableAssertion` cop to able similar auto-detection,
but will remove `rubocop-minitest` from this PR if you don't like it.
2021-08-17 20:33:08 +09:00
Xavier Noria 2306a8e645 Setup the once autoloader on bootstrap 2021-08-17 05:23:51 +02:00
Xavier Noria bbe74a8c97 Delete AS::Dependencies.unhook! 2021-08-17 05:18:22 +02:00
Drew Bragg 592570f1bf Add `weekday_options_for_select` method
Add `weekday_select` method

Create `Tags::WeekdaySelect` class

Add `weekday_select` to `FromBuilder`

Add Documentation

Allow `WeekdaySelect` to use selected option if value is nil

Doc fix

Add tests

Use kwrd args

Update CHANGELOG

Fix `Tags::WeekdaySelect` for updated kwrd args

Update CHANGELOG format

Condense `weekday_options_for_select` method

Update tests for kwargs
2021-08-16 13:04:33 -04:00
Kasper Timm Hansen 0965b67bf7
Merge pull request #42967 from p8/main
Clean up missing dots in changelogs
2021-08-13 02:24:40 +02:00
John Hawthorn bb5208692a Avoid building full path objects when cached 2021-08-09 14:52:11 -07:00
John Hawthorn 4db7ae52f8 Remove cache from Template::Resolver 2021-08-09 14:52:11 -07:00
John Hawthorn 76561430e5 Normalize locals in unbound templates 2021-08-09 12:56:57 -07:00
John Hawthorn da81403665 Use TemplateDetails::Requested as details_key 2021-08-09 12:56:57 -07:00
John Hawthorn 6b49f33054
Merge pull request #42969 from Matt-Yorkley/tracker-tests
Create shared examples for dependency tracker tests
2021-08-08 12:36:01 -07:00
Matt-Yorkley 73b3772e49 Move dependency tracker tests shared examples
The bulk of these tests should be run using both the ERBTracker and the RipperTracker until ERBTracker is eventually removed.
2021-08-08 15:01:15 +01:00
Petrik de Heus 6828334555
Add missing dots to changelogs 2021-08-07 18:53:10 +02:00
Ryuta Kamizono c3518b4a9c Fix markup in RDoc [ci skip] 2021-08-07 17:52:33 +09:00
Rafael Mendonça França d4d14a34a1
Remove duplicated test
We have a test with the same name in this file, so this test doesn't
run.
2021-08-05 11:02:09 -04:00
Carlos Antonio da Silva 65bbfa9519 Fix typo in Action View changelog [ci skip] 2021-08-05 11:03:08 -03:00
HParker 41c0681fb7 Default to ERB Tracker
This leaves Ripper tracker as an optional view dependency tracker, but uses the current ERBTracker by default.

Eventually the default can change to the Ripper tracker, but this makes it an optional update for now
2021-08-04 15:34:07 -07:00
John Hawthorn c44d702a08
Merge pull request #42458 from HParker/use-ripper-dependency-tracker
Replace dependency tracker with ripper based tracker
2021-08-04 11:10:13 -07:00
Joel Hawksley fd5792f0fc
Add caching? helper method
Caching something that shouldn't be cached is a potential source of
bugs and security vulnerabilities. For example, one could write a
form helper that outputs a request-specific auth token, only for
the helper to be used inside of a `cache` block.

In the GitHub application, we implemented a caching? method and used
it to raise an error if a specific code path is being cached that
we don't want to be cached.

I've credited its original author, @btoews.

Co-authored-by: Ben Toews <mastahyeti@gmail.com>
Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2021-08-03 15:49:48 -06:00
Rafael Mendonça França 18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
Rafael Mendonça França 6741222f65
Merge pull request #41728 2021-07-29 01:11:59 +00:00
Xander d9fda55594
Update resolve_link_as to include SVG (#42892)
* Update resolve_link_as to include SVG

Preloading SVGs won't work without 'as: image' because of:

`Preload of /packs/media/images/81d035675e31079ea9da.svg was ignored due to unknown “as” or “type” values, or non-matching “media” attribute.`

Preloading SVGs can be useful, for instance when using sprites such as bootstrap-icons.

* Adds test case for asset_tag_helper

* Fix test case -- silly mistake

[xanderificnl + Rafael Mendonça França]
2021-07-28 16:26:55 -04:00
Jonathan Hefner 11c2c0ef2f Fix incomplete :nodoc: directives [ci-skip] 2021-07-28 10:30:06 -05:00
Jonathan Hefner 8ace007519 Fix current_page? when URL has trailing slash
This fixes the `current_page?` helper when the given URL has a trailing
slash, and is an absolute URL or also has query params.

Fixes #33956.

Co-authored-by: Rien Maertens <rien.maertens@posteo.be>
2021-07-23 17:03:45 -05:00
Ryuta Kamizono e50b0e3ab3 Fixup CHANGELOGs [ci skip] 2021-07-21 10:08:08 +09:00