Sha256: 41b82296dec427b8550861807f2f1a40596ad6f1b062d11a83f7e3e935cd4287

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'sinatra/base'
require 'sinatra_more'
require 'haml'

class RenderUser
  attr_accessor :name
  def initialize(name); @name = name; end
end

class RenderDemo < Sinatra::Base
  register Sinatra::RenderPlugin
  
  configure do
    set :root, File.dirname(__FILE__)
  end
  
  # haml_template
  get '/render_haml' do
    @template = 'haml'
    haml_template 'haml/test'
  end
  
  # erb_template
  get '/render_erb' do
    @template = 'erb'
    erb_template 'erb/test'
  end
  
  # render_template with explicit engine
  get '/render_template/:engine' do
    @template = params[:engine]
    render_template "template/#{@template}_template", :template_engine => @template
  end
  
  # render_template without explicit engine
  get '/render_template' do
    render_template "template/some_template"
  end
  
  # partial with object
  get '/partial/object' do
    partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
  end
  
  # partial with collection
  get '/partial/collection' do
    partial 'template/user', :collection => [RenderUser.new('John'), RenderUser.new('Billy')], :locals => { :extra => "bar" }
  end
  
  # partial with locals
  get '/partial/locals' do
    partial 'template/user', :locals => { :user => RenderUser.new('John'), :extra => "bar" }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
darkhelmet-sinatra_more-0.3.36 test/fixtures/render_app/app.rb
darkhelmet-sinatra_more-0.3.35 test/fixtures/render_app/app.rb
darkhelmet-sinatra_more-0.3.34 test/fixtures/render_app/app.rb
darkhelmet-sinatra_more-0.3.33 test/fixtures/render_app/app.rb