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, bind) ⇒ Object



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

def self.file_finder(dir, template, engine, bind)
  file_name = template.to_s + '.' + engine.to_s
  full_path = dir + '/' + file_name

  return Tilt.new(full_path).render(bind) if File.exists?(full_path)

  full_path = dir + '/' + template.to_s

  if Tilt.template_for(full_path)
    Tilt.new(full_path).render(bind)
  else
    if File.exists?(full_path)
      File.read(full_path)
    else
      raise FileNotFound, "could not find file: #{full_path}"
    end
  end
end