diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-17 17:56:20 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-17 17:56:20 +0100 |
commit | 2683dcc60ecbdb328bb213b20b7165a332b9d12e (patch) | |
tree | 435b1902cf8d7ab1dfd4b49a2a2144430d144480 /actionview/lib/action_view/template | |
parent | 5d1b7c3b441654e8008dcd303f5367883ec660a6 (diff) | |
parent | 91f2ad36821cc01d2084dd1690fecc0913fc541d (diff) | |
download | rails-2683dcc60ecbdb328bb213b20b7165a332b9d12e.tar.gz rails-2683dcc60ecbdb328bb213b20b7165a332b9d12e.tar.bz2 rails-2683dcc60ecbdb328bb213b20b7165a332b9d12e.zip |
Merge pull request #23089 from kaspth/better-template-types
Enrich Action View Template types with symbols from Action Dispatch Mime.
Diffstat (limited to 'actionview/lib/action_view/template')
-rw-r--r-- | actionview/lib/action_view/template/types.rb | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/actionview/lib/action_view/template/types.rb b/actionview/lib/action_view/template/types.rb index be45fcf742..ddc5b25831 100644 --- a/actionview/lib/action_view/template/types.rb +++ b/actionview/lib/action_view/template/types.rb @@ -5,19 +5,12 @@ module ActionView class Template class Types class Type - cattr_accessor :types - self.types = Set.new - - def self.register(*t) - types.merge(t.map(&:to_s)) - end - - register :html, :text, :js, :css, :xml, :json + SET = Struct.new(:symbols).new([ :html, :text, :js, :css, :xml, :json ]) def self.[](type) - return type if type.is_a?(self) - - if type.is_a?(Symbol) || types.member?(type.to_s) + if type.is_a?(self) + type + else new(type) end end @@ -28,16 +21,18 @@ module ActionView @symbol = symbol.to_sym end - delegate :to_s, :to_sym, :to => :symbol + def to_s + @symbol.to_s + end alias to_str to_s def ref - to_sym || to_s + @symbol end + alias to_sym ref def ==(type) - return false if type.blank? - symbol.to_sym == type.to_sym + @symbol == type.to_sym unless type.blank? end end @@ -52,6 +47,10 @@ module ActionView def self.[](type) type_klass[type] end + + def symbols + type_klass::SET.symbols + end end end end |