aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/renderer
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Use a hash to record every partial's cache hit status instead of sharing a ↵Stan Lo2017-06-081-1/+1
| | | | boolean.
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-1/+1
|
* Use recyclable cache keys (#29092)David Heinemeier Hansson2017-05-181-1/+1
|
* Add partial iteration variable to template keysMatthew Eagar2017-01-251-1/+1
| | | | | | | When rendering heterogeneous collection using `render @collection` or `render partial: @collection`, the expected `<partial_name>_iteration` variable is missing due to `find_template` not having the name of the iteration variable included in its cache keys.
* Remove TODOs related to Exceptron [ci skip]kenta-s2017-01-181-2/+0
|
* Fix grammar in partial_renderer.rb [ci skip]kenta-s2017-01-181-1/+1
|
* Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-3/+3
| | | | (I personally prefer writing one string in one line no matter how long it is, though)
* Privatize unneededly protected methods in Action ViewAkira Matsuda2016-12-241-4/+4
|
* No need to nodoc private methodsAkira Matsuda2016-12-242-3/+3
|
* Merge pull request #26905 from bogdanvlviv/docsAndrew White2016-11-131-1/+1
|\ | | | | Add missing `+` around a some literals.
| * Add missing `+` around a some literals.bogdanvlviv2016-10-271-1/+1
| | | | | | | | | | | | Mainly around `nil` [ci skip]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
|/ | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* Remove deprecated support to :text in renderRafael Mendonça França2016-10-101-3/+1
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-143-22/+22
| | | | | | 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.