Module: Kaffe::Render

Includes:
Tilt::CompileSite
Included in:
Base
Defined in:
lib/kaffe/render.rb

Instance Method Summary collapse

Instance Method Details

#find_template(views, name, engine) ⇒ Object



35
36
37
38
39
# File 'lib/kaffe/render.rb', line 35

def find_template(views, name, engine)
  Tilt.mappings.each do |ext, engines|
    yield ::File.join(views, "#{name}.#{ext}")
  end
end

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kaffe/render.rb', line 8

def render(template, options: {}, &block)
  local = options.delete(:locals) || {}
  views = options.delete(:views) || settings.views || "./views"
  layout = options[:layout] || settings.layout || :layout

  case template
  when Symbol
    path = nil
    found = false
    find_template(views, template, engine) do |file|
      puts "testing #{file}"
      if found = File.exists?(file)
        path = file
        break
      end
    end
    raise "Could not find Template #{template}" unless found
    t = templates.fetch(path) { Tilt.new path }
    output = t.render(self, &block)

    if layout
      return render(engine, layout, layout: false) { output }
    end
    return output
  end
end

#templatesObject



4
5
6
# File 'lib/kaffe/render.rb', line 4

def templates
  @templates ||= Tilt::Cache.new
end