From be1afcd114d148dbfedb7a3fc068af64a83b5991 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 26 Nov 2012 21:45:33 +0100 Subject: refreshed documentation --- doc/Zero.html | 4 +- doc/Zero/Controller.html | 2 +- doc/Zero/Renderer.html | 463 +++++++++++++++++++++++++++------------ doc/Zero/Request.html | 2 +- doc/Zero/Request/Accept.html | 2 +- doc/Zero/Request/AcceptType.html | 2 +- doc/Zero/Request/Client.html | 2 +- doc/Zero/Request/Parameter.html | 2 +- doc/Zero/Request/Server.html | 2 +- doc/Zero/Response.html | 2 +- doc/Zero/Router.html | 2 +- doc/_index.html | 17 +- doc/class_list.html | 2 +- doc/file.README.html | 2 +- doc/index.html | 2 +- doc/method_list.html | 44 ++-- doc/top-level-namespace.html | 2 +- 17 files changed, 367 insertions(+), 187 deletions(-) diff --git a/doc/Zero.html b/doc/Zero.html index b7de645..eeaf9fd 100644 --- a/doc/Zero.html +++ b/doc/Zero.html @@ -92,7 +92,7 @@ - Classes: Controller, FileNotFoundError, Renderer, Request, Response, Router + Classes: Controller, Renderer, Request, Response, Router

@@ -121,7 +121,7 @@ diff --git a/doc/Zero/Controller.html b/doc/Zero/Controller.html index a4e6a0c..85b2540 100644 --- a/doc/Zero/Controller.html +++ b/doc/Zero/Controller.html @@ -607,7 +607,7 @@ the request before rendering stuff.

diff --git a/doc/Zero/Renderer.html b/doc/Zero/Renderer.html index 4ce1cee..0ff7fb7 100644 --- a/doc/Zero/Renderer.html +++ b/doc/Zero/Renderer.html @@ -102,22 +102,22 @@

Overview

-

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.

@@ -129,21 +129,13 @@ with all data given.

- - - - -

- Class Method Summary - (collapse) -

- - + + + +

