Sha256: 8feda1969e1eb8df4f981759cfd80c22eda7c43ca16fc32446695e65be80ed91

Contents?: true

Size: 1.73 KB

Versions: 133

Compression:

Stored size: 1.73 KB

Contents

module ActionView #:nodoc:
  # = Action View Template Handlers
  class Template
    module Handlers #:nodoc:
      autoload :ERB, 'action_view/template/handlers/erb'
      autoload :Builder, 'action_view/template/handlers/builder'

      def self.extended(base)
        base.register_default_template_handler :erb, ERB.new
        base.register_template_handler :builder, Builder.new
      end

      @@template_handlers = {}
      @@default_template_handlers = nil

      def self.extensions
        @@template_extensions ||= @@template_handlers.keys
      end

      # Register a class that knows how to handle template files with the given
      # extension. This can be used to implement new template types.
      # The constructor for the class must take the ActiveView::Base instance
      # as a parameter, and the class must implement a +render+ method that
      # takes the contents of the template to render as well as the Hash of
      # local assigns available to the template. The +render+ method ought to
      # return the rendered template as a string.
      def register_template_handler(extension, klass)
        @@template_handlers[extension.to_sym] = klass
        @@template_extensions = nil
      end

      def template_handler_extensions
        @@template_handlers.keys.map {|key| key.to_s }.sort
      end

      def registered_template_handler(extension)
        extension && @@template_handlers[extension.to_sym]
      end

      def register_default_template_handler(extension, klass)
        register_template_handler(extension, klass)
        @@default_template_handlers = klass
      end

      def handler_for_extension(extension)
        registered_template_handler(extension) || @@default_template_handlers
      end
    end
  end
end

Version data entries

133 entries across 99 versions & 18 rubygems

Version Path
actionpack-3.2.22.5 lib/action_view/template/handlers.rb
actionpack-3.2.22.4 lib/action_view/template/handlers.rb
actionpack-3.2.22.3 lib/action_view/template/handlers.rb
actionpack-3.2.22.2 lib/action_view/template/handlers.rb
actionpack-3.2.22.1 lib/action_view/template/handlers.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/template/handlers.rb
actionpack-3.2.22 lib/action_view/template/handlers.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.12/lib/action_view/template/handlers.rb
actionpack-3.2.21 lib/action_view/template/handlers.rb
actionpack-3.2.20 lib/action_view/template/handlers.rb
actionpack-3.2.19 lib/action_view/template/handlers.rb
actionpack-3.2.18 lib/action_view/template/handlers.rb
actionpack-3.2.17 lib/action_view/template/handlers.rb
actionpack-3.2.16 lib/action_view/template/handlers.rb
actionpack-3.2.15 lib/action_view/template/handlers.rb
actionpack-3.2.15.rc3 lib/action_view/template/handlers.rb
actionpack-3.2.15.rc2 lib/action_view/template/handlers.rb
actionpack-3.2.15.rc1 lib/action_view/template/handlers.rb
actionpack-3.2.14 lib/action_view/template/handlers.rb
actionpack-3.2.14.rc2 lib/action_view/template/handlers.rb