Module: Waves::Renderers::Mixin

Included in:
Erubis, Haml, Markaby
Defined in:
lib/renderers/mixin.rb

Overview

The renderers mixin provides a number of methods to simplify writing new renderers. Just include this in your Renderer class and write your render method.

Instance Method Summary collapse

Instance Method Details

#filename(path) ⇒ Object



20
21
22
# File 'lib/renderers/mixin.rb', line 20

def filename(path)
  "#{path}.#{self::Extension}"
end

#helper(path) ⇒ Object



28
29
30
# File 'lib/renderers/mixin.rb', line 28

def helper( path )
  Waves.main[ :helpers ][ File.basename( File.dirname( path ) ).camel_case ]
end

#included(app) ⇒ Object

Adds the following methods to the mod class:

  • filename: generate a filename for the template based on a logical path.

  • template: read the template from the file corresponding to the given logical path.

  • helper: return a helper module that corresponds to the given logical path.



16
17
18
# File 'lib/renderers/mixin.rb', line 16

def included( app )
  Waves::Views.renderers << self
end

#template(path) ⇒ Object



24
25
26
# File 'lib/renderers/mixin.rb', line 24

def template( path )
  File.read( filename( path ) )
end