Module: Hobbit::Render

Defined in:
lib/hobbit/render.rb

Instance Method Summary collapse

Instance Method Details

#default_layoutObject



5
6
7
# File 'lib/hobbit/render.rb', line 5

def default_layout
  "#{layouts_path}/application.#{template_engine}"
end

#find_template(template) ⇒ Object



9
10
11
# File 'lib/hobbit/render.rb', line 9

def find_template(template)
  "#{views_path}/#{template}.#{template_engine}"
end

#layouts_pathObject



13
14
15
# File 'lib/hobbit/render.rb', line 13

def layouts_path
  "#{views_path}/layouts"
end

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



17
18
19
20
# File 'lib/hobbit/render.rb', line 17

def partial(template, locals = {}, options = {}, &block)
  template = find_template "_#{template}"
  _render template, locals, options, &block
end

#render(template, locals = {}, options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hobbit/render.rb', line 22

def render(template, locals = {}, options = {}, &block)
  template = find_template template
  layout = default_layout
  if options.include? :layout
    layout = options.delete :layout
  end
  if layout
    _render(layout, locals, options) { _render(template, locals, options) }
  else
    _render template, locals, options
  end
end

#template_engineObject



35
36
37
# File 'lib/hobbit/render.rb', line 35

def template_engine
  'erb'
end

#views_pathObject



39
40
41
# File 'lib/hobbit/render.rb', line 39

def views_path
  'views'
end