aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Templates have one formatAaron Patterson2019-02-252-8/+19
| | | | | | | 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.
* 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.
* Add a finalizer to inline templatesAaron Patterson2019-02-221-0/+22
| | | | | | | | | | | | | | | | | | | 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
* 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.
* Turn lookup context in to a stack, push and pop if formats changeAaron Patterson2019-02-111-1/+1
| | | | | | | | | | | 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
* Take in to account optional arguments when deprecatingAaron Patterson2019-02-041-1/+1
| | | | Refs: rails/jbuilder#452
* Pass source to template handler and deprecate old style handlerAaron Patterson2019-02-015-11/+37
| | | | | | | | | This commit passes the mutated source to the template handler as a parameter and deprecates the old handlers. Old handlers required that templates contain a reference to mutated source code, but we would like to make template objects "read only". This change lets the template remain "read only" while still giving template handlers access to the source code after mutations.
* 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.
* Tighten up the AV::Base constructorAaron Patterson2019-01-291-1/+1
| | | | | | | | | | | | | | | The AV::Base constructor was too complicated, and this commit tightens up the parameters it will take. At runtime, AV::Base is most commonly constructed here: https://github.com/rails/rails/blob/94d54fa4ab641a0ddeb173409cb41cc5becc02a9/actionview/lib/action_view/rendering.rb#L72-L74 This provides an AV::Renderer instance, a hash of assignments, and a controller instance. Since this is the common case for construction, we should remove logic from the constructor that handles other cases. This commit introduces special constructors for those other cases. Interestingly, most code paths that construct AV::Base "strangely" are tests.
* Pull buffer assignment upAaron Patterson2019-01-161-1/+1
| | | | | Since everything goes through a `run` method, we can pull the buffer assignment up.
* Always evaluate views against an ActionView::BaseAaron Patterson2019-01-161-4/+6
| | | | | Methods created by views should always be evaluated against an AV::Base instance. This way we can extract and refactor things in to classes.
* Pull output buffer conditional upAaron Patterson2019-01-161-1/+3
| | | | | | This pulls the "output buffer existence" conditional up. Instead of evaling the same conditional over and over, we can pull it in to "only compiled once" Ruby code.
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-2/+2
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* 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
|
* Permit list usage cleanup and clearer documentationKevin Deisz2018-08-271-6/+6
|
* Deprecate usage of ActionView::Template::Handlers::ERB::escape_whitelistKevin Deisz2018-08-241-2/+12
|
* Remove unused `MissingRequestError`yuuji.yaginuma2017-10-311-3/+0
| | | | `MissingRequestError` is no longer used since 1e2b0ce.
* Remove deprecated Erubis ERB handlerRafael Mendonça França2017-10-233-97/+0
|
* [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
|
* Fix broken doc layout for action_view [ci skip]Yoshiyuki Hirano2017-08-274-4/+4
|
* Use frozen string literal in actionview/Kir Shatrov2017-07-2413-0/+26
|
* 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-0213-13/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0213-0/+13
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0113-0/+13
| | |
| * | 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
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-292-10/+4
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* call `gem` `erubis` before requireyuuji.yaginuma2017-02-011-0/+1
| | | | For inform that need to add `erubis` to gemfile.
* Fix inherit from deprecated `ActionView::Template::Handlers::Erubis`Fumiaki MATSUSHIMA2017-02-012-1/+10
| | | | | | | | | | There are some classes inherit from `ActionView::Template::Handlers::Erubis`. (ex. https://github.com/haml/haml/blob/4.0.7/lib/haml/helpers/safe_erubis_template.rb#L3) ``` Class.new(ActionView::Template::Handlers::Erubis) # => TypeError: superclass must be a Class (ActiveSupport::Deprecation::DeprecatedConstantProxy given) ```
* 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
| |
* | Change ActionView ERB Handler from Erubis to ErubiJeremy Evans2017-01-253-72/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Erubi offers the following advantages for Rails: * Works with ruby's --enable-frozen-string-literal option * Has 88% smaller memory footprint * Does no freedom patching (Erubis adds a method to Kernel) * Has simpler internals (1 file, <150 lines of code) * Has an open development model (Erubis doesn't have a public source control repository or bug tracker) * Is not dead (Erubis hasn't been updated since 2011) Erubi is a simplified fork of Erubis that contains just the parts that are generally needed (which includes the parts that Rails uses). The only intentional difference in behavior is that it does not include support for <%=== tags for debug output. That could be added to the ActionView ERB handler if it is desired. The Erubis template handler remains in a deprecated state so that code that accesses it directly does not break. It can be removed after Rails 5.1.
* | `find_templates` should be able to handle 5 argumentskenta-s2017-01-191-2/+2
|/
* Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-1/+1
| | | | (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-2/+2
|
* No need to nodoc private methodsAkira Matsuda2016-12-241-2/+2
|
* Remove unused argumentRafael Mendonça França2016-12-021-4/+3
| | | | Now Text class is only used to render text mime type pages