Instance Method Summary @@ -224,7 +235,7 @@ with all data given.

  • - - (Renderer) initialize(path, context, accept_types) + - (Renderer) initialize(template_path, type_map = {}) @@ -241,7 +252,7 @@ with all data given.

    -

    take the path and render the template within the context.

    +

    initializes a new Renderer.

  • @@ -250,7 +261,7 @@ with all data given.

  • - - (String) render + - (Self) read_template_path! @@ -265,7 +276,31 @@ with all data given.

    -

    render the template within the context.

    +

    load the template tree.

    +
    + +
  • + + +
  • + + + - (String) render(name, type, context) + + + + + + + + + + + + + +
    +

    render a template.

  • @@ -280,7 +315,7 @@ with all data given.

    - - (Renderer) initialize(path, context, accept_types) + - (Renderer) initialize(template_path, type_map = {}) @@ -289,18 +324,46 @@ with all data given.

    -

    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.

    -

    Parameters:

    + +
    +

    Examples:

    + + +

    +

    create a simple renderer

    +

    + +
    Renderer.new('app/templates')
    +
    + + +

    +

    create a renderer with a small map

    +

    + +
    Renderer.new('app', {
    +  'html' => ['text/html', 'application/html+xml'],
    +  'json' => ['application/json', 'application/aweomse+json']
    +})
    +
    + +
    +

    Parameters:

    • - path + template_path (String) @@ -309,38 +372,29 @@ with all data given.

      -

      the relative path to the template

      +

      a string to templates

    • - context + type_map - (Object) + (Hash) + + (defaults to: {})
      -

      the object to process on

      +

      a map of simple types to complex ones

    • -
    • - - accept_types - - - - - - -
    • -
    @@ -350,19 +404,17 @@ with all data given.

     
     
    -49
    -50
    -51
    -52
    -53
    +36 +37 +38 +39 -
    # File 'lib/zero/renderer.rb', line 49
    +      
    # File 'lib/zero/renderer.rb', line 36
     
    -def initialize(path, context, accept_types)
    -  accept_types ||= Request::Accept.new('text/html')
    -  @path    = find_template(path, accept_types)
    -  @context = context
    +def initialize(template_path, type_map = {})
    +  @template_path = template_path + '/'
    +  @type_map = type_map
     end
     
    @@ -372,15 +424,15 @@ with all data given.

    - -
    -

    Class Method Details

    - +
    +

    Instance Attribute Details

    + +
    -

    +

    - + (Object) template_path=(path) + - (String) template_path (readonly) @@ -389,19 +441,18 @@ with all data given.

    -

    set a base path for template search

    +

    get the path to the templates

    -

    Parameters:

    -
      + +

      Returns:

      +
      • - path - (String) @@ -409,29 +460,28 @@ with all data given.

        -

        the path to the template base dir

        +

        the base template path

      -
    @@ -439,10 +489,12 @@ with all data given.

     
     
    -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
     
    + +
    -

    +

    - + (Hash) type_map + - (Hash) templates (readonly) @@ -450,8 +502,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

    @@ -470,7 +526,7 @@ with all data given.

    -

    the mapping for types

    +

    the template tree

    @@ -483,15 +539,15 @@ with all data given.

     
     
    -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
     
    @@ -499,10 +555,12 @@ with all data given.

    + +
    -

    +

    - + (Object) type_map=(map) + - (Hash) type_map (readonly) @@ -511,32 +569,18 @@ with all data given.

    -

    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

    -
    -

    Examples:

    - - -
    Zero::Renderer.map = {'text/html' => 'html'}
    -
    - -
    -

    Parameters:

    -
      +

      Returns:

      +
      • - map - (Hash) @@ -544,29 +588,28 @@ fitting template.

        -

        maps the content type to a simple representation

        +

        type conversion

      -
    @@ -576,14 +619,15 @@ fitting template.

    +

    Instance Method Details

    -

    +

    - - (String) render + - (Self) read_template_path! @@ -592,7 +636,11 @@ fitting template.

    -

    render the template within the context

    +

    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.

    @@ -605,13 +653,13 @@ fitting template.

  • - (String) + (Self)
    -

    the rendered template

    +

    returns the object

  • @@ -624,15 +672,154 @@ fitting template.

     
     
    -57
     58
    -59
    +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 + +
    + +
     
     
    -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
     
    +
    # 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
    +
    +
    +
    + +
    +

    + + - (String) render(name, type, context) + + + + + +

    +
    + +

    render a template

    + +

    This method will render the given template, based on the type in the given +context.

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + name + + + (String) + + + + — +
      +

      the name of the template

      +
      + +
    • + +
    • + + type + + + (Array) + + + + — +
      +

      a list of accept types used to find the template

      +
      + +
    • + +
    • + + context + + + (Object) + + + + — +
      +

      the context in which to evaluate the template

      +
      + +
    • + +
    + +

    Returns:

    +
      + +
    • + + + (String) + + + + — +
      +

      the rendered content

      +
      + +
    • + +
    + +
    + + @@ -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 @@ diff --git a/doc/_index.html b/doc/_index.html index 1b45dbc..0aa5fa0 100644 --- a/doc/_index.html +++ b/doc/_index.html @@ -124,21 +124,6 @@ - - -
    • P
      • @@ -226,7 +211,7 @@ diff --git a/doc/class_list.html b/doc/class_list.html index 9e726e9..80ff11d 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 e684d3a..f8492d1 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 e684d3a..f8492d1 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 f610b0d..f02085b 100644 --- a/doc/method_list.html +++ b/doc/method_list.html @@ -391,7 +391,7 @@
      • - #render + #read_template_path! Zero::Renderer @@ -399,6 +399,14 @@
      • + #render + + Zero::Renderer + +
      • + + +
      • renderer Zero::Controller @@ -406,7 +414,7 @@
      • -
      • +
      • #renderer Zero::Controller @@ -414,7 +422,7 @@
      • -
      • +
      • renderer= Zero::Controller @@ -422,7 +430,7 @@
      • -
      • +
      • #response Zero::Controller @@ -430,7 +438,7 @@
      • -
      • +
      • #server Zero::Request @@ -438,7 +446,7 @@
      • -
      • +
      • #software Zero::Request::Server @@ -446,7 +454,7 @@
      • -
      • +
      • #status Zero::Response @@ -454,8 +462,16 @@
      • +
      • + #template_path + + Zero::Renderer + +
      • + +
      • - template_path= + #templates Zero::Renderer @@ -471,7 +487,7 @@
      • - type_map + #type_map Zero::Renderer @@ -479,14 +495,6 @@
      • - type_map= - - Zero::Renderer - -
      • - - -
      • #types Zero::Request::Accept @@ -494,7 +502,7 @@
      • -
      • +
      • #user_agent Zero::Request::Client diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html index 124c135..f402421 100644 --- a/doc/top-level-namespace.html +++ b/doc/top-level-namespace.html @@ -103,7 +103,7 @@ -- cgit v1.2.3-70-g09d2
    +
    +
    +
    +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