Module: Volt::ComponentTemplates::Handlers

Included in:
Volt::ComponentTemplates
Defined in:
lib/volt/server/component_templates.rb

Overview

:nodoc:

Constant Summary collapse

@@template_handlers =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Setup default handler on extend



17
18
19
20
# File 'lib/volt/server/component_templates.rb', line 17

def self.extended(base)
  base.register_template_handler :html, BasicHandler.new
  base.register_template_handler :email, BasicHandler.new
end

.extensionsObject



24
25
26
# File 'lib/volt/server/component_templates.rb', line 24

def self.extensions
  @@template_handlers.keys
end

Instance Method Details

#handler_for_extension(extension) ⇒ Object



40
41
42
# File 'lib/volt/server/component_templates.rb', line 40

def handler_for_extension(extension)
  registered_template_handler(extension)
end

#register_template_handler(extension, handler) ⇒ Object

Register an object that knows how to handle template files with the given extensions. This can be used to implement new template types. The handler must respond to :call, which will be passed the template and should return the rendered template as a String.



32
33
34
# File 'lib/volt/server/component_templates.rb', line 32

def register_template_handler(extension, handler)
  @@template_handlers[extension.to_sym] = handler
end

#registered_template_handler(extension) ⇒ Object



36
37
38
# File 'lib/volt/server/component_templates.rb', line 36

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