Sha256: 239f1abb52ef2c7a093950c24d645fd1c05262b58a6973da5caf1f1939b521b9

Contents?: true

Size: 1.07 KB

Versions: 30

Compression:

Stored size: 1.07 KB

Contents

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

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
actionpack-4.0.13 lib/action_view/template/types.rb
actionpack-4.0.13.rc1 lib/action_view/template/types.rb
actionpack-4.0.11.1 lib/action_view/template/types.rb
actionpack-4.0.12 lib/action_view/template/types.rb
actionpack-4.0.11 lib/action_view/template/types.rb
actionpack-4.0.10 lib/action_view/template/types.rb
actionpack-4.0.10.rc2 lib/action_view/template/types.rb
actionpack-4.0.10.rc1 lib/action_view/template/types.rb
actionpack-4.0.9 lib/action_view/template/types.rb
actionpack-4.0.8 lib/action_view/template/types.rb
actionpack-4.0.7 lib/action_view/template/types.rb
actionpack-4.0.6 lib/action_view/template/types.rb
actionpack-4.0.6.rc3 lib/action_view/template/types.rb
actionpack-4.0.6.rc2 lib/action_view/template/types.rb
actionpack-4.0.6.rc1 lib/action_view/template/types.rb
actionpack-4.0.5 lib/action_view/template/types.rb
actionpack-4.0.4 lib/action_view/template/types.rb
actionpack-4.0.4.rc1 lib/action_view/template/types.rb
actionpack-4.0.3 lib/action_view/template/types.rb
actionpack-4.0.2 lib/action_view/template/types.rb