Class: Zero::Renderer
- Inherits:
-
Object
- Object
- Zero::Renderer
- Defined in:
- lib/zero/renderer.rb
Overview
This class helps with rendering of content.
The purpose of this class is to render templates. All variables pushed into the renderer should be already processed, so that the raw data can be used.
The workflow of this class is like the following.
-
setup the type mapping
-
create a new instance of the class to prepare rendering
-
call #render to process the template
The call to #render will return the String representation of the template with all data given.
Class Method Summary (collapse)
-
+ (Object) template_path=(path)
set a base path for template search.
-
+ (Hash) type_map
returns the type map.
-
+ (Object) type_map=(map)
save a mapping hash for the type.
Instance Method Summary (collapse)
-
- (Renderer) initialize(path, context, accept_types)
constructor
take the path and render the template within the context.
-
- (String) render
render the template within the context.
Constructor Details
- (Renderer) initialize(path, context, accept_types)
take the path and render the template within the context
49 50 51 52 53 |
# File 'lib/zero/renderer.rb', line 49 def initialize(path, context, accept_types) accept_types ||= Request::Accept.new('text/html') @path = find_template(path, accept_types) @context = context end |
Class Method Details
+ (Object) template_path=(path)
set a base path for template search
20 21 22 |
# File 'lib/zero/renderer.rb', line 20 def template_path=(path) @@path = path + '/' end |
+ (Hash) type_map
returns the type map
40 41 42 |
# File 'lib/zero/renderer.rb', line 40 def type_map @@map ||= {} end |
+ (Object) type_map=(map)
save a mapping hash for the type
With that it is possible to map long and complex contant types to simpler representations. These get then used in the finding process for the best fitting template.
34 35 36 |
# File 'lib/zero/renderer.rb', line 34 def type_map=(map) @@map = map end |
Instance Method Details
- (String) render
render the template within the context
57 58 59 |
# File 'lib/zero/renderer.rb', line 57 def render Tilt.new(@path).render(@context) end |