| |   |
| 1 | require 'rubygems' |
| 2 | require 'sinatra' |
| 3 | require 'haml' |
| 4 | require 'data_mapper' |
| 5 | |
| 6 | DataMapper::Database.setup({ |
| 7 | :adapter => 'sqlite3', |
| 8 | :database => 'events.db' |
| 9 | }) |
| 10 | |
| 11 | class Event < DataMapper::Base |
| 12 | property :name, :string |
| 13 | end |
| 14 | Event.table.create! |
| 15 | |
| 16 | get('/stylesheet.css') { Sass::Engine.new(File.read(__FILE__).gsub(/.*__END__/m, '')).render } |
| 17 | |
| 18 | get '/events' do |
| 19 | puts Event.all.inspect |
| 20 | @events = Event.all |
| 21 | haml(layout('Events', %q{ |
| 22 | %h1= "Events" |
| 23 | %form{:action => '/events', :method => 'POST'} |
| 24 | %table |
| 25 | %tr |
| 26 | %th Name |
| 27 | %td |
| 28 | %input{:type => 'text', :name => 'name', :size => 30} |
| 29 | %tr |
| 30 | %td |
| 31 | %td |
| 32 | %input{:type => 'submit', :value => 'Create Event'} |
| 33 | - if @events.empty? |
| 34 | %p No events found. |
| 35 | - else |
| 36 | %table.long |
| 37 | - c = 'even' |
| 38 | - @events.each do |e| |
| 39 | %tr{:class => (c == 'even' ? c = 'odd' : c = 'even') } |
| 40 | %td |
| 41 | %a{:href => "/event/#{e.id}" } |
| 42 | %code= e.name |
| 43 | })) |
| 44 | end |
| 45 | |
| 46 | post '/events' do |
| 47 | name = params[:name].to_s.strip |
| 48 | x = Event.new(:name => name).save |
| 49 | redirect '/events' |
| 50 | end |
| 51 | |
| 52 | |
| 53 | def layout(title, content) |
| 54 | @saved = $ticgit.config['list_options'].keys rescue [] |
| 55 | %Q( |
| 56 | %html |
| 57 | %head |
| 58 | %title #{title} |
| 59 | %link{:rel => 'stylesheet', :href => '/stylesheet.css', :type => 'text/css', :media => 'screen'} |
| 60 | %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'} |
| 61 | |
| 62 | %body |
| 63 | #{content} |
| 64 | ) |
| 65 | end |
| 66 | |
| 67 | __END__ |
| 68 | body |
| 69 | :font |
| 70 | family: Verdana, Arial, "Bitstream Vera Sans", Helvetica, sans-serif |
| 71 | color: black |
| 72 | line-height: 160% |
| 73 | background-color: white |
| 74 | margin: 2em |
| 75 | |
| 76 | #navigation |
| 77 | a |
| 78 | background-color: #e0e0e0 |
| 79 | color: black |
| 80 | text-decoration: none |
| 81 | padding: 2px |
| 82 | padding: 5px |
| 83 | border-bottom: 1px black solid |
| 84 | |
| 85 | #action |
| 86 | text-align: right |
| 87 | |
| 88 | .addtag |
| 89 | padding: 5px 0 |
| 90 | |
| 91 | h1 |
| 92 | display: block |
| 93 | padding-bottom: 5px |
| 94 | |
| 95 | a |
| 96 | color: black |
| 97 | a.exists |
| 98 | font-weight: bold |
| 99 | a.unknown |
| 100 | font-style: italic |
| 101 | |
| 102 | .comments |
| 103 | margin: 10px 20px |
| 104 | .comment |
| 105 | .head |
| 106 | background: #eee |
| 107 | padding: 4px |
| 108 | .comment-text |
| 109 | padding: 10px |
| 110 | color: #333 |
| 111 | |
| 112 | table.long |
| 113 | width: 100% |
| 114 | |
| 115 | table |
| 116 | tr.even |
| 117 | td |
| 118 | background: #eee |
| 119 | tr.odd |
| 120 | td |
| 121 | background: #fff |
| 122 | |
| 123 | table |
| 124 | tr |
| 125 | th |
| 126 | text-align: left |
| 127 | padding: 3px |
| 128 | vertical-align: top |
| 129 | td.open |
| 130 | background: #ada |
| 131 | td.resolved |
| 132 | background: #abd |
| 133 | td.hold |
| 134 | background: #dda |
| 135 | td.invalid |
| 136 | background: #aaa |
| 137 | |
| 138 | .submit |
| 139 | font-size: large |
| 140 | font-weight: bold |
| 141 | |
| 142 | .page_title |
| 143 | font-size: xx-large |
| 144 | |
| 145 | .edit_link |
| 146 | color: black |
| 147 | font-size: 14px |
| 148 | font-weight: bold |
| 149 | background-color: #e0e0e0 |
| 150 | font-variant: small-caps |
| 151 | text-decoration: none |
| 152 | |
| toggle raw diff |
--- /dev/null
+++ b/sinatra/events.rb
@@ -0,0 +1,152 @@
+require 'rubygems'
+require 'sinatra'
+require 'haml'
+require 'data_mapper'
+
+DataMapper::Database.setup({
+ :adapter => 'sqlite3',
+ :database => 'events.db'
+})
+
+class Event < DataMapper::Base
+ property :name, :string
+end
+Event.table.create!
+
+get('/stylesheet.css') { Sass::Engine.new(File.read(__FILE__).gsub(/.*__END__/m, '')).render }
+
+get '/events' do
+ puts Event.all.inspect
+ @events = Event.all
+ haml(layout('Events', %q{
+ %h1= "Events"
+ %form{:action => '/events', :method => 'POST'}
+ %table
+ %tr
+ %th Name
+ %td
+ %input{:type => 'text', :name => 'name', :size => 30}
+ %tr
+ %td
+ %td
+ %input{:type => 'submit', :value => 'Create Event'}
+ - if @events.empty?
+ %p No events found.
+ - else
+ %table.long
+ - c = 'even'
+ - @events.each do |e|
+ %tr{:class => (c == 'even' ? c = 'odd' : c = 'even') }
+ %td
+ %a{:href => "/event/#{e.id}" }
+ %code= e.name
+ }))
+end
+
+post '/events' do
+ name = params[:name].to_s.strip
+ x = Event.new(:name => name).save
+ redirect '/events'
+end
+
+
+def layout(title, content)
+ @saved = $ticgit.config['list_options'].keys rescue []
+ %Q(
+%html
+ %head
+ %title #{title}
+ %link{:rel => 'stylesheet', :href => '/stylesheet.css', :type => 'text/css', :media => 'screen'}
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
+
+ %body
+ #{content}
+ )
+end
+
+__END__
+body
+ :font
+ family: Verdana, Arial, "Bitstream Vera Sans", Helvetica, sans-serif
+ color: black
+ line-height: 160%
+ background-color: white
+ margin: 2em
+
+#navigation
+ a
+ background-color: #e0e0e0
+ color: black
+ text-decoration: none
+ padding: 2px
+ padding: 5px
+ border-bottom: 1px black solid
+
+#action
+ text-align: right
+
+.addtag
+ padding: 5px 0
+
+h1
+ display: block
+ padding-bottom: 5px
+
+a
+ color: black
+a.exists
+ font-weight: bold
+a.unknown
+ font-style: italic
+
+.comments
+ margin: 10px 20px
+ .comment
+ .head
+ background: #eee
+ padding: 4px
+ .comment-text
+ padding: 10px
+ color: #333
+
+table.long
+ width: 100%
+
+table
+ tr.even
+ td
+ background: #eee
+ tr.odd
+ td
+ background: #fff
+
+table
+ tr
+ th
+ text-align: left
+ padding: 3px
+ vertical-align: top
+ td.open
+ background: #ada
+ td.resolved
+ background: #abd
+ td.hold
+ background: #dda
+ td.invalid
+ background: #aaa
+
+.submit
+ font-size: large
+ font-weight: bold
+
+.page_title
+ font-size: xx-large
+
+.edit_link
+ color: black
+ font-size: 14px
+ font-weight: bold
+ background-color: #e0e0e0
+ font-variant: small-caps
+ text-decoration: none
+ |