diff options
| author | Gibheer <gibheer@gmail.com> | 2012-11-26 08:51:51 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2012-11-26 21:41:09 +0100 | 
| commit | a913aac8268a7ecbb686fba03a3769a547a37524 (patch) | |
| tree | 79c33a08e73356853484a9b9a23a9da77075c269 | |
| parent | 0fd7035a886320a9ec7c11bfd643a99b163944b1 (diff) | |
added more documentation to the renderer
| -rw-r--r-- | lib/zero/renderer.rb | 21 | 
1 files changed, 20 insertions, 1 deletions
| diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb index 31a6e27..ac8d991 100644 --- a/lib/zero/renderer.rb +++ b/lib/zero/renderer.rb @@ -31,7 +31,8 @@ module Zero      #     'json' => ['application/json', 'application/aweomse+json']      #   })      # -    # @param [String] a string to templates +    # @param template_path [String] a string to templates +    # @param type_map [Hash] a map of simple types to complex ones      def initialize(template_path, type_map = {})        @template_path = template_path + '/'        @type_map = type_map @@ -53,6 +54,7 @@ module Zero      # 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. +    # @return [Self] returns the object      def read_template_path!        @templates = Hash.new do |hash, key|          # TODO this is just ugly @@ -65,10 +67,18 @@ module Zero      private +    # search in `template_path` for templates beginning with `template_name` +    # @api private +    # @param template_name [String] the name of the template +    # @return [#each] a list of all templates found      def search_files(template_name)        Dir[template_path + template_name + '**/*.*']      end +    # fill the `datamap` with all variants of files and types found +    # @api private +    # @param dataset [Hash] the hash to fill with values +    # @param file [String] a filename which will be used to fill the hash      def fill_template_type_map(dataset, file)        parts = file.split('.')        read_type(parts[2]).each do |type| @@ -76,10 +86,19 @@ module Zero        end      end +    # gets the type information from a file and converts it to an array of +    # possible matching types +    # @api private +    # @param short_notation [String] a short notation of a type, like `html` +    # @return [Array] a list of matching types, like `text/html`      def read_type(short_notation)        to_type_list(type_map[short_notation] || short_notation)      end +    # convert a map to an array if it is not one +    # @api private +    # @param original_map [Object] the type(s) to convert +    # @return [Array] a list of objects      def to_type_list(original_map)        return original_map if original_map.respond_to?(:each)        [original_map] | 
