Class/Module Index [+]

Quicksearch

Cuba::Render

Public Class Methods

setup(app) click to toggle source
# File lib/cuba/render.rb, line 5
def self.setup(app)
  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

Public Instance Methods

partial(template, locals = {}) click to toggle source
# File lib/cuba/render.rb, line 26
def partial(template, locals = {})
  render(template_path(template), locals, settings[:render][:options])
end
render(template, locals = {}, options = {}, &block) click to toggle source

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") }
# File lib/cuba/render.rb, line 46
def render(template, locals = {}, options = {}, &block)
  _cache.fetch(template) {
    Tilt.new(template, 1, options.merge(outvar: '@_output'))
  }.render(self, locals, &block)
end
template_path(template) click to toggle source
# File lib/cuba/render.rb, line 18
def template_path(template)
  "%s/%s.%s" % [
    settings[:render][:views],
    template,
    settings[:render][:template_engine]
  ]
end
view(template, locals = {}, layout = "layout") click to toggle source
# File lib/cuba/render.rb, line 14
def view(template, locals = {}, layout = "layout")
  partial(layout, { content: partial(template, locals) }.merge(locals))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.