aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-134-5/+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.
* Remove useless find_partial methodst00122019-05-071-5/+1
|
* Merge pull request #35337 from ↵Rafael França2019-05-013-8/+7
|\ | | | | | | | | abhaynikam/35265-remove-unused-argument-layout-from-rendered-template Removed unused layout attribute from RenderedTemplate
| * Removed unused layout attribute from RenderedTemplateAbhay Nikam2019-03-093-8/+7
| |
* | Merge pull request #35145 from st0012/fix-35114Rafael França2019-04-031-13/+20
|\ \ | | | | | | Fix partial caching ignore repeated items issue
| * | Fix partial caching ignore repeated items issuest00122019-04-041-13/+20
| | | | | | | | | | | | | | | | | | This is because we only use hash to maintain the result. So when the key are the same, the result would be skipped. The solution is to maintain an array for tracking every item's position to restructure the result.
* | | Merge pull request #35825 from jhawthorn/always_filter_view_pathsEileen M. Uchitelle2019-04-031-1/+1
|\ \ \ | |/ / |/| | Make Resolver#find_all_anywhere equivalent to #find_all
| * | Always reject files external to appJohn Hawthorn2019-04-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Rename File to RawFileCliff Pruitt2019-04-011-1/+1
|/ /
* | Merge pull request #35793 from jhawthorn/deprecate_layout_absolute_pathKasper Timm Hansen2019-03-311-0/+1
|\ \ | | | | | | Deprecate render layout with an absolute path
| * | Deprecate render layout with an absolute pathJohn Hawthorn2019-03-291-0/+1
| | | | | | | | | | | | | | | | | | | | | This has similar problems to render file:. I've never seen this used, and believe it's a relic from when all templates could be rendered from an absolute path.
* | | Merge pull request #35688 from jhawthorn/render_file_rfcAaron Patterson2019-03-301-1/+6
|\ \ \ | |/ / |/| | RFC: Introduce Template::File
| * | Introduce Template::File as new render file:John Hawthorn2019-03-271-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous behaviour of render file: was essentially the same as render template:, except that templates can be specified as an absolute path on the filesystem. This makes sense for historic reasons, but now render file: is almost exclusively used to render raw files (not .erb) like public/404.html. In addition to complicating the code in template/resolver.rb, I think the current behaviour is surprising to developers. This commit deprecates the existing "lookup a template from anywhere" behaviour and replaces it with "render this file exactly as it is on disk". Handlers will no longer be used (it will render the same as if the :raw handler was used), but formats (.html, .xml, etc) will still be detected (and will default to :plain). The existing render file: behaviour was the path through which Rails apps were vulnerable in the recent CVE-2019-5418. Although the vulnerability has been patched in a fully backwards-compatible way, I think it's a strong hint that we should drop the existing previously-vulnerable behaviour if it isn't a benefit to developers.
* | | Fix annotated typoPrathamesh Sonpatki2019-03-291-1/+1
|/ /
* / Aligned the order of the arguments of render_template and render_with_layoutShigeyuki-fukuda2019-03-271-2/+2
|/
* Templates have one formatAaron Patterson2019-02-252-2/+2
| | | | | | | Templates only have one format. Before this commit, templates would be constructed with a single element array that contained the format. This commit eliminates the single element array and just implements a `format` method. This saves one array allocation per template.
* Add a finalizer to inline templatesAaron Patterson2019-02-221-1/+1
| | | | | | | | | | | | | | | | | | | This commit adds a finalizer just to inline templates. We can't cache compilation of inline templates because it's possible that people could have render calls that look like this: ```ruby loop do render inline: "#{rand}" end ``` and we would cache every one of these different inline templates. That would cause a memory leak. OTOH, we don't need finalizers on regular templates because we can cache, control, and detect changes to the template source. Fixes: #35372
* Merge pull request #35371 from rails/always-have-a-formatAaron Patterson2019-02-223-5/+17
|\ | | | | Ensure that rendered templates always have a format
| * Ensure that rendered templates always have a formatAaron Patterson2019-02-223-5/+17
| | | | | | | | | | This removes one call to `lookup_context` and also eliminates a conditional in `_render_template`.
* | Pass lookup context to the layout handlersAaron Patterson2019-02-221-1/+1
|/ | | | | | | I want to start reducing the calls to `lookup_context`. That method caches the lookup context in an ivar, but I would like to cache the lookup context on the stack. That way we aren't coupled to the behavior of the `lookup_context` method.
* Fix up styleAaron Patterson2019-02-194-8/+8
|
* Return rendered template information instead of just stringsAaron Patterson2019-02-196-29/+85
| | | | | | | | | | | | This commit introduces "rendered template" and "rendered collection" objects. The template renderers can now return a more complex object than just strings. This allows the framework to get more information about the templates that were rendered. In this commit we use the rendered template object to set the "rendered_format" on the lookup context in the controller rather than all the way in the template renderer. That means we don't need to check the "rendered_format" every time we render a template, we just do it once after all templates have been rendered.
* Pass the template format to the digestorAaron Patterson2019-02-151-1/+1
| | | | | | | | | | | | | | | This commit passes the template format to the digestor in order to come up with a key. Before this commit, the digestor would depend on the side effect of the template renderer setting the rendered_format on the lookup context. I would like to remove that mutation, so I've changed this to pass the template format in to the digestor. I've introduced a new instance variable that will be alive during a template render. When the template is being rendered, it pushes the current template on to a stack, setting `@current_template` to the template currently being rendered. When the cache helper asks the digestor for a key, it uses the format of the template currently on the stack.
* Merge pull request #35253 from rails/cached-collections-must-have-a-templateAaron Patterson2019-02-131-3/+11
|\ | | | | Cached collections only work if there is one template
| * Cached collections only work if there is one templateAaron Patterson2019-02-131-3/+11
| | | | | | | | | | Cached collections only work if there is one template. If there are more than one templates, the caching mechanism doesn't have a key.
* | Turn lookup context in to a stack, push and pop if formats changeAaron Patterson2019-02-111-2/+0
|/ | | | | | | | | | | This commit keeps a stack of lookup contexts on the ActionView::Base instance. If a format is passed to render, we instantiate a new lookup context and push it on the stack, that way any child calls to "render" will use the same format information as the parent. This also isolates "sibling" calls to render (multiple calls to render in the same template). Fixes #35222 #34138
* Speed up partial rendering by caching "variable" calculationAaron Patterson2019-02-051-18/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit speeds up rendering partials by caching the variable name calculation on the template. The variable name is based on the "virtual path" used for looking up the template. The same virtual path information lives on the template, so we can just ask the cached template object for the variable. This benchmark takes a couple files, so I'll cat them below: ``` [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat render_benchmark.rb require "benchmark/ips" require "action_view" require "action_pack" require "action_controller" class TestController < ActionController::Base end TestController.view_paths = [File.expand_path("test/benchmarks")] controller_view = TestController.new.view_context result = Benchmark.ips do |x| x.report("render") do controller_view.render("many_partials") end end [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat test/benchmarks/test/_many_partials.html.erb Looping: <ul> <% 100.times do |i| %> <%= render partial: "list_item", locals: { i: i } %> <% end %> </ul> [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat test/benchmarks/test/_list_item.html.erb <li>Number: <%= i %></li> ``` Benchmark results (master): ``` [aaron@TC ~/g/r/actionview (master)]$ be ruby render_benchmark.rb Warming up -------------------------------------- render 41.000 i/100ms Calculating ------------------------------------- render 424.269 (± 3.5%) i/s - 2.132k in 5.031455s ``` Benchmark results (this branch): ``` [aaron@TC ~/g/r/actionview (speed-up-partials)]$ be ruby render_benchmark.rb Warming up -------------------------------------- render 50.000 i/100ms Calculating ------------------------------------- render 521.862 (± 3.8%) i/s - 2.650k in 5.085885s ```
* Remove `with_layout_format` delegationAaron Patterson2019-01-281-1/+1
| | | | | That method doesn't exist on LookupContext, so the delegate doesn't make sense.
* Cache the digest path on the stack.Aaron Patterson2019-01-281-7/+5
| | | | We can remove the ivar by caching the digest on the stack
* Pull `@template` in to a local variableAaron Patterson2019-01-283-25/+24
| | | | | | This gets the PartialRenderer to be a bit closer to the TemplateRenderer. TemplateRenderer already keeps its template in a local variable.
* Remove default parameters from method signatureAaron Patterson2019-01-281-4/+2
| | | | This method is private, and we always pass something in.
* Remove `@view` instance variable from the partial rendererAaron Patterson2019-01-282-25/+24
| | | | Similar to 1853b0d0abf87dfdd4c3a277c3badb17ca19652e
* Remove `find_template` and `find_file` delegate methodsAaron Patterson2019-01-281-1/+1
| | | | | | | | | | This reduces the surface area of our API and removes a Liskov issue. Both TemplateRenderer and PartialRenderer inherit from AbstractRenderer, but since PartialRenderer implements it's own `find_template` that is private, and has the wrong method signature, an instance of PartialRenderer cannot be substituted for an instance of AbstractRenderer renderer. Removing the superclass implementation solves both issues.
* Deprecate `with_fallbacks` using a blockAaron Patterson2019-01-281-4/+4
| | | | | | | This patch changes `with_fallbacks` to be a factory method that returns a new instance of a lookup context which contains the fallback view paths in addition to the controller specific view paths. Since the lookup context is more "read only", we may be able to cache them
* Revert "Allow usage of strings as locals for partial renderer"Ufuk Kayserilioglu2019-01-241-1/+1
|
* Pass the view around instead of using an ivarAaron Patterson2019-01-232-9/+7
| | | | | If we pass the view instance around it's easier to understand the flow control.
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | 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 ```
* [ci skip] document collection_caching.rbschneems2018-09-191-0/+35
|
* Move digest path calculation out of loopschneems2018-09-111-1/+5
| | | | | | | | | | | On every iteration of generating a cache for a collection a “digest path” is calculated even though it’s exactly the same for every element. This PR exposes a method `digest_path_from_virtual` that returns back a “digest_path”. This can in turn be passed back into `cache_fragment_name`. This not only does less work, but it also (you guessed it) uses less memory. before: Total allocated: 762539 bytes (7035 objects) after: Total allocated: 743590 bytes (6621 objects) (762539 - 743590)/ 762539.0 # => 2.4% faster ⚡️⚡️
* Merge pull request #30647 from droptheplot/render-partials-string-localsRafael França2018-04-271-1/+1
|\ | | | | Allow usage of strings as locals for partial renderer
| * Allow usage of strings as locals for partial rendererSergey Novikov2017-09-181-1/+1
| |
* | fix(streaming_template_renderer): I18n.locale broken in layout. I18n gem ↵mfo2017-11-251-0/+2
| | | | | | | | stores the current locale in Thread.current[:local] (see: https://github.com/svenfuchs/i18n/blob/master/lib/i18n.rb#L23). StreamingTemplateRenderer is implemented with Fiber which have its own stack of locals and can not access Thread.current.locals(keys, see: https://ruby-doc.org/core-2.2.0/Thread.html#class-Thread-label-Fiber-local+vs.+Thread-local).
* | [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-10/+10
|
* Fix RDoc formatting: `+` doesn't work with `@`ohbarye2017-08-111-1/+1
| | | | | | | | | | | | | | refs: https://github.com/rails/rails/pull/30161 ``` $ echo "+@size+" | rdoc --pipe <p>+@size+</p> $ echo "<tt>@size</tt>" | rdoc --pipe <p><code>@size</code></p> ``` [ci skip]
* Use frozen string literal in actionview/Kir Shatrov2017-07-246-0/+11
|
* Make actionview ready for frozen stringsKir Shatrov2017-07-231-1/+2
|
* [Action View] require => require_relativeAkira Matsuda2017-07-011-1/+1
|
* Merge pull request https://github.com/rails/rails/pull/28637 from ↵Kasper Timm Hansen2017-06-082-1/+5
| | | | st0012/fix-partial-cache-logging