Sha256: f4b4ffbbaf56003c398b2928f7b13f1da18b8aa76dba3620a9f6eb629b3a60dd

Contents?: true

Size: 1.07 KB

Versions: 96

Compression:

Stored size: 1.07 KB

Contents

require 'set'
require 'active_support/core_ext/module/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

96 entries across 92 versions & 9 rubygems

Version Path
actionview-4.2.11.3 lib/action_view/template/types.rb
actionview-4.2.11.2 lib/action_view/template/types.rb
actionview-4.2.11.1 lib/action_view/template/types.rb
actionview-4.2.11 lib/action_view/template/types.rb
actionview-4.2.10 lib/action_view/template/types.rb
actionview-4.2.10.rc1 lib/action_view/template/types.rb
actionview-4.2.9 lib/action_view/template/types.rb
actionview-4.2.9.rc2 lib/action_view/template/types.rb
actionview-4.2.9.rc1 lib/action_view/template/types.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actionview-4.2.8/lib/action_view/template/types.rb
actionview-4.2.8 lib/action_view/template/types.rb
actionview-4.2.8.rc1 lib/action_view/template/types.rb
actionview-4.2.7.1 lib/action_view/template/types.rb
actionview-4.2.7 lib/action_view/template/types.rb
actionview-4.1.16 lib/action_view/template/types.rb
actionview-4.1.16.rc1 lib/action_view/template/types.rb
actionview-4.2.7.rc1 lib/action_view/template/types.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actionview-4.2.6/lib/action_view/template/types.rb
actionview-4.1.15 lib/action_view/template/types.rb
actionview-4.2.6 lib/action_view/template/types.rb