From 46739a8a2494f7b3e8ae83ce3caeee078378a473 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 27 Nov 2012 06:40:49 +0100 Subject: Revert "refreshed documentation" This reverts commit be1afcd114d148dbfedb7a3fc068af64a83b5991. --- 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, 187 insertions(+), 367 deletions(-) diff --git a/doc/Zero.html b/doc/Zero.html index eeaf9fd..b7de645 100644 --- a/doc/Zero.html +++ b/doc/Zero.html @@ -92,7 +92,7 @@ - Classes: Controller, Renderer, Request, Response, Router + Classes: Controller, FileNotFoundError, Renderer, Request, Response, Router

@@ -121,7 +121,7 @@ diff --git a/doc/Zero/Controller.html b/doc/Zero/Controller.html index 85b2540..a4e6a0c 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 0ff7fb7..4ce1cee 100644 --- a/doc/Zero/Renderer.html +++ b/doc/Zero/Renderer.html @@ -102,22 +102,22 @@

Overview

-

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.

@@ -129,13 +129,21 @@ then can be used to actually render something.

-

Instance Attribute Summary (collapse)

-

Instance Method Summary @@ -235,7 +224,7 @@ then can be used to actually render something.

  • - - (Renderer) initialize(template_path, type_map = {}) + - (Renderer) initialize(path, context, accept_types) @@ -252,7 +241,7 @@ then can be used to actually render something.

    -

    initializes a new Renderer.

    +

    take the path and render the template within the context.

  • @@ -261,7 +250,7 @@ then can be used to actually render something.

  • - - (Self) read_template_path! + - (String) render @@ -276,31 +265,7 @@ then can be used to actually render something.

    -

    load the template tree.

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

    render a template.

    +

    render the template within the context.

  • @@ -315,7 +280,7 @@ then can be used to actually render something.

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

    - -
    -

    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:

    +

    Parameters:

    • - template_path + path (String) @@ -372,29 +309,38 @@ types, which the clients sends.

      -

      a string to templates

      +

      the relative path to the template

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

      a map of simple types to complex ones

      +

      the object to process on

    • +
    • + + accept_types + + + + + + +
    • +
    @@ -404,17 +350,19 @@ types, which the clients sends.

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

    -
    -

    Instance Attribute Details

    + +
    +

    Class Method Details

    + - -
    -

    +

    - - (String) template_path (readonly) + + (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

    - -

    Returns:

    -
      +

      Parameters:

      +
      • + path + (String) @@ -460,28 +409,29 @@ types, which the clients sends.

        -

        the base template path

        +

        the path to the template base dir

      +
    @@ -489,12 +439,10 @@ types, which the clients sends.

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

    +

    - - (Hash) templates (readonly) + + (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 (readonly) + + (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.

    -

    Returns:

    -
      +
      +

      Examples:

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

      Parameters:

      +
      • + map + (Hash) @@ -588,28 +544,29 @@ types, which the clients sends.

        -

        type conversion

        +

        maps the content type to a simple representation

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

    - - -
    -
    -
    - -

    Returns:

    -
      - -
    • - - - (Self) - - - - — -
      -

      returns the object

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

    +

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

    -

    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:

      @@ -798,7 +611,7 @@ context.

      -

      the rendered content

      +

      the rendered template

      @@ -811,15 +624,15 @@ context.

       
       
      -82
      -83
      -84
      +57 +58 +59 -
      # File 'lib/zero/renderer.rb', line 82
      +      
      # File 'lib/zero/renderer.rb', line 57
       
      -def render(name, type, context)
      -  template(name, type).render(context)
      +def render
      +  Tilt.new(@path).render(@context)
       end
       
      @@ -832,7 +645,7 @@ 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 @@ + + +