Commit Graph

2310 Commits

Author SHA1 Message Date
Rafael Mendonça França
855cb4bef2
Call method outside the loop
We only need to call this method once.
2019-12-27 15:13:44 -03:00
Ben Ubois
2bb7dbf75d Improve escape_javascript performance. 2019-12-22 23:52:37 +01:00
Kasper Timm Hansen
6047301063
Merge pull request #38059 from eugeneius/source_extract_encode_template
Encode template source before extracting lines
2019-12-22 08:56:29 +01:00
John Hawthorn
5579871687 Use ActionDispatch mimes in asset_tag_helper_test
We need a more complete understanding of mime types for the asset tags
to render properly, so we need to load this rather than just the stubs
included by actionview by default.

This fixes running these tests in isolation.
2019-12-21 03:38:39 -08:00
Eugene Kenny
d7b015a167 Encode template source before extracting lines
Before 2169bd3d2a9d2f331a5dd6e41d9d638e0da6117c, a template's source was
encoded in place when it was compiled, and the `source_extract` method
could rely on `Template#source` to return a properly encoded string.

Now that `Template#source` always returns a new copy of the template
source with no encoding, `source_extract` should call `encode!` itself.
2019-12-21 07:30:52 +00:00
Ryuta Kamizono
b3da023081 Add ruby2_keywords for delegating to fields helper 2019-12-21 02:44:26 +09:00
Rafael França
e36d4a0381
Merge pull request #38026 from Edouard-chin/ec-av-base-loadorder
Don't require "action_view/base" in action pack:
2019-12-19 13:40:56 -03:00
Edouard CHIN
88ee52f9d9 Don't require "action_view/base" in action pack:
- ### Problem

  ActionPack requires "action_view/base" at boot time, this
  causes a variety of issue that I described in detail in #38024.

  There is no real reason to require av/base in the
  ActionDispatch::Debugexceptions class.

  ### Solution

  Like any other components (such as ActiveRecord, ActiveJob...),
  ActionView::Base shouldn't be loaded at boot time.

  Here are the two main changes needed for this:

  1) Actionview has a special initializer that needs to run
     before the app is fully booted (adding a executor needs to be done
     before application is done booting)
  63ec70e700/actionview/lib/action_view/railtie.rb (L81-L84)

     That initializer used a lazy load hooks but we can't do that anymore
     because Action::Base view won't be triggered during booting process.
     When it will get triggered, (presumably on the first request),
     it's too late to add an executor.

  ------------------------------------------------

  2) Compare to other components, ActionView doesn't use `Base` for
     configuration flag. A lot of flags ares instead set on modules
     (FormHelper, FormTagHelper).
     The problem is that those module depends on AV::Base to be
     loaded, as otherwise configuration set by the user aren't applied.
     (Since the lazy load hooks hasn't been triggered)
     63ec70e700/actionview/lib/action_view/railtie.rb (L66-L69)

     We shouldn't wait for AB::Base to be loaded in order to set these
     configuration. However, we need to do it inside an
     `after_initialize` block in order to let application
     set it to the value they want.

  Closes #28538

  Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-19 17:28:24 +01:00
Rafael França
8619a76be8
Merge pull request #28902 from voxik/fix-inspect
Prevent negative IDs in output of #inspect.
2019-12-19 13:20:45 -03:00
Rafael França
afdee462a8
Merge pull request #36147 from pustomytnyk/patch-1
Fix handling of undefined year in DateTimeSelector
2019-12-18 12:24:16 -03:00
Rafael Mendonça França
7c1bf1a474
Merge pull request #25214 from maclover7/jm-av-tests
Cleanup Action View `abstract_unit`
2019-12-18 12:23:11 -03:00
Roman Sokhan
8251651a0d Fix handling of undefined year in DateTimeSelector 2019-12-18 16:56:09 +02:00
Rafael França
f741f56da3
Merge pull request #37865 from hectorbus/number-to-currency-negative-zero-fix
number_to_currency negative zero fix
2019-12-17 12:30:57 -03:00
Ryuta Kamizono
0c2bb3485c
Merge pull request #37995 from abhaynikam/37918-fix-typo-in-class_names-helper-documentation
Fixed typo in the class_names helper documentation
2019-12-17 15:04:50 +09:00
Eugene Kenny
ee525ff663 Load framework test files in deterministic order
`Dir.glob` doesn't guarantee the order of its results:

https://ruby-doc.org/core-2.6.5/Dir.html#method-c-glob

> Case sensitivity depends on your system (File::FNM_CASEFOLD is
> ignored), as does the order in which the results are returned.

Minitest stores a list of all test cases in the order that they were
defined; it shuffles them before they're run, but doesn't sort them:

https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L1048
https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L156

This means that the order in which framework tests run is platform
dependent, and running a test command that failed in CI locally won't
necessarily reproduce the error, even when the same seed is provided.

`Rake::FileList` resolves glob patterns to a sorted list of files:

https://github.com/ruby/rake/blob/v13.0.1/lib/rake/file_list.rb#L408

By using `Rake::FileList` instead of `Dir.glob`, framework tests will
always run in the same order when given the same seed, and reproducing
order dependent CI failures will be easier.
2019-12-16 16:55:06 +00:00
Abhay Nikam
2cd84ad745 Fixed typo in the class_names helper documentation and added a spec covering the scenario 2019-12-16 13:48:19 +05:30
Kasper Timm Hansen
2bcf24795b
Merge pull request #37928 from CGA1123/fix-race-in-action-view
Make ActionView::LookupContext::DetailsKey thread-safe
2019-12-12 22:47:30 +01:00
Joel Hawksley
e1545682eb
Add changelog entry for https://github.com/rails/rails/pull/37918
Per request from @bogdanvlviv.
2019-12-11 09:20:38 -07:00
Eileen M. Uchitelle
774e77c2cc
Merge pull request #37918 from joelhawksley/class_names_helper
Introduce class_names helper
2019-12-10 09:27:37 -05:00
Eileen M. Uchitelle
e36097a950
Merge pull request #37919 from joelhawksley/controller-render-in
Render objects that respond_to render_in in controllers
2019-12-10 09:18:26 -05:00
Joel Hawksley
20a83f52d7
Render objects that respond_to render_in in controllers
In https://github.com/rails/rails/pull/36388,
we supported passing objects that `respond_to` `render_in`
to `render`, but _only_ in views.

This change does the same for controllers, as Rails
generally gives the expectation that `render` behaves
the same in both contexts.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2019-12-09 16:43:18 -07:00
Joel Hawksley
f24734a7e1
Introduce class_names helper
As a follow-up to https://github.com/rails/rails/pull/37872,
this change introduces a class_names view helper
to make it easier to conditionally apply class names
in views.

Before:
<div class="<%= item.for_sale? ? 'active' : '' %>">

After:
<div class="<%= class_names(active: item.for_sale?) %>">

We've been using this helper in the GitHub monolith
since 2016.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2019-12-09 16:41:18 -07:00
Edouard CHIN
95bc8d0a23 Fix input value not properly applied:
- #37872 introduced a regression and you can't do

  ```html.erb
    hidden_field_tag('token', value: [1, 2, 3])
  ```

  This will result in a `<input type="hidden" value=""`>.

  I chose `hidden_field_tag` and the `value` attribute as an example
  but this issue applies to any tag helper and any attributes.

  https://github.com/rails/rails/pull/37872#issuecomment-561806468
  mention that the feature should only apply for "class" attribute.

  This commit fix original intent of #37872
2019-12-09 22:54:25 +01:00
Rafael Mendonça França
e67fdc5aeb
Revert "Merge pull request #37504 from utilum/no_implicit_conversion_of_nil"
This reverts commit 4e105385d046e2aeab16955943df97c5eefa3a6f, reversing
changes made to 62b43839098bbbbfc4be789128d33dc0612f1ab3.

The change in Ruby that made those changes required was reverted in
8852fa8760
2019-12-09 11:50:39 -03:00
Santiago Bartesaghi
8872ec431a
perform_caching config affects collection caching 2019-12-05 21:46:02 +01:00
Joel Hawksley
54f418d96d
appease rubocop 2019-12-03 11:45:51 -07:00
Joel Hawksley
f508d4da4d
Merge branch 'master' into content-tag-hash-class-conditional 2019-12-03 11:32:58 -07:00
Joel Hawksley
f1c63d8673
Add support for conditional values to TagBuilder
Adds support for conditional values to TagBuilder,
extracting logic we use in the GitHub application,
inspired by https://github.com/JedWatson/classnames.

It’s common practice to conditionally apply CSS classes
in Rails views. This can lead to messy string interpolation,
often using ternaries:

```ruby
content_tag(
  "My username",
  class: "always #{'sometimes' if current_user.special?} another"
)
```

By adding support for hashes to TagBuilder, we can instead write the following:

```ruby
content_tag(
  "My username",
  class: ["always", "another", { 'sometimes' => current_user.special? }]
)
```

cc @JedWatson
2019-12-03 11:30:38 -07:00
Hector Bustillos
92fea7a574 number_to_currency negative zero fix 2019-12-02 23:18:26 -07:00
Michael MacDonald
2863619b94
Fix minor typo in pattern example for number_to_phone [ci skip]
There is an extra closing parenthesis on the last example for `number_to_phone` which causes it to be invalid
2019-11-28 22:08:39 +11:00
Ryuta Kamizono
d558febe32 Auto-correct rubocop offences 2019-11-24 09:54:47 +09:00
Ryuta Kamizono
214f439343 Fixup CHANGELOGs [ci skip] 2019-11-24 09:20:00 +09:00
BelenRemedi
4bf9e49ec4 show consitency in cache key and avoid getting into implementation details 2019-11-22 10:12:00 -03:00
Tatsuya Hoshino
41f0fb8c6e Remove needless require "pp"
In Ruby 2.5 and later, `Kernel#pp` is automatically loaded.

https://bugs.ruby-lang.org/issues/14123

This changes remove the needless `require "pp"`.
2019-11-06 22:50:53 +09:00
Artin Boghosian
ec737fb846
Use singular, instance, in deprecation warning. 2019-11-04 13:45:46 -08:00
Rafael Mendonça França
86dd7d1621
No need to break the line 2019-11-04 15:24:40 -05:00
utilum
2ca6830831 TypeError Regexp#match?(nil) in Ruby Head
Aa of ruby/ruby@2a22a6b2d8 calling
`Regexp#match?(nil)` raises an exception.

[utilum, eregon, eugeneius]
2019-11-03 09:26:46 +02:00
Kasper Timm Hansen
d2e8b839d2
Merge pull request #37561 from SinanMujan/fix_docs_actionview
[ci skip] Small fixes in ActionView documentation.
2019-10-27 08:31:23 -05:00
John Hawthorn
82f9d7c8b6
Merge pull request #37445 from jhawthorn/optimize_content_tag
Make content_tag a bit faster
2019-10-25 13:13:03 -07:00
sinanmujan
f66946b11a [ci skip] Small fixes in ActionView documentation. 2019-10-25 09:02:26 +02:00
Orien Madgwick
493edf044f Add bug tracker/documentation/mailing list URIs to the gemspecs 2019-10-11 20:47:19 -04:00
John Hawthorn
25ed6627dd Convert two hash lookups into one 2019-10-11 13:52:51 -07:00
John Hawthorn
a2720dd053 Avoid extra allocations when don't need escaping 2019-10-11 13:35:11 -07:00
Takayuki Nakata
4871f1f8d1 Remove unused requires
`remove_method` were removed at 661fd98aad and 737b718ea0
2019-10-07 10:03:46 +09:00
Kasper Timm Hansen
eca6c273fe
[ci skip] switch eg. to proper e.g. 2019-10-07 02:18:36 +02:00
Xavier Noria
9f2c74eda0
Merge pull request #37350 from xuanxu/https
Update URLs in docs [ci skip]
2019-10-03 11:09:45 +02:00
Juanjo Bazán
b24190807d update https urls [ci skip] 2019-10-03 11:01:32 +02:00
Juanjo Bazán
e4b5a3eb77 update package.json files to use https homepage value 2019-10-02 12:00:11 +02:00
George Claghorn
8f37e2555a Avoid Element.closest() for IE 9 compatibility
Fixes #37234.
2019-09-29 09:07:11 -04:00
Akira Matsuda
d1d1a2dee7 template_exists? takes keyword arguments 2019-09-24 13:48:14 +09:00