Skip to content

Instantly share code, notes, and snippets.

@oshow
Created November 16, 2011 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshow/1369671 to your computer and use it in GitHub Desktop.
Save oshow/1369671 to your computer and use it in GitHub Desktop.
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