class Wouter::Views

Public Class Methods

file_finder(dir, template, engine, layout, bind) click to toggle source
# 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) click to toggle source
# 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