Module: Volt::ComponentTemplates::Preprocessors

Included in:
Volt::ComponentTemplates
Defined in:
lib/volt/server/template_handlers/preprocessors.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



5
6
7
8
# File 'lib/volt/server/template_handlers/preprocessors.rb', line 5

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

.extensionsObject



12
13
14
# File 'lib/volt/server/template_handlers/preprocessors.rb', line 12

def self.extensions
  @@template_handlers.keys
end

Instance Method Details

#handler_for_extension(extension) ⇒ Object



28
29
30
# File 'lib/volt/server/template_handlers/preprocessors.rb', line 28

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.



20
21
22
# File 'lib/volt/server/template_handlers/preprocessors.rb', line 20

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

#registered_template_handler(extension) ⇒ Object



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

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