Commit 4f60c40dba37e398bc65a8dc1ef97d8a122f0cab

cool hash hack

Commit diff

sinatra/events.rb

 
88 :database => 'events.db'
99})
1010
11class Hash
12 # Cool hack by Evan Phoenix
13 def &(keys)
14 reject{|k,v| !keys.include?(k)}
15 end
16end
17
1118class Event < DataMapper::Base
1219 property :name, :string
20 property :url, :string
1321 property :description, :text
1422end
1523Event.table.create!
2828 puts Event.all.inspect
2929 @events = Event.all
3030 haml(layout('Events', %q{
31 %h1= "Events"
32 %form{:action => '/events', :method => 'POST'}
33 %fieldset
34 %legend New Event
35
36 %label{:for => 'name'} Name
37 %input{:type => 'text', :name => 'name', :id => 'name', :size => 30}
38 %br
39
40 %label{:for => 'description'} Description
41 %textarea{:type => 'description', :name => 'description', :id => 'description', :cols => 30, :rows => 4}
42 %br
43
44 %input{:type => 'submit', :class => 'submit', :value => 'Create'}
4531 - if @events.empty?
4632 %p No events found.
4733 - else
4141 %td{:class => 'name'}
4242 %a{:href => '#'}= e.name
4343 = e.description
44 %form{:action => '/events', :method => 'POST'}
45 %fieldset
46 %legend New Event
47
48 %label{:for => 'name'} Name
49 %input{:type => 'text', :name => 'name', :id => 'name', :size => 30}
50 %br
51
52 %label{:for => 'description'} Description
53 %textarea{:type => 'description', :name => 'description', :id => 'description', :cols => 30, :rows => 4}
54 %br
55
56 %input{:type => 'submit', :class => 'submit', :value => 'Create', :name => 'foo[bar]'}
57
4458 }))
4559end
4660
4761post '/events' do
48 name = params[:name].to_s.strip
49 description = params[:description].to_s.strip
50 x = Event.new(:name => name, :description => description).save
62 Event.new(params & [:name, :url, :description]).save
5163 redirect '/events'
5264end
5365
5466
5567def layout(title, content)
56 @saved = $ticgit.config['list_options'].keys rescue []
5768 %Q(
5869%html
5970 %head
9696
9797form
9898 label
99 width: 120px
99100 float: left
100 text-align: right
101 width: 200px
102 :font
103 weight: bold
101 font-weight: bold
104102
105103 input, textarea
106 margin-left: 210px
107 display: block
108 margin-bottom: 0pt
109 width: 300px
104 width: 180px
105 margin-bottom: 5px
106
107 input.submit
108 width: 90px
109 margin-left: 120px
110 margin-top: 5px
111
112 br
113 clear: left
110114
111115table
112116 width: 100%
143143 display: block
144144 :font
145145 weight: bold
146
147.submit
148 font-size: large
149 font-weight: bold
150
151.page_title
152 font-size: xx-large
153
154.edit_link
155 color: black
156 font-size: 14px
157 font-weight: bold
158 background-color: #e0e0e0
159 font-variant: small-caps
160 text-decoration: none
161
toggle raw diff