From 46739a8a2494f7b3e8ae83ce3caeee078378a473 Mon Sep 17 00:00:00 2001
From: Gibheer
the base renderer for getting render containers
+This class helps with rendering of content.
-This class handles templates and render coontainers, which can be used for -the actual rendering.
+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.
-To use this renderer you have to give it a template path and optionally a -map of shorthand type descriptions to fully types. This will then be used -to extend the internal map of templates to possible formats in a way, that -you will be able to answer xhtml and html requests with the same template.
+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
+When the object is initialized and you are sure, everything is loaded, call -#read_template_path! and the template tree will be built. Without this -step, you will probably don't get any output.
- -After the setup, the renderer can be used to build render containers, which -then can be used to actually render something.
+The call to #render will return the String representation of the template +with all data given.
get the path to the templates.
+set a base path for template search.
get the tree of templates.
+returns the type map.
returns the hash of type conversions.
+save a mapping hash for the type.
initializes a new Renderer.
+take the path and render the template within the context.
load the template tree.
-render a template.
+render the template within the context.
initializes a new Renderer
- -This method takes a path to the base template directory and a type map. -This type map is used to extend the possible renderings for different -types, which the clients sends.
+take the path and render the template within the context
get the path to the templates
+set a base path for template search
-46 -47 -48+20 +21 +22 |
- # File 'lib/zero/renderer.rb', line 46 +# File 'lib/zero/renderer.rb', line 20 -def template_path - @template_path +def template_path=(path) + @@path = path + '/' end |
@@ -489,12 +439,10 @@ types, which the clients sends.
- This method is part of a private API. - You should avoid using this method if possible, as it may be removed or be changed in the future. -
- -get the tree of templates
+ +returns the type map
the template tree
+the mapping for types
-50 -51 -52+40 +41 +42
# File 'lib/zero/renderer.rb', line 50 +# File 'lib/zero/renderer.rb', line 40 -def templates - @templates +def type_map + @@map ||= {} end
returns the hash of type conversions
+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.
-43 -44 -45+34 +35 +36 |
- # File 'lib/zero/renderer.rb', line 43 +# File 'lib/zero/renderer.rb', line 34 -def type_map - @type_map +def type_map=(map) + @@map = map end |
@@ -619,103 +576,14 @@ types, which the clients sends.
-
- - - -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72- |
-
- # File 'lib/zero/renderer.rb', line 58 - -def read_template_path! - # TODO clean up later - @templates = {} - search_files.each do |file| - parts = file.gsub(/#{template_path}/, '').split('.') - @templates[parts[0]] ||= {} - if parts.count > 2 then - read_type(parts[1]).each do |type| - @templates[parts[0]][type] = file - end - else - @templates[parts[0]][''] = file - end - end -end -- |
-
render a template
- -This method will render the given template, based on the type in the given -context.
+render the template within the context