aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/tag_helper.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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 ```
* Address `Style/StringLiterals` offenceRyuta Kamizono2018-04-271-1/+1
| | | | Caused at 9276ea89d2b0be9fdd1ad6590857f8d45a38c267.
* Don't try to destoy the given string via method argumentAkira Matsuda2018-04-271-1/+1
| | | | | | | Or it would raise if the argument was frozen. And even with this change, it would still reduce String allocations together with 9276ea89d2b0be9fdd1ad6590857f8d45a38c267 because `escape` should be `true` in most cases
* Reduce String allocations when building Action View tagsAkira Matsuda2018-04-271-1/+2
| | | | | This method is called against each tag option for each tag, and creates an extra garbage String per each call
* Use consistent spacing in actionview helper docs [ci skip]Olivier Lacan2018-04-011-2/+2
| | | | | | | | The spacing in these comments is fairly inconsistent. Array argument contents are often separated with a space from the array literal brackets but in several cases the Hash literal curly braces are tangent to their contents which makes the documentation harder to read in some cases.
* Fix some typos.Mike Boone2017-10-101-1/+1
|
* Use frozen string literal in actionview/Kir Shatrov2017-07-241-1/+1
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+1
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-1/+1
|
* [ci skip] Revise TagHelper only permitting symbols doc.Kasper Timm Hansen2016-10-281-4/+3
| | | | | | | | | | | Follow up to 454460e. Rebuild the sentence so the bit about only symbols allowed comes less out of left field and fits in better with the existing doc. Also remove the `(Legacy syntax)` construct. The sections are properly nested under `=== Options` with `====` and look fine on the generated API doc site.
* Docs: `tag` only accept attribute names as symbolsclaudiob2016-10-111-2/+3
| | | | | | | | | | [ci skip] See https://github.com/rails/rails/issues/26518#issuecomment-252826489 @dhh: > I'd support symbol-only keys going forward with these new APIs. > We can break with the past here since the tag proxy is new and so is form_with.
* Improve TagHelper#tag_option performanceAmadeus Folego2016-08-221-2/+2
| | | | | | Freeze string literals and use String instead of Regex inside gsub call. This should improve performance from 20% up to 50% on most cases.
* Ensure values are strings before calling gsubMike Virata-Stone2016-08-121-1/+1
|
* ensure tag/content_tag escapes " in attribute valsAndrew Carpenter2016-08-111-1/+1
| | | | | | Many helpers mark content as HTML-safe without escaping double quotes -- including `sanitize`. Regardless of whether or not the attribute values are HTML-escaped, we want to be sure they don't include double quotes, as that can cause XSS issues. For example: `content_tag(:div, "foo", title: sanitize('" onmouseover="alert(1);//'))` CVE-2016-6316
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* applies new string literal convention in actionview/libXavier Noria2016-08-061-5/+5
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Tiny documentation fixes [ci skip]Robin Dupret2016-07-041-4/+9
| | | | | | Fix a link to use RDoc syntax and make sure that the titles' level match the section we are in since we are both documenting the new and the legacy syntax.
* Merge pull request #25553 from vipulnsward/25543-docs-follow-upVipul A M2016-06-301-16/+7
|\ | | | | 25543 docs cleanup
| * - Tone down documentationVipul A M2016-06-281-16/+7
| | | | | | | | | | | | | | - Remove repetative docs - Fix grammar on sentences - Add escaping for literals [ci skip]
* | Add dup leftover from 26710ab.Kasper Timm Hansen2016-06-281-1/+1
| |
* | Default to frozen string literals in TagHelper.Kasper Timm Hansen2016-06-281-5/+7
| | | | | | | | Removes littering `freeze` calls with Ruby 2.3's magic comment.
* | Merge pull request #25555 from vipulnsward/boolean-attributes-updateRafael França2016-06-281-6/+9
|\ \ | | | | | | Bring Boolean Attributes list for AV Tags helper upto speed with current spec
| * | Bring Boolean Attributes list for AV Tags helper upto speed with current spec.Vipul A M2016-06-281-6/+9
| |/ | | | | | | | | | | | | | | | | This is based on https://github.com/kangax/html-minifier/blob/6b2d4536d82819143b468b41a89c700b6c61631f/src/htmlminifier.js#L197 and spec from https://www.w3.org/TR/html51/single-page.html. Couple of other changes to tests due to support update: - autobuffer has been dropped in favour of preload attribute, ref: https://msdn.microsoft.com/en-us/library/ff974743(v=vs.85).aspx - pubdate attribute has been dropped from spec, ref: https://www.w3.org/html/wg/tracker/issues/185
* | Merge pull request #25551 from vipulnsward/25543-follow-upKasper Timm Hansen2016-06-281-1/+1
|\ \ | | | | | | Expand list of void elements to match spec
| * | Expand list of void elements to match spec from ↵Vipul A M2016-06-281-1/+1
| |/ | | | | | | https://html.spec.whatwg.org/multipage/syntax.html#void-elements
* / Freeze string for default content for tag_strings, which later goes on to ↵Vipul A M2016-06-281-1/+1
|/ | | | create new content. This should also be inline with content being passed should not be mutable
* New syntax for tag helpers i.e. tag.br instead of tag(br) #25195Marek2016-06-271-56/+173
|
* Test to check if the data-attr if nil is same or notSourav Moitra2016-02-141-0/+1
| | | | | | | | | | if data attribute is nil it is ignored if value is nil the pair is ignored if value is nil it is skipped Improved test for data attr nil
* Save a string allocation inside loopBenjamin Quorning2015-08-021-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the `tag_options` method, strings are continuously added to the `output` string. Previously, we concatenated two strings and added the generated string to `output`. By adding each of the strings to `output`, one after the other, we will save the allocation of that concatenated string. Benchmark: require 'benchmark/ips' sep = " ".freeze Benchmark.ips do |x| x.report("string +") { output = "" output << sep + "foo" } x.report("string <<") { output = "" output << sep output << "foo" } x.compare! end Results (Ruby 2.2.2): Calculating ------------------------------------- string + 88.086k i/100ms string << 94.287k i/100ms ------------------------------------------------- string + 2.407M (± 5.8%) i/s - 12.068M string << 2.591M (± 7.0%) i/s - 12.917M Comparison: string <<: 2591482.4 i/s string +: 2406883.7 i/s - 1.08x slower
* Don't allocate array when not necessaryschneems2015-07-301-5/+6
| | | | | | In the `tag_options` method an array is used to build up elements, then `Array#*` (which is an alias for `Array#join` is called to turn the array into a string. Instead of allocating an array to build a string, we can build the string we want from the beginning. Saved: 121,743 bytes 893 objects
* Decrease string allocation in content_tag_stringschneems2015-07-291-6/+7
| | | | | | | | | | When an unknonwn key is passed to the hash in `PRE_CONTENT_STRINGS` it returns nil, when you call "#{nil}" it allocates a new empty string. We can get around this allocation by using a default value `Hash.new { "".freeze }`. We can avoid the `to_sym` call by pre-populating the hash with a symbol key in addition to a string key. We can freeze some strings when using Array#* to reduce allocations. Array#join can take frozen strings. This change buys us 86,600 bytes of memory and 1,857 fewer objects per request.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Call gsub with a Regexp instead of a String for better performancePablo Herrero2014-11-011-1/+1
|
* remove un-needed sortschneems2014-10-071-1/+1
| | | | | | HTML doesn't care what order the elements are rendered in, so why should we? Updates tests to use proper `assert_dom_equal` instead of `assert_equal` /cc @jeremy
* Extract data/aria attribute prefixes to a constantRafael Mendonça França2014-09-031-1/+3
|
* Add support for ARIA attributes in tagsPaoMar2014-09-031-4/+4
|
* Include missing module in tag_helperCarlos Antonio da Silva2014-07-091-0/+1
| | | | | | | | | Since 6857415187810f1289068a448268264d0cf0844f we are using #safe_join to join the content when an Array is given, so we must include the dependent module here to make sure it's available when this module is used alone. This was making Simple Form tests to fail with current master due to the missing dependency.
* Merge pull request #15654 from pdg137/masterMatthew Draper2014-06-131-2/+5
|\ | | | | | | In tag helper, honor html_safe on arrays; also make safe_join more similar to Array.join
| * In tag helper, honor html_safe on array parameters; also make safe_join more ↵Paul Grayson2014-06-121-3/+15
|/ | | | similar to Array.join by first calling flatten.
* drastically reduce object allocationsAaron Patterson2014-06-021-2/+2
| | | | | | | | | | before this change, we were allocating AS::SafeBuffer objects that were being interpolated in to a string, so the safe buffer object was being thrown away. This change only allocates a string (vs a string *and* a safebuffer) and interpolates the string. On my test application, this reduced the AS::SafeBuffer objects from 1527k per request to about 500 per request.
* Update doc for TagHelper.Hendy Tanata2014-03-051-2/+8
|
* Allocate one less object using html_safe during content_tag constructionJosh Jordan2013-11-141-1/+1
|
* Convert CDATA input to string before gsub'ingCarsten Zimmermann2013-10-291-1/+1
| | | | | Rails 3.2 API allowed arbitrary input for cdata_section; this change re-introduces the old behaviour.
* Move actionpack/lib/action_view* into actionview/libPiotr Sarnacki2013-06-201-0/+176