diff options
| author | Gibheer <gibheer@gmail.com> | 2012-11-26 20:11:39 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2012-11-26 21:41:09 +0100 | 
| commit | cb39d8ac909c5c7c5d564c883b6d5bf2c5e26760 (patch) | |
| tree | 7a67ed86ca6f469142bd15b98dc409f5d93f2b26 | |
| parent | 2a1499479a4317b8cccf7f8c12804165f39675b5 (diff) | |
renderer is now able to render templates
| -rw-r--r-- | lib/zero/renderer.rb | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb index ac8d991..473db7c 100644 --- a/lib/zero/renderer.rb +++ b/lib/zero/renderer.rb @@ -65,6 +65,18 @@ module Zero        self      end +    # render a template +    # +    # This method will render the given template, based on the type in the given +    # context. +    # @param name [String] the name of the template +    # @param type [Array] a list of accept types used to find the template +    # @param context [Object] the context in which to evaluate the template +    # @return [String] the rendered content +    def render(name, type, context) +      template(name, type).render(context) +    end +      private      # search in `template_path` for templates beginning with `template_name` @@ -103,5 +115,21 @@ module Zero        return original_map if original_map.respond_to?(:each)        [original_map]      end + +    # get the prepared template for the name and type +    # @api private +    # @param name [String] the name of the template +    # @param type [Array] the types for the template +    # @return [Tilt::Template] a prepared tilt template +    def template(name, types) +      types.each do |type| +        template = templates[name][type] +        unless template.nil? +          return template if template.kind_of?(Tilt::Template) +          return Tilt.new(template) +        end +      end +      raise ArgumentError "No template found for '#{name}'!" +    end    end  end | 
