Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first run at basic status toggling functionality

  • Loading branch information...
commit da171c3975be1ffc18b27d660c0231cec15f750e 1 parent 9c8c203
Andrew Fulton authored
View
1  Gemfile
@@ -4,6 +4,7 @@ gem "sinatra"
gem "dm-core"
gem "dm-migrations"
gem "dm-serializer"
+gem "dm-types"
group :production do
gem "pg"
View
18 Gemfile.lock
@@ -2,6 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.2.6)
+ bcrypt-ruby (3.0.1)
data_objects (0.10.7)
addressable (~> 2.1)
dm-core (1.2.0)
@@ -23,6 +24,14 @@ GEM
dm-sqlite-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_sqlite3 (~> 0.10.6)
+ dm-types (1.2.1)
+ bcrypt-ruby (~> 3.0.0)
+ dm-core (~> 1.2.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.6.1)
+ multi_json (~> 1.0.3)
+ stringex (~> 1.3.0)
+ uuidtools (~> 2.1.2)
do_postgres (0.10.7)
data_objects (= 0.10.7)
do_sqlite3 (0.10.7)
@@ -36,10 +45,12 @@ GEM
rack-protection (1.1.4)
rack
sinatra (1.3.1)
- rack (~> 1.3, >= 1.3.4)
- rack-protection (~> 1.1, >= 1.1.2)
- tilt (~> 1.3, >= 1.3.3)
+ rack (>= 1.3.4, ~> 1.3)
+ rack-protection (>= 1.1.2, ~> 1.1)
+ tilt (>= 1.3.3, ~> 1.3)
+ stringex (1.3.0)
tilt (1.3.3)
+ uuidtools (2.1.2)
PLATFORMS
ruby
@@ -50,6 +61,7 @@ DEPENDENCIES
dm-postgres-adapter
dm-serializer
dm-sqlite-adapter
+ dm-types
json
pg
sinatra
View
57 squishface.rb
@@ -3,6 +3,63 @@
Bundler.require
require 'sinatra'
+## setup db ##
+DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/squish.sqlite")
+
+## models ##
+
+class Person
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, Text
+ property :status, Enum[:in,:out], :default=>:out
+end
+
+DataMapper.finalize
+DataMapper.auto_migrate!
+
get '/' do
"Hello, world"
end
+
+get '/list' do
+ @people = Person.all()
+
+ erb :list
+end
+
+get '/:person_name/is/:status_to' do
+
+ person = Person.first(:name=>params[:person_name])
+
+ redirect '/list' unless person.status
+
+ person.status = params[:status_to]
+ person.save()
+
+ redirect '/list'
+ #'hello'
+end
+
+get '/populate' do
+ azza = Person.create(
+ :name => "Azza",
+ )
+ hutcho = Person.create(
+ :name => "Hutcho",
+ )
+ david = Person.create(
+ :name => "David",
+ )
+ sarah = Person.create(
+ :name => "Sarah",
+ )
+ marta = Person.create(
+ :name => "Marta",
+ )
+ sascha = Person.create(
+ :name => "Sascha",
+ )
+ redirect '/list'
+end
View
40 views/layout.erb
@@ -0,0 +1,40 @@
+<!doctype html>
+<html lang='en'>
+ <head>
+ <meta charset="utf-8">
+ <meta name="description" content="Who is in the studio? Who is out?">
+ <meta name="author" content="Andrew at bundle.com.au">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+ <title>Squishface</title>
+ <style>
+ .people-status a
+ {
+ border-radius:5px;
+ padding:2px;
+ color:inherit;
+ text-decoration:none;
+ background-color:#eee;
+ }
+ .people-status li
+ {
+ list-style:none;
+ padding:4px;
+ }
+ li.out a.out
+ {
+ font-weight:bold;
+ color:#fff;
+ background-color:#f00;
+ }
+ li.in a.in
+ {
+ font-weight:bold;
+ color:#fff;
+ background-color:#0f0;
+ }
+ </style>
+ </head>
+ <body>
+ <%= yield %>
+ </body>
+</html>
View
6 views/list.erb
@@ -0,0 +1,6 @@
+<h1>Who is in the house? Who is out of the house?</h1>
+<ul class="people-status">
+<% for person in @people %>
+ <li class="<%= person.status %>"><%= person.name %> <a class="in" href="/<%= person.name %>/is/in">in</a> or <a class="out" href="/<%= person.name %>/is/out">out</a></li>
+<% end %>
+</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.