lib/cuba/render.rb in cuba-3.0.1.rc2 vs lib/cuba/render.rb in cuba-3.1.0.rc1

- old
+ new

@@ -1,21 +1,32 @@ require "tilt" class Cuba module Render def self.setup(app) - app.settings[:template_engine] ||= "erb" - app.settings[:views] ||= File.expand_path("views", Dir.pwd) + app.settings[:render] ||= {} + app.settings[:render][:template_engine] ||= "erb" + app.settings[:render][:views] ||= File.expand_path("views", Dir.pwd) + app.settings[:render][:options] ||= { + default_encoding: Encoding.default_external + } end def view(template, locals = {}, layout = "layout") partial(layout, { content: partial(template, locals) }.merge(locals)) end + def template_path(template) + "%s/%s.%s" % [ + settings[:render][:views], + template, + settings[:render][:template_engine] + ] + end + def partial(template, locals = {}) - render("#{settings[:views]}/#{template}.#{settings[:template_engine]}", - locals, default_encoding: Encoding.default_external) + render(template_path(template), locals, settings[:render][:options]) end # Render any type of template file supported by Tilt. # # @example @@ -32,10 +43,10 @@ # # Renders in layout # render("layout.haml") { render("home.haml") } # def render(template, locals = {}, options = {}, &block) _cache.fetch(template) { - Tilt.new(template, 1, options.merge(outvar: '@_output') + Tilt.new(template, 1, options.merge(outvar: '@_output')) }.render(self, locals, &block) end # @private Used internally by #render to cache the # Tilt templates.