aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/resolver.rb
Commit message (Collapse)AuthorAgeFilesLines
* :golf:Akira Matsuda2019-06-151-6/+2
|
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-4/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Avoid duplication using _find_allJohn Hawthorn2019-04-121-11/+7
|
* Support disabling cache for DigestorJohn Hawthorn2019-04-121-20/+35
| | | | | | This adds a bit of complexity, but is necessary for now to avoid holding extra copies of templates which are resolved from ActionView::Digestor after disabling cache on the lookup context.
* De-dup Templates, introduce UnboundTemplateJohn Hawthorn2019-04-121-10/+19
| | | | | | | | | | | | | | | | | | | | | | Previously it's possible to have multiple copies of the "same" Template. For example, if index.html.erb is found both the :en and :fr locale, it will return a different Template object for each. The same can happen with formats, variants, and handlers. This commit de-duplicates templates, there will now only be one template per file/virtual_path/locals tuple. We need to consider virtual_path because both `render "index"`, and `render "index.html"` can both find the same file but will have different virtual_paths. IMO this is rare and should be deprecated/removed, but it exists now so we need to consider it in order to cache correctly. This commit introduces a new UnboundTemplate class, which represents a template with unknown locals. Template objects can be built from it by using `#with_locals`. Currently, this is just a convenience around caching templates, but I hope it's a helpful concept that could have more utility in the future.
* Remove FileTemplateJohn Hawthorn2019-04-041-1/+3
| | | | This is unnecessary now that we can just provide a file source
* Always reject files external to appJohn Hawthorn2019-04-031-14/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, when using `render file:`, it was possible to render files not only at an absolute path or relative to the current directory, but relative to ANY view paths. This was probably done for absolutely maximum compatibility when addressing CVE-2016-0752, but I think is unlikely to be used in practice. Tihs commit removes the ability to `render file:` with a path relative to a non-fallback view path. Make FallbackResolver.new private To ensure nobody is making FallbackResolvers other than "/" and "". Make reject_files_external_... no-op for fallbacks Because there are only two values used for path: "" and "/", and File.join("", "") == File.join("/", "") == "/", this method was only testing that the absolute paths started at "/" (which of course all do). This commit doesn't change any behaviour, but it makes it explicit that the FallbackFileSystemResolver works this way. Remove outside_app_allowed argument Deprecate find_all_anywhere This is now equivalent to find_all Remove outside_app argument Deprecate find_file for find Both LookupContext#find_file and PathSet#find_file are now equivalent to their respective #find methods.
* Only clear template caches in dev after changes (#35629)John Hawthorn2019-04-011-0/+2
|
* Deprecate custom patterns for PathResolverJohn Hawthorn2019-03-261-39/+11
| | | | | | | | | | | | | Custom glob patterns tie the implementation (Using Dir.glob) to the API we provide. It also doesn't really work. extract_handler_and_format_and_variant expects the handler, format, and variant to be at the end of the template path, and in the same order as they are in the default pattern. This deprecates specifying a custom path for FileSystemResolver and removes the pattern argument of OptimizedFileSystemResolver#initialize, which does not work with a custom pattern.
* Remove virtual_path from fallback templatesJohn Hawthorn2019-03-181-8/+16
|
* Remove updated_at from TemplatesJohn Hawthorn2019-03-151-7/+1
|
* Make Template::Resolver always cacheJohn Hawthorn2019-03-151-30/+2
| | | | | | | | | | | | All actionview caches are already cleared at the start of each request (when Resolver.caching is false) by PerExecutionDigestCacheExpiry, which calls LookupContext::DetailsKey.clear (which clears all caches). Because caches are always cleared per-request in dev, we shouldn't need this extra logic to compare mtimes and conditionally reload templates. This should make templates slightly faster in development (particularly multiple renders of the same template)
* Remove query_format argument from resolverJohn Hawthorn2019-02-261-2/+2
|
* Create templates with format=nilJohn Hawthorn2019-02-261-2/+2
|
* Remove unused method / fix documentationAaron Patterson2019-02-261-6/+1
|
* Update actionview/lib/action_view/template/resolver.rbJohn Hawthorn2019-02-261-1/+1
| | | Co-Authored-By: tenderlove <tenderlove@github.com>
* Don't mutate `virtual_path`, remove `decorate`Aaron Patterson2019-02-251-14/+2
| | | | | | `virtual_path` is calculated in the constructor when the Template object is allocated. We don't actually need to set it in the `decorate` method. That means we can remove the decorate method all together.
* Pass locals in to the template object on constructionAaron Patterson2019-02-251-8/+11
| | | | | | | This commit ensures that locals are passed in to the template objects when they are constructed, then removes the `locals=` mutator on the template object. This means we don't need to mutate Template objects with locals in the `decorate` method.
* Remove potential `variants` mutation in `decorate`Aaron Patterson2019-02-251-1/+0
| | | | | | | | | | Even if the template is constructed with a `nil` variant, the array it constructs will never be `empty?`: https://github.com/rails/rails/blob/56b030605b4d968077a4ddb96b4ab619e75fb999/actionview/lib/action_view/template.rb#L152 We get an array that is `[nil]`, which is not empty, so this conditional is never true.
* Dereference the format type before template constructionAaron Patterson2019-02-251-1/+1
| | | | | The format should always be exactly one symbol. Now we don't need to check whether or not the format is a `Type` in the constructor.
* Always pass a format to the ActionView::Template constructorAaron Patterson2019-02-251-5/+13
| | | | | This means we can eliminate nil checks and remove some mutations from the `decorate` method.
* Introduce a file type template, deprecate `Template#refresh`Aaron Patterson2019-02-011-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Every template that specifies a "virtual path" loses the template source when the template gets compiled: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template.rb#L275 The "refresh" method seems to think that the source code for a template can be recovered if there is a virtual path: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template.rb#L171-L188 Every call site that allocates a template object *and* provides a "virtual path" reads the template contents from the filesystem: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template/resolver.rb#L229-L231 Templates that are inline or literals don't provide a "virtual path": https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/renderer/template_renderer.rb#L34 This commit introduces a `FileTemplate` type that subclasses `Template`. The `FileTemplate` keeps a reference to the filename, and reads the source from the filesystem. This effectively makes the template source immutable. Other classes depended on the source to be mutated while being compiled, so this commit also introduces a temporary way to pass the mutated source to the ERB (or whatever) compiler. See `LegacyTemplate`. I think we should consider it an error to provide a virtual path on a non file type template an non-file templates can't recover their source. Here is an example: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/testing/resolvers.rb#L53 This provides a "virtual path" so the source code (a string literal) is thrown away after compilation. Clearly we can't recover that string, so I think this should be an error.
* use match?pavel2018-12-121-1/+1
|
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-2/+2
| | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Fix for variants: :any special caseJohn Hawthorn2018-09-121-1/+3
|
* Use wildcard glob for optimized template resolvingJohn Hawthorn2018-09-121-13/+51
|
* [Action View] require_relative => requireAkira Matsuda2017-10-211-1/+1
| | | | This basically reverts c4d1a4efeec6f0b5b58222993aa0bec85a19b6a8
* Use tt in doc for ActionView [ci skip]Yoshiyuki Hirano2017-08-271-3/+3
|
* Use frozen string literal in actionview/Kir Shatrov2017-07-241-0/+2
|
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-1/+1
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| | |
| * | Make ActionMailer frozen string literal friendly.Pat Allan2017-06-201-1/+1
| |/
* / [Action View] require => require_relativeAkira Matsuda2017-07-011-1/+1
|/
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-2/+1
|
* Merge pull request #27738 from kenta-s/remove-unused-argument-formatsRafael França2017-01-311-2/+2
|\ | | | | Remove unused argument `formats`
| * Remove unused argument `formats`kenta-s2017-01-201-2/+2
| |
* | `find_templates` should be able to handle 5 argumentskenta-s2017-01-191-2/+2
|/
* No need to nodoc private methodsAkira Matsuda2016-12-241-2/+2
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-5/+5
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-5/+5
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-4/+4
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-74/+74
|
* modernizes hash syntax in actionviewXavier Noria2016-08-061-6/+6
|
* applies new string literal convention in actionview/libXavier Noria2016-08-061-3/+3
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* keep layouts + locals from bloating the cacheAaron Patterson2016-05-171-0/+17
| | | | | | Using locals will cause layouts to be cached multiple times in the template cache. This commit removes locals from consideration when looking up the layout.
* Ensure Cache#inspect doesn't block concurrent cache writesJeremy Daer2016-04-191-0/+4
| | | | | | | Object#inspect recursively inspects instance variables, exposing all internal state, including sensitive internal cache objects. Override Cache#inspect to give a high-level summary that never interferes with concurrent cache writes.
* Support `:any` variants lookup in `PathResolver`Godfrey Chan2016-03-011-2/+6
| | | | | | | | `OptimizedFileSystemResolver` (which most Rails apps use), but did not implement the feature on the more generic `PathResolver`, which is often used in tests etc. Fixes #23881