summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/zero/renderer.rb28
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