Module: Waves::Renderers::Mixin
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.
Class Method Summary collapse
-
.included(target) ⇒ Object
Adds the following methods to the target class:.
Class Method Details
.included(target) ⇒ Object
Adds the following methods to the target class:
-
extension: allows you to set or get the extension used by this renderer.
Renderers::Markaby.extension 'foo' # tell Waves to use .foo as Markaby extension
-
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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/renderers/mixin.rb', line 22 def self.included(target) class << target def extension(*args) return @extension if args.length == 0 @extension = args.first end def filename(path) :templates / "#{path}.#{self.extension}" end def render(path,args=nil) end def template( path ) File.read( filename( path ) ) end def helper( path ) Waves.application.helpers[ File.basename( File.dirname( path ) ).camel_case ] end end end |