| @@ -10,6 +10,10 @@ helpers do | |||||
| def commify(amount) | def commify(amount) | ||||
| amount.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse | amount.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse | ||||
| end | end | ||||
| def yesno(boolean) | |||||
| boolean == true ? 'Yes' : 'No' | |||||
| end | |||||
| end | end | ||||
| get '/' do | get '/' do | ||||
| @@ -143,6 +147,11 @@ get '/about' do | |||||
| haml :about | haml :about | ||||
| end | end | ||||
| get '/scoreboard' do | |||||
| @councils = Council.all( :order => ['name'] ) | |||||
| haml :scoreboard | |||||
| end | |||||
| not_found do | not_found do | ||||
| haml :not_found | haml :not_found | ||||
| end | end | ||||
| @@ -88,5 +88,28 @@ class Supplier | |||||
| end | end | ||||
| end | end | ||||
| class Council | |||||
| include DataMapper::Resource | |||||
| property :id, Serial | |||||
| property :created_at, DateTime | |||||
| property :updated_at, DateTime | |||||
| property :name, String, :length => 255, :required => true | |||||
| property :slug, String, :length => 255 | |||||
| property :url, String, :length => 255 | |||||
| property :data_url, String, :length => 512 | |||||
| property :open_licence, Boolean, :default => false | |||||
| property :machine_readable, Boolean, :default => false | |||||
| property :grade, String, :length => 1 | |||||
| property :start_d, Date | |||||
| property :end_d, Date | |||||
| before :save, :slugify | |||||
| def slugify | |||||
| @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase | |||||
| end | |||||
| end | |||||
| DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") | DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") | ||||
| DataMapper.auto_upgrade! | DataMapper.auto_upgrade! | ||||
| @@ -0,0 +1,26 @@ | |||||
| .grid_12 | |||||
| %h2= @page_title = "Council Spending Data Scoreboard" | |||||
| %table | |||||
| %tr | |||||
| %th Council | |||||
| %th Data URL | |||||
| %th Open licence? | |||||
| %th Machine readable? | |||||
| %th Start | |||||
| %th End | |||||
| %th Updated | |||||
| - for council in @councils | |||||
| %tr | |||||
| %td | |||||
| %a{ :href => council.url } | |||||
| = council.name | |||||
| %td | |||||
| %a{ :href => council.data_url } | |||||
| data | |||||
| %td= yesno(council.open_licence) | |||||
| %td= yesno(council.machine_readable) | |||||
| %td= council.start_d.strftime("%b %Y") | |||||
| %td= council.end_d.strftime("%b %Y") | |||||
| %td= council.updated_at.strftime("%d %b %Y") | |||||