aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/types.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2013-05-04 15:09:22 +0200
committerŁukasz Strzałkowski <lukasz.strzalkowski@gmail.com>2013-06-20 17:23:15 +0200
commit0d6e8edc2a47a4b4c6824936632bfb83850db343 (patch)
tree8829bfb94756e48e9489c4e8d22bb41df251bc81 /actionview/lib/action_view/template/types.rb
parent78b0934dd1bb84e8f093fb8ef95ca99b297b51cd (diff)
downloadrails-0d6e8edc2a47a4b4c6824936632bfb83850db343.tar.gz
rails-0d6e8edc2a47a4b4c6824936632bfb83850db343.tar.bz2
rails-0d6e8edc2a47a4b4c6824936632bfb83850db343.zip
Move actionpack/lib/action_view* into actionview/lib
Diffstat (limited to 'actionview/lib/action_view/template/types.rb')
-rw-r--r--actionview/lib/action_view/template/types.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/actionview/lib/action_view/template/types.rb b/actionview/lib/action_view/template/types.rb
new file mode 100644
index 0000000000..db77cb5d19
--- /dev/null
+++ b/actionview/lib/action_view/template/types.rb
@@ -0,0 +1,57 @@
+require 'set'
+require 'active_support/core_ext/class/attribute_accessors'
+
+module ActionView
+ class Template
+ class Types
+ class Type
+ cattr_accessor :types
+ self.types = Set.new
+
+ def self.register(*t)
+ types.merge(t.map { |type| type.to_s })
+ end
+
+ register :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)
+ new(type)
+ end
+ end
+
+ attr_reader :symbol
+
+ def initialize(symbol)
+ @symbol = symbol.to_sym
+ end
+
+ delegate :to_s, :to_sym, :to => :symbol
+ alias to_str to_s
+
+ def ref
+ to_sym || to_s
+ end
+
+ def ==(type)
+ return false if type.blank?
+ symbol.to_sym == type.to_sym
+ end
+ end
+
+ cattr_accessor :type_klass
+
+ def self.delegate_to(klass)
+ self.type_klass = klass
+ end
+
+ delegate_to Type
+
+ def self.[](type)
+ type_klass[type]
+ end
+ end
+ end
+end