Bläddra i källkod

Added CSV download to /scoreboard

pull/3/head
Adrian Short 14 år sedan
förälder
incheckning
baf15c8e8f
4 ändrade filer med 48 tillägg och 3 borttagningar
  1. +24
    -0
      app.rb
  2. +0
    -1
      lib/models.rb
  3. +6
    -0
      public/style.css
  4. +18
    -2
      views/scoreboard.haml

+ 24
- 0
app.rb Visa fil

@@ -147,6 +147,30 @@ get '/about' do
haml :about
end

get '/scoreboard.csv' do
@councils = Council.all( :order => ['name'] )
labels = %w[
id
created_at
updated_at
name
slug
url
data_url
open_licence
machine_readable
start_d
end_d
]
headers "Content-Disposition" => "attachment;filename=armchair-auditor-scoreboard.csv",
"Content-Type" => "text/csv"
output = ""
for council in @councils
output += council.to_csv
end
labels.join(',') + "\n" + output
end

get '/scoreboard' do
@councils = Council.all( :order => ['name'] )
haml :scoreboard


+ 0
- 1
lib/models.rb Visa fil

@@ -100,7 +100,6 @@ class Council
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


+ 6
- 0
public/style.css Visa fil

@@ -104,6 +104,12 @@ strong
color: #000;
}

.strong
{
color: #000;
font-weight: bold;
}

table
{
border-collapse: collapse;


+ 18
- 2
views/scoreboard.haml Visa fil

@@ -1,6 +1,10 @@
.grid_12
%h2= @page_title = "Council Spending Data Scoreboard"

%p.noprint.download
%a{ :href => "/scoreboard.csv" }
Download data as CSV

%table
%tr
%th Council
@@ -24,7 +28,19 @@
%td= council.start_d.strftime("%b %Y")
%td= council.end_d.strftime("%b %Y")
%td= council.updated_at.strftime("%d %b %Y")
%p.highlight.noprint
This scoreboard data is free for you to use according to the
%a{ :href => "http://creativecommons.org/licenses/by/3.0/"}<
Creative Commons Attribution 3.0 Unported Licence.
Please credit to
%strong
Adrian Short/Armchair Auditor
and link back to
%a{ :href => "http://armchairauditor.co.uk/scoreboard" }<
http://armchairauditor.co.uk/scoreboard
where possible.
%h3 Notes
%p


Laddar…
Avbryt
Spara