Browse files

Use sinatra contrib respond with instead of respond_to gem

  • Loading branch information...
1 parent e7872a6 commit c998bde72177ee60dd1a319fcf522df977d72784 @smgt smgt committed Sep 1, 2012
View
3 Gemfile
@@ -1,6 +1,7 @@
source :rubygems
gem 'sinatra'
-gem 'sinatra-respond_to'
+gem 'sinatra-contrib'
gem 'haml'
gem 'json'
gem 'sass'
+gem 'thin'
View
44 app.rb
@@ -1,46 +1,56 @@
-require 'rubygems'
+require 'sinatra'
require 'sinatra/base'
-require 'sinatra/respond_to'
+require 'sinatra/respond_with'
+require 'sinatra/reloader' if development?
require 'haml'
require 'sass'
require 'json'
require './tracker'
-
class Timesheet < Sinatra::Base
- register Sinatra::RespondTo
+ register Sinatra::RespondWith
- set :server, %w[webrick]
- set :haml, :format => :html5
- set :port, 1337
+ configure :development do
+ register Sinatra::Reloader
+ enable :logging
+ end
+
+ configure :development, :production do
+ set :haml, :format => :html5
+ set :port, 1337
+ set :server, "thin"
+ set :sessions, true
+ end
+
+ before "*.:format" do
+ content_type params[:format]
+ end
get "/" do
redirect '/index'
end
- get "/index" do
+ get "/index.?:format?" do
@summary = Tracker.summary
@running = Tracker.running?
respond_to do |format|
format.html { haml :index }
format.json { @summary.to_json }
- format.text { @summary.inspect }
format.txt { @summary.inspect }
end
end
- get "/history" do
+ get "/history.?:format?" do
@history = Tracker.history
respond_to do |format|
format.json { @history.to_json}
format.html { haml :history}
- format.text { @history.inspect }
format.txt { @history.inspect }
end
end
- post "/index" do
+ post "/index.?:format?" do
status = "false"
if params[:cmd].eql?('start')
error = "Already running" if Tracker.running?
@@ -55,19 +65,15 @@ class Timesheet < Sinatra::Base
respond_to do |format|
format.html { redirect '/' }
format.json { response.to_json }
- format.text { response.inspect }
format.txt { response.inspect }
end
end
- get '/master' do
+ get '/master.css', :provides => [:css] do
respond_to do |format|
format.css { sass :master }
end
- end
-
-end
+ end
-if __FILE__ == $0
- Timesheet.run!
+ run! if app_file == $0
end
View
4 config.ru
@@ -1,3 +1,3 @@
-$: << File.dirname(__FILE__)
-require "app.rb"
+require "sinatra"
+require "./app.rb"
run Timesheet
View
0 views/history.html.haml → views/history.haml
File renamed without changes.
View
0 views/index.html.haml → views/index.haml
File renamed without changes.
View
0 views/layout.html.haml → views/layout.haml
File renamed without changes.
View
0 views/master.css.sass → views/master.sass
File renamed without changes.

0 comments on commit c998bde

Please sign in to comment.