Browse Source

Text additions. Moved to pat gem. Added Datamapper code

tags/last-sinatra-version
Adrian Short 14 years ago
parent
commit
e6eee3b89d
9 changed files with 159 additions and 80 deletions
  1. +2
    -0
      .gems
  2. +2
    -0
      .gitignore
  3. +35
    -11
      app.rb
  4. +31
    -0
      public/style.css
  5. +14
    -57
      views/about.haml
  6. +27
    -0
      views/election.haml
  7. +3
    -9
      views/home.haml
  8. +9
    -3
      views/layout.haml
  9. +36
    -0
      views/voting.haml

+ 2
- 0
.gems View File

@@ -0,0 +1,2 @@
pat --source gemcutter.org


+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
db.sqlite3


+ 35
- 11
app.rb View File

@@ -1,25 +1,49 @@
require 'rubygems' require 'rubygems'
require 'sinatra' require 'sinatra'
require 'json'
require 'rest_client'
require 'pat'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'

DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")

class Postcode
include DataMapper::Resource

property :id, Integer, :serial => true
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
end

DataMapper.auto_upgrade!


get '/' do get '/' do
@wards = %w{ Cheam Sutton Stonecot }
haml :home haml :home
end end


get '/wards' do get '/wards' do
@postcode = params[:postcode].strip.upcase @postcode = params[:postcode].strip.upcase

url = "http://www.uk-postcodes.com/postcode/" + @postcode.gsub(/ /, '') + '.json'

result = RestClient.get(url)
result_ary = JSON.parse(result)
@district_name = result_ary['administrative']['district']['title']
@ward_name = result_ary['administrative']['ward']['title']
result = Pat.get(@postcode)
@district_name = result['administrative']['district']['title']
@ward_name = result['administrative']['ward']['title']
haml :wards haml :wards
end end


get '/how-the-election-works' do
haml :election
end

# get '/voting' do
# haml :voting
# end

get '/about' do get '/about' do
@accounts = %w{ adrianshort mashthestate openlylocal openelection lbsuttonnews stef stonecothill sutmoblib mysociety pezholio stonecotparking }
haml :about haml :about
end
end

+ 31
- 0
public/style.css View File

@@ -11,6 +11,11 @@ body
input input
{ {
font-size: 150%; font-size: 150%;
background-color: #fff;
}

input.postcode
{
text-transform: uppercase; text-transform: uppercase;
} }


@@ -27,6 +32,10 @@ input
#footer #footer
{ {
font-size: 90%; font-size: 90%;
}

.credit
{
text-align: right; text-align: right;
} }


@@ -48,3 +57,25 @@ h2
{ {
margin-top: 50px; margin-top: 50px;
} }

form
{
font-size: 150%;
}

a.date
{
font-size: 620%;
font-weight: bold;
padding: 30px 30px;
}

#header
{
margin-bottom: 60px;
}

h1
{
margin-top: 50px;
}

+ 14
- 57
views/about.haml View File

@@ -1,65 +1,22 @@
%h1 How the council election works

%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 Each ward has three councillors. That makes 54 councillors for the whole borough.

%p You get three votes to choose three councillors for your ward from the list of candidates.

%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.


%h2 Registering to vote
%h1 About this website


%p %p
If you're not already registered to vote you must do so by
%strong 20 April
otherwise you won't be able to take part.
This website was designed by
%a{ :href => 'http://adrianshort.co.uk' } Adrian Short
%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 %p
You can get a registration form at the
%a{ :href => "http://www.aboutmyvote.co.uk/" } About My Vote
website or by phoning Sutton Council on
%span{ :class => 'phone' } 020 8770 4888.

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.


%h2 Voting
%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.


%h3 Voting at your polling station

%p Most people vote at their local polling station. This is usually in a school, hall or community centre near you.

%p
The council will send you a
%strong poll card
showing you where to vote.

%p If you lose your poll card, don't worry. You can still vote as long as you are registered.

%p
You can vote at your polling station
%strong between 7am and 10pm on 6 May.

%p If you don't want to vote at a polling station or are unable to get there you can:
%h2 #followfooter


%ul %ul
%li vote by post
%li ask someone to vote for you

%h3 Voting by post

%p Anyone can apply to vote by post.

%p If you are registered to vote by post you won't be allowed to vote at a polling station.

%h3 Asking someone to vote for you

%p
You can choose to have someone vote for you at the polling station. This is called a
%strong proxy vote.

%p If you want to vote by post or have someone vote for you and haven't already told Sutton Council about this, do it straight away.
- for account in @accounts
%li
%a{ :href => "http://twitter.com/#{account}" }@#{account}

+ 27
- 0
views/election.haml View File

@@ -0,0 +1,27 @@
%h1 How the council election works

%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 Each ward has three councillors. That makes 54 councillors for the whole borough.

%p You get three votes to choose three councillors for your ward from the list of candidates.

%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.


%h2 Registering to vote

%p
If you're not already registered to vote you must do so by
%strong 20 April
otherwise you won't be able to take part.

%p
You can get a registration form at the
%a{ :href => "http://www.aboutmyvote.co.uk/" } About My Vote
website or by phoning Sutton Council on
%span{ :class => 'phone' } 020 8770 4888.

+ 3
- 9
views/home.haml View File

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

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


%form{ :method => 'get', :action => '/wards' } %form{ :method => 'get', :action => '/wards' }
%label{ :for => "postcode" } My postcode is %label{ :for => "postcode" } My postcode is
%input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 } %input{ :type => 'text', :name => 'postcode', :value => 'SM1 1EA', :size => 8, :maxlength => 8 }
%input{ :type => 'submit', :value => "Find" }
%p
%a{ :href => '/about' } How the council election works
-#
- for ward in @wards
%p= ward
%input{ :type => 'submit', :value => "Find it" }

+ 9
- 3
views/layout.haml View File

@@ -1,15 +1,21 @@
!!! Strict !!! Strict
%html %html
%head %head
%title Sutton Council Elections
%title Sutton Council Elections 2010
%link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' } %link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' }
%body %body
#header #header
%h1
%a{ :href => '/' } Sutton Council Elections
%a.date{ :href => '/' } 6 May 2010
#main #main
= yield = yield
#footer #footer
%p %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 Design
%a{ :href => "http://adrianshort.co.uk/" } Adrian Short %a{ :href => "http://adrianshort.co.uk/" } Adrian Short

+ 36
- 0
views/voting.haml View File

@@ -0,0 +1,36 @@
%h1 Voting

%h2 Voting at your polling station

%p Most people vote at their local polling station. This is usually in a school, hall or community centre near you.

%p
The council will send you a
%strong poll card
showing you where to vote.

%p If you lose your poll card, don't worry. You can still vote as long as you are registered.

%p
You can vote at your polling station
%strong between 7am and 10pm on 6 May.

%p If you don't want to vote at a polling station or are unable to get there you can:

%ul
%li vote by post
%li ask someone to vote for you

%h2 Voting by post

%p Anyone can apply to vote by post.

%p If you are registered to vote by post you won't be allowed to vote at a polling station.

%h2 Asking someone to vote for you

%p
You can choose to have someone vote for you at the polling station. This is called a
%strong proxy vote.

%p If you want to vote by post or have someone vote for you and haven't already told Sutton Council about this, do it straight away.

Loading…
Cancel
Save