From cb39d8ac909c5c7c5d564c883b6d5bf2c5e26760 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 26 Nov 2012 20:11:39 +0100 Subject: renderer is now able to render templates --- lib/zero/renderer.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3-70-g09d2