aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template
Commit message (Collapse)AuthorAgeFilesLines
...
* Change the raw template handler to render html-safe stringseileencodes2016-06-211-1/+1
| | | | | | | | | | | | | | | In PR #24929 the changelog was updated to make note that while the new template handler was changed to raw this changed the behavior when outputting plain html or js files. Previously ERB would output the files unescaped. Changing the default handler to RAW meant that these same files would be rendered as escaped rather than as js or html. Because of this change in behavior and after the discussion #24949 in we decided to change the behavior of the Raw handler to output html_safe strings by default. Now files rendered with the default handler (raw) render the file unescaped.
* 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.
* set in no more used in ActionView::Template::TypesGaurav Sharma2016-03-251-1/+0
| | | | | initially set is used for template type https://github.com/rails/rails/commit/67f55e28 after this commit https://github.com/rails/rails/commit/91f2ad36 it’s not require
* 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
* Lock down new `ImplicitRender` behavior for 5.0 RCGodfrey Chan2016-02-251-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Conceptually revert #20276 The feature was implemented for the `responders` gem. In the end, they did not need that feature, and have found a better fix (see plataformatec/responders#131). `ImplicitRender` is the place where Rails specifies our default policies for the case where the user did not explicitly tell us what to render, essentially describing a set of heuristics. If the gem (or the user) knows exactly what they want, they could just perform the correct `render` to avoid falling through to here, as `responders` did (the user called `respond_with`). Reverting the patch allows us to avoid exploding the complexity and defining “the fallback for a fallback” policies. 2. `respond_to` and templates are considered exhaustive enumerations If the user specified a list of formats/variants in a `respond_to` block, anything that is not explicitly included should result in an `UnknownFormat` error (which is then caught upstream to mean “406 Not Acceptable” by default). This is already how it works before this commit. Same goes for templates – if the user defined a set of templates (usually in the file system), that set is now considered exhaustive, which means that “missing” templates are considered `UnknownFormat` errors (406). 3. To keep API endpoints simple, the implicit render behavior for actions with no templates defined at all (regardless of formats, locales, variants, etc) are defaulted to “204 No Content”. This is a strictly narrower version of the feature landed in #19036 and #19377. 4. To avoid confusion when interacting in the browser, these actions will raise an `UnknownFormat` error for “interactive” requests instead. (The precise definition of “interactive” requests might change – the spirit here is to give helpful messages and avoid confusions.) Closes #20666, #23062, #23077, #23564 [Godfrey Chan, Jon Moss, Kasper Timm Hansen, Mike Clark, Matthew Draper]
* Make collection caching explicit.Kasper Timm Hansen2016-02-201-25/+0
| | | | | | | | | | | | Having collection caching that wraps templates and automatically tries to infer if they are cachable proved to be too much of a hassle. We'd rather have it be something you explicitly turn on. This removes much of the code and docs to explain the previous automatic behavior. This change also removes scoped cache keys and passing cache_options.
* WIP: Errors in logs should show log tags as well.Vipul A M2016-02-121-2/+2
| | | | | | | - Changed formatted_code_for to return array of logs to be tagged for each line - Changed some render tests to match new behaviour of return Fixes #22979
* Merge pull request #22772 from gsamokovarov/nack-template-errorDavid Heinemeier Hansson2016-02-101-0/+4
|\ | | | | Fix edge case with ActionView::Template::Error reraise
| * Fix edge case with ActionView::Template::Error reraiseGenadi Samokovarov2015-12-231-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When you re-raise an ActionView::Template::Error, the #cause can change. You can see this behaviour with [nack]. Currently, `web-console` doesn't run the console in the proper binding in the case of errors in the views, because when we follow the `#cause` of the exception it is an [`EOFError`][EOFError]. This also affects [pow] as it runs on [nack]. [nack]: https://github.com/josh/nack [pow]: http://pow.cx/ [EOFError]: https://github.com/josh/nack/blob/d523cc870c0a11dcf349388a15adfecba9314f97/lib/nack/server.rb#L108
* | Merge branch '5-0-beta-sec'Aaron Patterson2016-01-251-3/+20
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 5-0-beta-sec: bumping version fix version update task to deal with .beta1.1 Eliminate instance level writers for class accessors allow :file to be outside rails root, but anything else must be inside the rails view directory Don't short-circuit reject_if proc stop caching mime types globally use secure string comparisons for basic auth username / password
| * | allow :file to be outside rails root, but anything else must be inside the ↵Aaron Patterson2016-01-221-3/+20
| |/ | | | | | | | | | | rails view directory CVE-2016-0752
* | Remove ActionView dependence on ActionPack's Mime implementationJon Moss2016-01-171-1/+1
| |
* | Store the symbols as an array.Kasper Timm Hansen2016-01-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A Set can't be implicitly converted into an Array: ``` irb(main):012:0> formats = [ :rss ] => [:rss] irb(main):013:0> formats &= SET.symbols TypeError: no implicit conversion of Set into Array from (irb):13:in `&' from (irb):13 from /Users/kasperhansen/.rbenv/versions/2.2.3/bin/irb:11:in `<main>' ``` Besides `Mime::SET.symbols` returns an Array, so we're closer to that.
* | Enrich the SET constant to respond to symbols.Kasper Timm Hansen2016-01-171-1/+5
| | | | | | | | Match `Mime::SET.symbols`.
* | Don't bother looking up the types.Kasper Timm Hansen2016-01-171-3/+3
| | | | | | | | If they aren't symbols, then they aren't likely to be in the set anyway.
* | Replace class attribute with SET constant.Kasper Timm Hansen2016-01-171-3/+2
| | | | | | | | We'll be using this to map over to Action Dispatch's Mime::Set.
* | Remove register abstraction.Kasper Timm Hansen2016-01-171-7/+1
| | | | | | | | | | The template types is a private abstraction to fill in basic blanks from Action Dispatch's mime types. As such we can modify the data structure ourselves.
* | Replace delegate calls with standard method defs.Kasper Timm Hansen2016-01-171-1/+4
| | | | | | | | | | | | Spares a to_sym call by aliasing to_sym to ref. Then the delegate felt meager for one method; ditch and define method ourselves.
* | Spare to_sym call in `==`.Kasper Timm Hansen2016-01-171-2/+1
| | | | | | | | | | | | | | The @symbol has already been converted to a symbol in initialize, so no need to call to_sym when comparing it. Ditch early return for a simple unless statement.
* | Make ref return the internal symbol.Kasper Timm Hansen2016-01-171-1/+1
| | | | | | | | | | | | | | | | | | We delegate to_sym to the internal symbol, which we've already called to_sym on in initialize, so we don't need to do that. We also know to_sym will never return a falsy value, so we'll never hit to_s. Just return the symbolized symbol.
* | Prefer inspect over escaping and sorround by quote marksSantiago Pastorino2016-01-051-3/+1
| |
* | Add Html template handler that wraps Raw output in an OutputBufferSantiago Pastorino2016-01-052-1/+12
| | | | | | | | | | | | | | This fixes the case when you try to render an html you know safe and the file is named something.html. With this commit the content of the html won't be escaped anymore because AV won't use Raw handler and choose Html handler instead.
* | Require only the concurrent/map featureRafael Mendonça França2015-12-231-1/+1
|/
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-6/+13
|
* Replaced `ThreadSafe::Map` with successor `Concurrent::Map`.Jerry D'Antonio2015-09-191-2/+2
| | | | | | | The thread_safe gem is being deprecated and all its code has been merged into the concurrent-ruby gem. The new class, Concurrent::Map, is exactly the same as its predecessor except for fixes to two bugs discovered during the merge.
* Add wildcard template dependencies.Kasper Timm Hansen2015-07-261-0/+14
|
* Freeze string literals when not mutated.schneems2015-07-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* Support explicit defintion of resouce name for collection caching.Dov Murik2015-07-071-2/+9
| | | | | | | | | | | | | | If a template includes `# Template Collection: ...` anywhere in its source, that name will be used as the cache name for the partial that is rendered for the collection. This allows users to enable collection caching even if the template doesn't start with `<% cache ... do %>`. Moreover, the `# Template Collection: ...` notation is recognized in all template types (and template types other than ERB can define a resource_cache_call_pattern method to allow the `cache ... do` pattern to be recognized too).
* Improve detection of partial templates eligible for collection caching.Dov Murik2015-06-221-1/+1
| | | | | | | | | | | | | | The regular expression which was used to detect partial templates that begin with a `<% cache ... do %>` call missed some cases. This commits attempts to improve the detection for some cases such as multi-line comments at the beginning of the template. The different templates are listed in two new unit test methods. Note that specially crafted Ruby code can still evade such `cache`-call detection: for example, a user might have its own method which itself calls the Rails `cache` helper. In such a case, the template's code doesn't start with a literal `cache` string and therefore will not be eligible for collection caching.
* applies project style guidelinesXavier Noria2015-06-201-7/+7
| | | | Just saw these in passing while reading this file.
* removes unnecessary backslashes in regexpsXavier Noria2015-06-201-3/+3
| | | | Colons are not metacharacters.
* Merge pull request #17512 from ↵Zachary Scott2015-04-101-1/+1
|\ | | | | | | | | JackDanger/danger/use-default-view-pattern-in-docs [docs] Using the real resolver pattern in docs
| * Using the real resolver pattern in docsJack Danger Canty2014-11-041-1/+1
| | | | | | | | | | | | | | | | If someone copies the docs into their app they'll find it simply doesn't work because the locale pattern doesn't have the same logic. This makes the doc examples work exactly as written. [ci skip]
* | Freeze static arguments for gsubbrainopia2015-04-021-1/+1
| |
* | Prefer string patterns for gsubbrainopia2015-04-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://github.com/ruby/ruby/pull/579 - there is a new optimization since ruby 2.2 Previously regexp patterns were faster (since a string was converted to regexp underneath anyway). But now string patterns are faster and better reflect the purpose. Benchmark.ips do |bm| bm.report('regexp') { 'this is ::a random string'.gsub(/::/, '/') } bm.report('string') { 'this is ::a random string'.gsub('::', '/') } bm.compare! end # string: 753724.4 i/s # regexp: 501443.1 i/s - 1.50x slower
* | Collections automatically cache and fetch partials.Kasper Timm Hansen2015-02-211-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Collections can take advantage of `multi_read` if they render one template and their partials begin with a cache call. The cache call must correspond to either what the collections elements are rendered as, or match the inferred name of the partial. So with a notifications/_notification.html.erb template like: ```ruby <% cache notification %> <%# ... %> <% end %> ``` A collection would be able to use `multi_read` if rendered like: ```ruby <%= render @notifications %> <%= render partial: 'notifications/notification', collection: @notifications, as: :notification %> ```
* | Remove version conditional for find_template_pathsRafael Mendonça França2015-01-041-18/+6
| | | | | | | | | | Now that we only support Ruby 2.2+ we don't need this conditional anymore
* | Remove unneeded requiresRafael Mendonça França2015-01-041-1/+0
| | | | | | | | These requires were added only to change deprecation message
* | Change the default template handler from `ERB` to `Raw`.Rafael Mendonça França2015-01-042-8/+2
| | | | | | | | | | Files without a template handler in their extension will be rended using the raw handler instead of ERB.
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-294-4/+4
| |
* | Wrap code snippets in +, not backticks, in sdocclaudiob2014-11-201-1/+1
| | | | | | | | | | | | | | | | I grepped the source code for code snippets wrapped in backticks in the comments and replaced the backticks with plus signs so they are correctly displayed in the Rails documentation. [ci skip]
* | Some valid block calls in templates caused syntax errorsAkira Matsuda2014-11-201-1/+1
|/ | | | Now ActionView accepts <%= foo(){ %> and <%= foo()do %> :golf:
* Call gsub with a Regexp instead of a String for better performancePablo Herrero2014-11-011-1/+1
|
* let's warn with heredocsXavier Noria2014-10-281-3/+5
| | | | | | | | | | | | The current style for warning messages without newlines uses concatenation of string literals with manual trailing spaces where needed. Heredocs have better readability, and with `squish` we can still produce a single line. This is a similar use case to the one that motivated defining `strip_heredoc`, heredocs are super clean.
* Add +variants to ActionView::FileSystemResolver documentation.Felipe Oliveira2014-09-261-3/+4
|
* handle <%== nil %> casesAaron Patterson2014-09-141-2/+2
| | | | | This is much less common than string literal appends, so add a special case method for it. Maybe fixes bug reported by @jeremy on 97ef636191933f1d4abc92fc10871e6d1195285c
* Add unregister_template_handler to prevent leaks.Zuhao Wan2014-06-121-0/+9
|
* Feature detect based on Ruby version.Aaron Patterson2014-05-181-1/+1
| | | | | | | I didn't want to do this, FNM_EXTGLOB is defined on 2.1.x, but Dir.glob returns the wrong value on Ruby less than 2.2.0. Checking for a case-insensitive FS seems too hard, so just check Ruby version Checking for a case-insensitive FS seems too hard, so just check Ruby version.
* feature detect for FNM_EXTGLOB for older Ruby. Fixes #15053Aaron Patterson2014-05-101-5/+21
|