From 0d6e8edc2a47a4b4c6824936632bfb83850db343 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 4 May 2013 15:09:22 +0200 Subject: Move actionpack/lib/action_view* into actionview/lib --- actionview/lib/action_view/template/types.rb | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 actionview/lib/action_view/template/types.rb (limited to 'actionview/lib/action_view/template/types.rb') 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 -- cgit v1.2.3