Browse files

Refactor Edit to use base Person class

  • Loading branch information...
1 parent bd57fb5 commit 5cab9707ebaad4bd3ce8fdaf8d2c6a63cea08ab5 @namelessjon committed Jul 1, 2010
Showing with 37 additions and 21 deletions.
  1. +1 −0 views.rb
  2. +9 −21 views/edit.rb
  3. +27 −0 views/person.rb
View
1 views.rb
@@ -3,4 +3,5 @@
require 'mustache/sinatra'
require 'views/layout'
require 'views/index'
+require 'views/person'
require 'views/edit'
View
30 views/edit.rb
@@ -1,35 +1,23 @@
#!/usr/bin/ruby
# Jonathan D. Stott <jonathan.stott@gmail.com>
-class Edit < Layout
+class Edit < Person
def action
page ? "/#{page}" : '/'
end
- def button_text
- page ? "Update" : "Create"
- end
-
- def title
- page ? "Editing #{name} - #{super}" : "New - #{super}"
- end
-
- def name
- @person['name']
- end
-
- def page
- @person['page']
+ def new?
+ !!@person['_id']
end
- def emails
- @person['emails']
+ def new_or_edit
+ new? ? 'Editing' : 'New'
end
- def addresses
- @person['addresses']
+ def button_text
+ new? ? "Update" : "Create"
end
- def numbers
- @person['numbers']
+ def title
+ new? ? "Editing #{super}" : "New#{super}"
end
end
View
27 views/person.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+class Person < Layout
+ def title
+ "#{name} - Addresses"
+ end
+
+ def name
+ @person['name']
+ end
+
+ def page
+ @person['page']
+ end
+
+ def emails
+ @person['emails']
+ end
+
+ def addresses
+ @person['addresses']
+ end
+
+ def numbers
+ @person['numbers']
+ end
+end

0 comments on commit 5cab970

Please sign in to comment.