-
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.
+
-
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.
- - (Renderer) initialize(template_path, type_map = {})
+ - (Renderer) initialize(path, context, accept_types)
@@ -324,46 +289,18 @@ then can be used to actually render something.
-
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
-
-
Instance Attribute Details
+
+
+
Class Method Details
+
-
-
-
+
- - (String) template_path
+ + (Object) template_path=(path)
@@ -441,18 +389,19 @@ types, which the clients sends.
-
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.
-
-
-
+
- - (Hash) templates
+ + (Hash) type_map
@@ -502,12 +450,8 @@ 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
@@ -526,7 +470,7 @@ types, which the clients sends.
—
-
the template tree
+
the mapping for types
@@ -539,15 +483,15 @@ types, which the clients sends.
-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
|
@@ -555,12 +499,10 @@ types, which the clients sends.
-
-
-
+
- - (Hash) type_map
+ + (Object) type_map=(map)
@@ -569,18 +511,32 @@ types, which the clients sends.
-
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.
-
Instance Method Details
-
-
- - (Self) read_template_path!
-
-
-
-
-
-
-
-
-
load the template tree
-
-
This method gets all templates in the `template_path` and builds an
-internal tree structure, where templates and types direct the request to
-the wanted template.
-
-
-
-
-
-
-
-
-
-
-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!
-
- @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
-
- |
-
-
-
-
-
-
+
- - (String) render(name, type, context)
+ - (String) render
@@ -724,68 +592,13 @@ the wanted template.
-
render a template
-
-
This method will render the given template, based on the type in the given
-context.
+
render the template within the context
diff --git a/doc/Zero/Request.html b/doc/Zero/Request.html
index ff9118e..03e5591 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 31a2474..8a45ae0 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 d5b6338..603d3d3 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 ce5d000..f2e733d 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 cc531a8..e8c170c 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 28a99aa..2a187d8 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 4114c2c..6ed9127 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 18afe2a..8f95463 100644
--- a/doc/Zero/Router.html
+++ b/doc/Zero/Router.html
@@ -324,7 +324,7 @@
diff --git a/doc/_index.html b/doc/_index.html
index 0aa5fa0..1b45dbc 100644
--- a/doc/_index.html
+++ b/doc/_index.html
@@ -124,6 +124,21 @@
+
+
+
- P
@@ -211,7 +226,7 @@
diff --git a/doc/class_list.html b/doc/class_list.html
index 80ff11d..9e726e9 100644
--- a/doc/class_list.html
+++ b/doc/class_list.html
@@ -45,7 +45,7 @@
diff --git a/doc/file.README.html b/doc/file.README.html
index f8492d1..e684d3a 100644
--- a/doc/file.README.html
+++ b/doc/file.README.html
@@ -67,7 +67,7 @@
web applications.
diff --git a/doc/index.html b/doc/index.html
index f8492d1..e684d3a 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -67,7 +67,7 @@
web applications.
diff --git a/doc/method_list.html b/doc/method_list.html
index f02085b..f610b0d 100644
--- a/doc/method_list.html
+++ b/doc/method_list.html
@@ -391,14 +391,6 @@
-
- #read_template_path!
-
- Zero::Renderer
-
-
-
-
- -
#render
Zero::Renderer
@@ -406,7 +398,7 @@
- -
+
-
renderer
Zero::Controller
@@ -414,7 +406,7 @@
- -
+
-
#renderer
Zero::Controller
@@ -422,7 +414,7 @@
- -
+
-
renderer=
Zero::Controller
@@ -430,7 +422,7 @@
- -
+
-
#response
Zero::Controller
@@ -438,7 +430,7 @@
- -
+
-
#server
Zero::Request
@@ -446,7 +438,7 @@
- -
+
-
#software
Zero::Request::Server
@@ -454,7 +446,7 @@
- -
+
-
#status
Zero::Response
@@ -462,16 +454,8 @@
- -
- #template_path
-
- Zero::Renderer
-
-
-
-
-
- #templates
+ template_path=
Zero::Renderer
@@ -487,7 +471,7 @@
-
- #type_map
+ type_map
Zero::Renderer
@@ -495,6 +479,14 @@
-
+ type_map=
+
+ Zero::Renderer
+
+
+
+
+ -
#types
Zero::Request::Accept
@@ -502,7 +494,7 @@
- -
+
-
#user_agent
Zero::Request::Client
diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html
index f402421..124c135 100644
--- a/doc/top-level-namespace.html
+++ b/doc/top-level-namespace.html
@@ -103,7 +103,7 @@
--
cgit v1.2.3-70-g09d2