Module: Plezi::Renderer

Defined in:
lib/plezi/render/render.rb

Class Method Summary collapse

Class Method Details

.register(extention, handler = nil, &block) ⇒ Object

Registers a rendering extention.

Slim, Markdown, ERB and SASS are registered by default.

extention

a Symbol or String representing the extention of the file to be rendered. i.e. ‘slim’, ‘md’, ‘erb’, etc’

handler

a Proc or other object that answers to call(filename, context, &block) and returnes the rendered string. The block accepted by the handler is for chaining rendered actions (allowing for ‘yield` within templates) and the context is the object within which the rendering should be performed (if `binding` handling is supported by the engine). `filename` might not point to an existing or valid file.

If a block is passed to the ‘register_hook` method with no handler defined, it will act as the handler.



20
21
22
23
24
25
# File 'lib/plezi/render/render.rb', line 20

def register(extention, handler = nil, &block)
   handler ||= block
   raise 'Handler or block required.' unless handler
   @render_library[extention.to_s] = handler
   handler
end

.remove(extention) ⇒ Object

Removes a registered render extention



28
29
30
# File 'lib/plezi/render/render.rb', line 28

def remove(extention)
   @render_library.delete extention.to_s
end

.render(base_filename, context = (Object.new.instance_eval { binding }), &block) ⇒ Object

Attempts to render the requested file (i.e. ‘’index.html’‘) using all known rendering handlers.



33
34
35
36
37
# File 'lib/plezi/render/render.rb', line 33

def render(base_filename, context = (Object.new.instance_eval { binding }), &block)
   ret = nil
   @render_library.each { |ext, handler| ret = handler.call("#{base_filename}.#{ext}".freeze, context, &block); return ret if ret; }
   ret
end