Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Sinatra app instead of Monrb app as instructed by the Heroku guy …
…at CodeConf 2011 Signed-off-by: Ilya Shindyapin <ilya@shindyapin.com>
- Loading branch information
Showing
24 changed files
with
7,306 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ sinatra | |
tilt | ||
data_mapper | ||
dm-postgres-adapter | ||
dm-sqlite-adapter | ||
dm-sqlite-adapter | ||
haml | ||
content_for2 | ||
json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
.idea | ||
db/* | ||
tmp/* | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Here is a sample/template sinatra application ready for deployment to [Heroku](http://heroku.com). | ||
|
||
**NOTE** This is for heroku.com and not herokugarden.com | ||
|
||
* Create an acount in seconds at [Heroku](http://heroku.com/signup). | ||
* Install the gem `sudo gem install heroku`. | ||
* If you do not have an SSH key | ||
you'll need to [generate | ||
one](http://heroku.com/docs/index.html#_setting_up_ssh_public_keys) | ||
and [tell Heroku about | ||
it](http://heroku.com/docs/index.html#_manage_keys_on_heroku) | ||
* Clone this repo `git clone git://github.com/sinatra/heroku-sinatra-app [appname]` | ||
* `cd /path/to/project` | ||
* `heroku create [optional-app-name]` (You can rename your app with `heroku rename`) | ||
* `git push heroku master` | ||
|
||
**NOTES** | ||
|
||
The small amount of code is heavily commented. If you have questions | ||
or comments please use [the channels provided](http://www.sinatrarb.com/contributing.html) by the Sinatra community as | ||
we at Heroku are heavily involved in Sinatra. Please use the Heroku [mailing list](http://groups.google.com/group/heroku) if you | ||
have non Sinatra questions. | ||
|
||
See [these guidelines](http://www.sinatrarb.com/contributing.html) for | ||
contributing or bugs. | ||
|
||
Happy Development and Deploying! | ||
|
||
Sincerely, | ||
The Heroku Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'dm-core' | ||
require 'dm-migrations' | ||
require 'dm-migrations' | ||
require 'dm-timestamps' | ||
require 'logger' | ||
require 'haml' | ||
require 'sinatra/content_for2' | ||
require 'json/pure' | ||
|
||
configure :development do | ||
DataMapper::Logger.new('tmp/seatr-debug.log', :debug) | ||
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/db/development.db") | ||
end | ||
|
||
configure :production do | ||
# Configure stuff here you'll want to | ||
# only be run at Heroku at boot | ||
|
||
# TIP: You can get you database information | ||
# from ENV['DATABASE_URI'] (see /env route below) | ||
end | ||
|
||
class Seat | ||
include DataMapper::Resource | ||
|
||
property :id, Serial | ||
property :loc, String | ||
property :twitter, String | ||
property :taken, Boolean, :default => true | ||
property :created, DateTime | ||
property :updated, DateTime | ||
|
||
end | ||
|
||
DataMapper.finalize | ||
#DataMapper.auto_migrate! | ||
DataMapper.auto_upgrade! | ||
|
||
#=end | ||
|
||
get "/" do | ||
@seats = Seat.all | ||
@title = "Open Seats" | ||
if @seats.count == 0 then | ||
redirect '/create' | ||
end | ||
haml :home | ||
end | ||
|
||
get "/create" do | ||
rows = 17 | ||
cols = 21 | ||
|
||
for i in 0..rows | ||
for j in 0..cols | ||
|
||
s = Seat.new( | ||
:loc => "seat-#{i}-#{j}", | ||
:taken => true, | ||
:created => Time.now | ||
) | ||
|
||
s.save | ||
|
||
end | ||
end | ||
|
||
redirect '/' | ||
|
||
end | ||
|
||
get "/seats.json" do | ||
@seats = Seat.all(:order => [ :loc.asc ]) | ||
data = {} | ||
|
||
currentRow = nil | ||
temp = nil | ||
@seats.each do |seat| | ||
=begin | ||
if seat.row != currentRow then | ||
data[seat.row] = {} | ||
currentRow = seat.row | ||
end | ||
=end | ||
data[seat.loc] = {} | ||
|
||
#data[seat.row][seat.col] = seat.taken ? (seat.twitter ? seat.twitter : "x") : nil | ||
data[seat.loc]["taken"] = seat.taken | ||
data[seat.loc]["twitter"] = seat.twitter | ||
|
||
end | ||
|
||
content_type :json | ||
data.to_json | ||
end | ||
|
||
get "/update/:loc/mark/:taken[/]?" do | ||
seat = Seat.first(:loc => params[:loc]) | ||
#"#{seat.inspect}" | ||
seat.update(:taken => (params[:taken] != 'open'), :twitter => params[:taken], :updated => Time.now) | ||
if seat.save then | ||
#redirect '/' | ||
"#{seat.taken}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'codeconf-2011-open-seats' | ||
|
||
## There is no need to set directories here anymore; | ||
## Just run the application | ||
|
||
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
body { | ||
background: #111111; | ||
color: #ddd; | ||
font-family: "Helvetica Neue", Helvetica, Liberation Sans, Arial, sans-serif; | ||
} | ||
|
||
#page { | ||
width: 960px; | ||
margin: 0 25px; | ||
} | ||
|
||
h1{ | ||
color: #aaa; | ||
text-align: center; | ||
} | ||
|
||
h1 img { | ||
width: 72px; | ||
height: 72px; | ||
} | ||
|
||
h1 span { | ||
font-size: 2em; | ||
} | ||
|
||
td { | ||
width: 40px; | ||
height: 40px; | ||
text-align: center; | ||
background-color: #FF8500; | ||
} | ||
|
||
td img { | ||
width: 36px; | ||
height: 36px; | ||
} | ||
|
||
td.filled { | ||
background-color: #333333; | ||
} | ||
|
||
td.isle { | ||
background: none; | ||
width: 72px; | ||
} | ||
|
||
td.seat { | ||
cursor: pointer; | ||
} | ||
|
||
#mark-seat-form { | ||
display: none; | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
$(function () { | ||
|
||
|
||
$('#mark-seat-form button').bind('click', function () { | ||
var value = $('#mark-seat-form input[name=status]:checked')[0].value; | ||
var seatId = $('#mark-seat-form input[name=seat-id]').val(); | ||
if (value === 'twitter') { | ||
value = $('#mark-seat-form input[name=twitter-username]').val(); | ||
} | ||
|
||
var url = '/update/'+seatId+'/mark/'+ value +'/'; | ||
$.get(url, updateFromServer); | ||
console.log(url); | ||
$('#mark-seat-form').slideUp('slow'); | ||
return false; | ||
}); | ||
|
||
var markSeat = function(seat, seatId) { | ||
|
||
var taken = 'taken'; | ||
var $seat = $(seat); | ||
var value = null; | ||
if ( $seat.hasClass('filled') ) { | ||
value = 'nottaken'; | ||
} else { | ||
value = 'taken'; | ||
} | ||
|
||
$('#mark-seat-form input[name=seat-id]').val(seatId); | ||
$('#mark-seat-form').slideDown(); | ||
|
||
}; | ||
|
||
var rows = 17; | ||
var cols = 21; | ||
var i, j; | ||
var tr, td, data; | ||
|
||
|
||
for (i = 0; i < rows; i++) { | ||
tr = $('<tr></tr>'); | ||
for (j = 0; j < cols; j++) { | ||
|
||
var seatId = 'seat-'+i+'-'+j; | ||
td = $('<td id="'+seatId+'"></td>'); | ||
if (j === 10) { | ||
td.addClass('isle'); | ||
} else { | ||
td.addClass('seat').click( (function (seatId) { return function () { markSeat(this, seatId); }; }(seatId)) ); | ||
} | ||
|
||
tr.append(td); | ||
} | ||
|
||
$('#openseats').append(tr); | ||
} | ||
|
||
|
||
|
||
var displayData = function (data) { | ||
var i, j; | ||
var td; | ||
for (i = 0; i < rows; i++) { | ||
for (j = 0; j < cols; j++) { | ||
var seatId = 'seat-'+i+'-'+j; | ||
td = $('#'+seatId); | ||
//console.log(data[seatId]); | ||
if (data[seatId].taken) { | ||
td.addClass('filled'); | ||
if (data[seatId].twitter) { | ||
if (td.find('img').length === 0) { | ||
//console.log(data[seatId].twitter); | ||
td.append('<img>'); | ||
} | ||
var imgSrc ='https://api.twitter.com/1/users/profile_image/' + data[seatId].twitter; | ||
//console.log(imgSrc); | ||
td.find('img').attr({ | ||
'src': imgSrc, | ||
'title': '@'+data[seatId].twitter, | ||
'alt': '@'+data[seatId].twitter | ||
}).css('opacity', .35).hover(function(){ | ||
$(this).css('opacity', 1); | ||
}, function(){ | ||
$(this).css('opacity', .35); | ||
}); | ||
} | ||
} else { | ||
td.removeClass('filled').find('img').remove(); | ||
} | ||
} | ||
|
||
} | ||
}; | ||
|
||
var updateFromServer = function () { | ||
$.getJSON('/seats.json', function (d) { data = d; displayData(d); }); | ||
}; | ||
|
||
|
||
updateFromServer(); | ||
//setInterval( updateFromServer, 10000); | ||
|
||
}); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.