Module: Cuba::Mote

Includes:
Mote::Helpers
Defined in:
lib/cuba/contrib/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
12
# File 'lib/cuba/contrib/mote.rb', line 7

def self.setup(app)
  app.plugin Cuba::Settings

  app.set :views,  File.expand_path("views", Dir.pwd)
  app.set :layout, "layout"
end

Instance Method Details

#mote_path(template) ⇒ Object



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

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

  File.expand_path("#{template}.mote", settings.views)
end

#mote_vars(content) ⇒ Object



33
34
35
# File 'lib/cuba/contrib/mote.rb', line 33

def mote_vars(content)
  { content: content, session: session }
end

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



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

def partial(template, locals = {})
  mote(mote_path(template), locals)
end

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

Raises:



18
19
20
21
22
23
24
25
# File 'lib/cuba/contrib/mote.rb', line 18

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

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