module Padrino::Helpers::RenderHelpers

def erb_template(template_path, options={})

erb_template 'users/new'
Renders a erb template based on the relative path
def erb_template(template_path, options={})
  render_template template_path, options.merge(:template_engine => :erb)
end

def haml_template(template_path, options={})

haml_template 'users/new'
Renders a haml template based on the relative path
def haml_template(template_path, options={})
  render_template template_path, options.merge(:template_engine => :haml)
end

def partial(template, options={})

partial 'photo/_item', :collection => @photos
partial 'photo/_item', :object => @photo
Partials implementation which includes collections support
def partial(template, options={})
  options.reverse_merge!(:locals => {}, :layout => false)
  path = template.to_s.split(File::SEPARATOR)
  object_name = path[-1].to_sym
  path[-1] = "_#{path[-1]}"
  template_path = File.join(path)
  raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil?
  if collection = options.delete(:collection)
    options.delete(:object)
    counter = 0
    collection.collect do |member|
      counter += 1
      options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
      render_template(template_path, options.merge(:layout => false))
    end.join("\n")
  else
    if member = options.delete(:object)
      options[:locals].merge!(object_name => member)
    end
    render_template(template_path, options.merge(:layout => false))
  end
end

def render_template(template_path, options={})

options = { :template_engine => 'haml' }
render_template 'users/new'
Renders a template from a file path automatically determining rendering engine
def render_template(template_path, options={})
  template_engine = options.delete(:template_engine) || resolve_template_engine(template_path)
  render template_engine.to_sym, template_path.to_sym, options
end

def resolve_template_engine(template_path)

resolve_template_engine('users/new') => :haml
Returns the template engine (i.e haml) to use for a given template_path
def resolve_template_engine(template_path)
  resolved_template_path = File.join(self.options.views, template_path.to_s + ".*")
  template_file = Dir[resolved_template_path].first
  raise "Template path '#{template_path}' could not be located in views!" unless template_file
  template_engine = File.extname(template_file)[1..-1].to_sym
end