ソースを参照

Fixed invalid layout. Text changes.

tags/last-sinatra-version
Adrian Short 14年前
コミット
69b3285ba1
7個のファイルの変更75行の追加73行の削除
  1. +3
    -3
      app.rb
  2. +17
    -18
      lib/models.rb
  3. +7
    -3
      views/about.haml
  4. +2
    -2
      views/election.haml
  5. +10
    -9
      views/home.haml
  6. +16
    -16
      views/layout.haml
  7. +20
    -22
      views/wards.haml

+ 3
- 3
app.rb ファイルの表示

@@ -10,13 +10,13 @@ DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlit
DataMapper.auto_upgrade!

get '/' do
@wards = Ward.all
@wards = Ward.all( :order => 'name' )
haml :home
end

get '/wards/:id' do
@ward = Ward.get(params[:id])
@candidates = Councilcandidate.all( :ward_id => @ward.id )
@candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname' )
haml :wards
end

@@ -26,7 +26,7 @@ get '/wards' do
@district_name = result['administrative']['district']['title']
@ward_name = result['administrative']['ward']['title']
@ward = Ward.first( :name => @ward_name )
@candidates = Councilcandidate.all( :ward_id => @ward.id )
@candidates = Councilcandidate.all( :ward_id => @ward.id, :order => 'surname')
haml :wards
end



+ 17
- 18
lib/models.rb ファイルの表示

@@ -2,22 +2,22 @@ class Postcode
include DataMapper::Resource

property :id, Serial
property :postcode, String, :required => true
property :created_at, DateTime
property :lat, Float
property :lng, Float
property :district_name, String
property :district_code, String
property :ward_name, String
property :ward_code, String
property :postcode, String, :required => true
property :created_at, DateTime, :required => true
property :lat, Float, :required => true
property :lng, Float, :required => true
property :district_name, String, :required => true
property :district_code, String, :required => true
property :ward_name, String, :required => true
property :ward_code, String, :required => true
end

class Ward
include DataMapper::Resource
property :id, Serial
property :ons_id, String, :required => true
property :name, String, :required => true
property :ons_id, String, :required => true
property :name, String, :required => true
has n, :councilcandidates
end
@@ -26,7 +26,7 @@ class Party
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :name, String, :required => true
has n, :councilcandidates
end
@@ -35,14 +35,13 @@ class Councilcandidate
include DataMapper::Resource
property :id, Serial
property :ward_id, Integer, :required => true
property :party_id, Integer, :required => true
property :forenames, String
property :surname, String
property :address, String, :length => 200
property :postcode, String
property :ward_id, Integer, :required => true
property :party_id, Integer, :required => true
property :forenames, String, :required => true
property :surname, String, :required => true
property :address, String, :length => 200
property :postcode, String, :required => true

belongs_to :party
belongs_to :ward

end

+ 7
- 3
views/about.haml ファイルの表示

@@ -6,13 +6,17 @@
%p It is independent of Sutton Council, all political parties and candidates.

%p The code for this website is open source and managed on Github. It is hosted by Heroku.
%p
The code for this website is open source and managed on Github. It is hosted by Heroku.

%p
The candidates' data comes from Sutton Council.
%p The postcode lookup is done by UK Postcodes using open data from Ordnance Survey Code-Point Open enhanced by MySociety. I use the Ruby Pat gem to access the postcodes API.
%p
The postcode lookup is done by UK Postcodes using open data from Ordnance Survey Code-Point Open enhanced by MySociety. I use the Ruby Pat gem to access the postcodes API.

%p This site is written in Ruby using the Sinatra framework. The HTML templates use Haml. The database is sqlite for development and postgresql for production, abstracted through DataMapper. Source control and deployment is done with Git.
%p
This site is written in Ruby using the Sinatra framework. The HTML templates use Haml. The database is sqlite for development and postgresql for production, abstracted through DataMapper. Source control and deployment is done with Git.

%h2 #followfooter



+ 2
- 2
views/election.haml ファイルの表示

@@ -2,7 +2,7 @@

%p On 6 May 2010 you get to choose your local councillors and to decide who runs Sutton Council for the next four years.

%p The borough is divided into 18 areas called wards.
%p Sutton borough is divided into 18 areas called wards.

%p Each ward has three councillors. That makes 54 councillors for the whole borough.

@@ -10,7 +10,7 @@

%p The three people with the most votes in each ward become the councillors for that ward.

%p If a political party gets 28 or more councillors they get to run the council and decide its policies and services until the next election in four years time.
%p If a political party gets 28 or more councillors they get to run Sutton Council and decide its policies and services until the next election in four years time.


%h2 Registering to vote


+ 10
- 9
views/home.haml ファイルの表示

@@ -1,16 +1,17 @@
%h2 One day. Two elections in Sutton.
-# %h2 One day. Two elections in Sutton.

%h2
Who are my local candidates in the Sutton Council elections on 6 May?
%h2 Who are my local candidates in the Sutton Council elections on 6 May?

%form{ :method => 'get', :action => '/wards' }
%label{ :for => "postcode" } My postcode is
%input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 }
%input{ :type => 'submit', :value => "Find it" }

%h2 Council Wards
- for ward in @wards
%p
%a{ :href => "/wards/#{ward.id.to_s}" }
= ward.name
-#

%h2 Council Wards

- for ward in @wards
%p
%a{ :href => "/wards/#{ward.id.to_s}" }
= ward.name

+ 16
- 16
views/layout.haml ファイルの表示

@@ -1,21 +1,21 @@
!!! Strict
!!!
%html
%head
%title Sutton Council Elections 2010
%link{ :rel => 'stylesheet', :type => 'text/css', :href => '/style.css' }
%body
#header
%a.date{ :href => '/' } 6 MAY 2010
#main
= yield
#footer
%body
#header
%a.date{ :href => '/' } 6 May 2010
#main
= yield
#footer
%p
%a{ :href => '/how-the-election-works' } How the council election works
-#
%p
%a{ :href => '/how-the-election-works' } How the council election works
-#
%p
%a{ :href => '/voting' } How to vote
%p
%a{ :href => '/about' } About this website
%p.credit
Design
%a{ :href => "http://adrianshort.co.uk/" } Adrian Short
%a{ :href => '/voting' } How to vote
%p
%a{ :href => '/about' } About this website
%p.credit
Design
%a{ :href => "http://adrianshort.co.uk/" } Adrian Short

+ 20
- 22
views/wards.haml ファイルの表示

@@ -1,25 +1,23 @@
%h1
= @ward.name
Ward

- if @postcode
%h2
%h1
= @postcode
is in
%span.highlight
= @ward_name
Ward
in
= @district_name
%h2
Council candidates in
= @ward.name
- for candidate in @candidates
%p
%span.candidate_name
= candidate.forenames
= candidate.surname
%br
= candidate.party.name
= @ward_name
Ward
-else
%h1
= @ward.name
Ward

#candidates
%h2
Council candidates in
= @ward.name
- for candidate in @candidates
%p
%span.candidate_name
= candidate.forenames
= candidate.surname
%br
= candidate.party.name

読み込み中…
キャンセル
保存