Module: Cuba::Mote

Includes:
Mote::Helpers
Defined in:
lib/cuba/mote.rb

Defined Under Namespace

Classes: NoLayout

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(app) ⇒ Object



7
8
9
10
11
# File 'lib/cuba/mote.rb', line 7

def self.setup(app)
  app.settings[:mote] ||= {}
  app.settings[:mote][:views]  ||= File.expand_path("views", Dir.pwd)
  app.settings[:mote][:layout] ||= "layout"
end

Instance Method Details

#mote_path(template) ⇒ Object



27
28
29
30
31
# File 'lib/cuba/mote.rb', line 27

def mote_path(template)
  return template if template.end_with?(".mote")

  File.join(settings[:mote][:views], "#{template}.mote")
end

#mote_vars(content) ⇒ Object

DEPRECATED: this will be removed in a future version. Use the ‘this` context variable instead.



35
36
37
# File 'lib/cuba/mote.rb', line 35

def mote_vars(content)
  { content: content }
end

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



13
14
15
# File 'lib/cuba/mote.rb', line 13

def partial(template, locals = {})
  mote(mote_path(template), locals.merge(this: self), TOPLEVEL_BINDING)
end

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



23
24
25
# File 'lib/cuba/mote.rb', line 23

def render(template, locals = {}, layout = settings[:mote][:layout])
  res.write view(template, locals, layout)
end

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

Raises:



17
18
19
20
21
# File 'lib/cuba/mote.rb', line 17

def view(template, locals = {}, layout = settings[:mote][:layout])
  raise NoLayout.new(self) unless layout

  partial(layout, locals.merge(mote_vars(partial(template, locals))))
end