aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/html.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-02-25 13:18:44 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-02-25 13:18:44 -0800
commitca5e23ed4d8818d81314953aadd422b2cbde63b0 (patch)
treea411836c47d0ac22af072ec580656e983954d131 /actionview/lib/action_view/template/html.rb
parentd1f68b50487ea1a8fc7f822973e2cc46d1288060 (diff)
downloadrails-ca5e23ed4d8818d81314953aadd422b2cbde63b0.tar.gz
rails-ca5e23ed4d8818d81314953aadd422b2cbde63b0.tar.bz2
rails-ca5e23ed4d8818d81314953aadd422b2cbde63b0.zip
Templates have one format
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.
Diffstat (limited to 'actionview/lib/action_view/template/html.rb')
-rw-r--r--actionview/lib/action_view/template/html.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/actionview/lib/action_view/template/html.rb b/actionview/lib/action_view/template/html.rb
index a262c6d9ad..ecd1c31e79 100644
--- a/actionview/lib/action_view/template/html.rb
+++ b/actionview/lib/action_view/template/html.rb
@@ -1,15 +1,21 @@
# frozen_string_literal: true
+require "active_support/deprecation"
+
module ActionView #:nodoc:
# = Action View HTML Template
class Template #:nodoc:
class HTML #:nodoc:
- attr_accessor :type
+ attr_reader :type
def initialize(string, type = nil)
+ unless type
+ ActiveSupport::Deprecation.warn "ActionView::Template::HTML#initialize requires a type parameter"
+ type = :html
+ end
+
@string = string.to_s
- @type = Types[type] || type if type
- @type ||= Types[:html]
+ @type = type
end
def identifier
@@ -26,9 +32,12 @@ module ActionView #:nodoc:
to_str
end
- def formats
- [@type.respond_to?(:ref) ? @type.ref : @type.to_s]
+ def format
+ @type
end
+
+ def formats; Array(format); end
+ deprecate :formats
end
end
end