1 module ActionView
#:nodoc:
2 module TemplateHandlers
#:nodoc:
3 autoload
:ERB, 'action_view/template_handlers/erb'
4 autoload
:RJS, 'action_view/template_handlers/rjs'
5 autoload
:Builder, 'action_view/template_handlers/builder'
7 def self.extended(base
)
8 base
.register_default_template_handler
:erb, TemplateHandlers
::ERB
9 base
.register_template_handler
:rjs, TemplateHandlers
::RJS
10 base
.register_template_handler
:builder, TemplateHandlers
::Builder
12 # TODO: Depreciate old template extensions
13 base
.register_template_handler
:rhtml, TemplateHandlers
::ERB
14 base
.register_template_handler
:rxml, TemplateHandlers
::Builder
17 @
@template_handlers = {}
18 @
@default_template_handlers = nil
20 # Register a class that knows how to handle template files with the given
21 # extension. This can be used to implement new template types.
22 # The constructor for the class must take the ActiveView::Base instance
23 # as a parameter, and the class must implement a +render+ method that
24 # takes the contents of the template to render as well as the Hash of
25 # local assigns available to the template. The +render+ method ought to
26 # return the rendered template as a string.
27 def register_template_handler(extension
, klass
)
28 @
@template_handlers[extension
.to_sym
] = klass
31 def template_handler_extensions
32 @
@template_handlers.keys
.map(&:to_s).sort
35 def registered_template_handler(extension
)
36 extension
&& @
@template_handlers[extension
.to_sym
]
39 def register_default_template_handler(extension
, klass
)
40 register_template_handler(extension
, klass
)
41 @
@default_template_handlers = klass
44 def handler_class_for_extension(extension
)
45 registered_template_handler(extension
) || @
@default_template_handlers