Module: Conjoin::Cuba::Render

Includes:
Cuba::Render
Defined in:
lib/conjoin/cuba.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(app) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/conjoin/cuba.rb', line 50

def self.setup(app)
  app.settings[:render] ||= {}
  app.settings[:render][:template_engine] ||= "slim"
  app.settings[:render][:layout] ||= "layouts/app"
  app.settings[:render][:views] ||= "#{app.root}/app/views"
  app.settings[:render][:options] ||= {
    default_encoding: Encoding.default_external
  }
end

Instance Method Details

#original_partialObject



60
# File 'lib/conjoin/cuba.rb', line 60

alias original_partial partial

#partial(template, locals = {}) ⇒ Object



66
67
68
69
# File 'lib/conjoin/cuba.rb', line 66

def partial template, locals = {}
  partial_template = template.to_s.gsub(/([a-zA-Z_]+)$/, '_\1')
  render(template_path(partial_template), locals, settings[:render][:options])
end

#view(template, locals = {}, layout = ) ⇒ Object



62
63
64
# File 'lib/conjoin/cuba.rb', line 62

def view(template, locals = {}, layout = settings[:render][:layout])
  original_partial(layout, { content: original_partial(template, locals) }.merge(locals))
end