瀏覽代碼

Added party colours

tags/last-sinatra-version
Adrian Short 14 年之前
父節點
當前提交
9a7a99f6c1
共有 6 個文件被更改,包括 41 次插入14 次删除
  1. +2
    -1
      app.rb
  2. +1
    -0
      lib/models.rb
  3. +19
    -1
      public/style.css
  4. +8
    -6
      views/home.haml
  5. +6
    -5
      views/resultssuttoncouncil.haml
  6. +5
    -1
      views/resultsukparliament.haml

+ 2
- 1
app.rb 查看文件

@@ -27,7 +27,8 @@ get '/' do
@results = repository(:default).adapter.query("
SELECT p.name,
sum(c.votes_2010) AS votes
sum(c.votes_2010) AS votes,
p.colour
FROM parties p,
councilcandidates c


+ 1
- 0
lib/models.rb 查看文件

@@ -69,6 +69,7 @@ class Party
property :id, Serial
property :name, String, :required => true
property :colour, String
has n, :councilcandidates, :order => ['surname']
has n, :parliamentcandidates, :order => ['surname']


+ 19
- 1
public/style.css 查看文件

@@ -103,12 +103,30 @@ strong
color: #000;
}

table
{
border-collapse: collapse;
}

td, th
{
padding: 0 15px 15px 0;
padding: 6px;
}

tr
{
border-bottom: 1px solid #eee;
}

.right
{
text-align: right;
}

.elected
{
background-color: #777;
color: white;
padding: 2px 2px;
font-weight: normal;
}

+ 8
- 6
views/home.haml 查看文件

@@ -8,21 +8,21 @@
%p
%a{ :href => '/results/uk-parliament/2010-05-06/sutton-and-cheam' } Sutton and Cheam Constituency
%h2 Sutton Council Election Results
%h2 Sutton Council Election Results Summary
%table
%tr
%th
%th Votes
%th % Votes
%th
%th Seats
%th % Seats
%th Votes
%th % Votes

- for result in @results
%tr
%td{ :style => "background-color: #{result[2]}" }  
%td= result[0]
%td.right= result[1]
%td.right= sprintf("%0.1f%%", result[1].to_f / @total_votes * 100)
-# Some pretty serious cheating going on here!
%td.right
- if result[0] == 'Conservative Party'
@@ -38,13 +38,15 @@
80%
- else
0%
%td.right= result[1]
%td.right= sprintf("%0.1f%%", result[1].to_f / @total_votes * 100)
%p
Total votes:
= @total_votes
%h2 Sutton Council ward results
%h2 Sutton Council Results by Ward
- for ward in @wards
%p


+ 6
- 5
views/resultssuttoncouncil.haml 查看文件

@@ -10,17 +10,18 @@
%table
%tr
%th
%th
%th
%th.right Votes
-#
%th.right %
%th.right Change
%th.right % Votes
%th
- for candidate in @candidates
- count += 1
%tr.vcard
%td= count
%td{ :style => "background-color: #{candidate.party.colour}" }  
%td
%span.candidate_name.fn
= candidate.forenames.split(' ')[0]
@@ -42,7 +43,7 @@
%td
- if count < 4
%strong ELECTED
.elected ELECTED
%p
Total votes:


+ 5
- 1
views/resultsukparliament.haml 查看文件

@@ -10,16 +10,20 @@
%table
%tr
%th
%th
%th
%th.right Votes
%th.right %
%th.right Change
%th
- for candidate in @candidates
- count += 1
%tr.vcard
%td= count
%td{ :style => "background-color: #{candidate.party.colour}" } &nbsp;
%td
%span.candidate_name.fn
= candidate.forenames.split(' ')[0]
@@ -41,7 +45,7 @@
%td
- if count == 1
%strong ELECTED
.elected ELECTED
%p
Total votes:


Loading…
取消
儲存