Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add show view

  • Loading branch information...
commit 725345362c9bc61b393e189a30587257d3485fbd 1 parent be5e422
@namelessjon authored
Showing with 52 additions and 0 deletions.
  1. +6 −0 address.rb
  2. +33 −0 templates/show.html
  3. +1 −0  views.rb
  4. +12 −0 views/show.rb
View
6 address.rb
@@ -48,6 +48,12 @@ def clean_params(param_set=params)
mustache :edit
end
+get '/:page' do |page|
+ @person = addresses.find_one(:page => page)
+ not_found unless @person
+ mustache :show
+end
+
get '/:page/edit' do |page|
@person = addresses.find_one(:page => page) || {'page' => page}
mustache :edit
View
33 templates/show.html
@@ -0,0 +1,33 @@
+<h1>{{name}}</h1>
+
+<h2>Numbers</h2>
+
+<dl class='address-list'>
+{{#numbers}}
+<dt>{{name}}</dt><dd>{{number}}</dd>
+{{/numbers}}
+</dl>
+
+<h2>Emails</h2>
+
+<dl class='address-list'>
+{{#emails}}
+<dt>{{name}}</dt><dd>{{email}}</dd>
+{{/emails}}
+</dl>
+
+<h2>Addresses</h2>
+
+{{#addresses}}
+<h3>{{name}}</h3>
+<dl class='address-list'>
+ <dt>Address</dt>
+ {{#lines}}
+ <dd>{{line}}</dd>
+ {{/lines}}
+ <dt>Postcode</dt>
+ <dd>{{postcode}}</dd>
+ <dt>Country</dt>
+ <dd>{{country}}</dd>
+</dl>
+{{/addresses}}
View
1  views.rb
@@ -5,3 +5,4 @@
require 'views/index'
require 'views/person'
require 'views/edit'
+require 'views/show'
View
12 views/show.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+class Show < Person
+ def addresses
+ if addresses = super
+ addresses.map! { |a| a['lines'] = a['address'].split(/\r?\n/).map! { |l| { :line => l } }; a }
+ addresses
+ else
+ addresses
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.