Sha256: e5232026a0e68e98fd3835aaceb4342bbd09b09260136fbdad07b49732a883af
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require "tilt" class Cuba module Render def self.setup(app) app.settings[:render] ||= {} app.settings[:render][:template_engine] ||= "erb" app.settings[:render][:layout] ||= "layout" 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 = settings[:render][: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(template_path(template), locals, settings[:render][:options]) end # Render any type of template file supported by Tilt. # # @example # # # Renders home, and is assumed to be HAML. # render("home.haml") # # # Renders with some local variables # render("home.haml", site_name: "My Site") # # # Renders with HAML options # render("home.haml", {}, ugly: true, format: :html5) # # # 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')) }.render(self, locals, &block) end # @private Used internally by #render to cache the # Tilt templates. def _cache Thread.current[:_cache] ||= Tilt::Cache.new end private :_cache end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cuba-3.1.1 | lib/cuba/render.rb |