Class: Wouter::Views

Inherits:
Object
  • Object
show all
Defined in:
lib/wouter/views.rb

Defined Under Namespace

Classes: FileNotFound

Class Method Summary collapse

Class Method Details

.file_finder(dir, template, engine, layout, bind) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wouter/views.rb', line 10

def file_finder(dir, template, engine, layout, bind)
  template_full_path = full_path(template, dir, engine)
  template_data = if Tilt.template_for(template_full_path)
                    Tilt.new(template_full_path).render(bind)
                  else
                    File.read(template_full_path)
                  end

  if layout
    layout_full_path = full_path(layout, dir, engine)
    if Tilt.template_for(layout_full_path)
      Tilt.new(layout_full_path).render(bind) { template_data }
    else
      File.read(layout_full_path) + template_data
    end
  else
    template_data
  end
end

.full_path(file, dir, engine) ⇒ Object

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wouter/views.rb', line 30

def full_path(file, dir, engine)
  file_name = file.to_s + '.' + engine.to_s
  full_path = dir + '/' + file_name

  return full_path if File.exists?(full_path)

  full_path = dir + '/' + file.to_s

  return full_path if File.exists?(full_path)

  raise FileNotFound, "cannot find file: '#{file}' in '#{dir}'"
end