Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
Use sinatra contrib respond with instead of respond_to gem
Browse files Browse the repository at this point in the history
  • Loading branch information
smgt committed Sep 1, 2012
1 parent e7872a6 commit c998bde
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source :rubygems
gem 'sinatra'
gem 'sinatra-respond_to'
gem 'sinatra-contrib'
gem 'haml'
gem 'json'
gem 'sass'
gem 'thin'
44 changes: 25 additions & 19 deletions app.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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
4 changes: 2 additions & 2 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$: << File.dirname(__FILE__)
require "app.rb"
require "sinatra"
require "./app.rb"
run Timesheet
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c998bde

Please sign in to comment.