From be1afcd114d148dbfedb7a3fc068af64a83b5991 Mon Sep 17 00:00:00 2001
From: Gibheer
This class helps with rendering of content.
+the base renderer for getting render containers
-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.
+This class handles templates and render coontainers, which can be used for +the actual rendering.
-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
-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 call to #render will return the String representation of the template -with all data given.
+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.
set a base path for template search.
+get the path to the templates.
returns the type map.
+get the tree of templates.
save a mapping hash for the type.
+returns the hash of type conversions.
take the path and render the template within the context.
+initializes a new Renderer.
render the template within the context.
+load the template tree.
+render a template.
take the path and 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.
set a base path for template search
+get the path to the templates
-20 -21 -22+46 +47 +48 |
- # File 'lib/zero/renderer.rb', line 20 +# File 'lib/zero/renderer.rb', line 46 -def template_path=(path) - @@path = path + '/' +def template_path + @template_path end |
@@ -439,10 +489,12 @@ with all data given.
returns the type map
++ 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
the mapping for types
+the template tree
-40 -41 -42+50 +51 +52
# File 'lib/zero/renderer.rb', line 40 +# File 'lib/zero/renderer.rb', line 50 -def type_map - @@map ||= {} +def templates + @templates end
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.
+returns the hash of type conversions
-34 -35 -36+43 +44 +45 |
- # File 'lib/zero/renderer.rb', line 34 +# File 'lib/zero/renderer.rb', line 43 -def type_map=(map) - @@map = map +def type_map + @type_map end |
@@ -576,14 +619,15 @@ fitting template.
+
+ # 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.
+ + +
+ + + +82 +83 +84 |
- # File 'lib/zero/renderer.rb', line 57 +# File 'lib/zero/renderer.rb', line 82 -def render - Tilt.new(@path).render(@context) +def render(name, type, context) + template(name, type).render(context) end |
@@ -645,7 +832,7 @@ fitting template.
diff --git a/doc/Zero/Request.html b/doc/Zero/Request.html
index 03e5591..ff9118e 100644
--- a/doc/Zero/Request.html
+++ b/doc/Zero/Request.html
@@ -1467,7 +1467,7 @@
diff --git a/doc/Zero/Request/Accept.html b/doc/Zero/Request/Accept.html
index 8a45ae0..31a2474 100644
--- a/doc/Zero/Request/Accept.html
+++ b/doc/Zero/Request/Accept.html
@@ -603,7 +603,7 @@ from sinatra
diff --git a/doc/Zero/Request/AcceptType.html b/doc/Zero/Request/AcceptType.html
index 603d3d3..d5b6338 100644
--- a/doc/Zero/Request/AcceptType.html
+++ b/doc/Zero/Request/AcceptType.html
@@ -394,7 +394,7 @@
diff --git a/doc/Zero/Request/Client.html b/doc/Zero/Request/Client.html
index f2e733d..ce5d000 100644
--- a/doc/Zero/Request/Client.html
+++ b/doc/Zero/Request/Client.html
@@ -570,7 +570,7 @@
diff --git a/doc/Zero/Request/Parameter.html b/doc/Zero/Request/Parameter.html
index e8c170c..cc531a8 100644
--- a/doc/Zero/Request/Parameter.html
+++ b/doc/Zero/Request/Parameter.html
@@ -480,7 +480,7 @@ parameters) and payload parameters (or POST parameters).
diff --git a/doc/Zero/Request/Server.html b/doc/Zero/Request/Server.html
index 2a187d8..28a99aa 100644
--- a/doc/Zero/Request/Server.html
+++ b/doc/Zero/Request/Server.html
@@ -678,7 +678,7 @@
diff --git a/doc/Zero/Response.html b/doc/Zero/Response.html
index 6ed9127..4114c2c 100644
--- a/doc/Zero/Response.html
+++ b/doc/Zero/Response.html
@@ -714,7 +714,7 @@ Content-Type, Content-Length and body on status code 204 and 304.
diff --git a/doc/Zero/Router.html b/doc/Zero/Router.html
index 8f95463..18afe2a 100644
--- a/doc/Zero/Router.html
+++ b/doc/Zero/Router.html
@@ -324,7 +324,7 @@
--
cgit v1.2.3-70-g09d2