Create a gist now

Instantly share code, notes, and snippets.

@oshow /app2.rb
Created Nov 16, 2011

What would you like to do?
for Rubyist Magazine 0036
# encoding: utf-8
require 'rubygems'
require 'sinatra/base'
require 'sinatra/reloader'
require 'rack/rewrite'
require 'padrino-helpers'
require 'padrino-core'
require 'padrino-cache'
require 'haml'
class App < Sinatra::Base
enable :inline_templates
disable :logging
# configure :development do
# set :server, "webrick"
# register Sinatra::Reloader
# end
set :app_name, "App"
register Padrino::Routing
register Padrino::Cache
enable :caching
register Padrino::Helpers
use Padrino::Logger::Rack, "/"
use Rack::Rewrite do
rewrite %r{^/song_for/(.*)}, '/name/$1'
end
get '/' do
haml :index
end
get '/name/:name' do
@name = params[:name]
@title = "Song for #{@name}"
haml "#{@name}'s Way"
end
get '/heavy_contents', :cache => true do
expires_in 60 # 60 秒でキャッシュクリア
sleep 5 # とても重い処理の代わり
"Process done!"
end
end
App.run!
__END__
@@ layout
!!! 5
%html
%head
%title= yield_content(:title) || @title
%body
%h1= yield_content(:header) || @title
%div= yield
@@ index
- content_for :title do
This is title from helper
- content_for :header do
This is header from helper
%p My Way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment