Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Also namespace views

  • Loading branch information...
commit 207ce05449f025fc10c851e27c0f4bed48df7be0 1 parent ba5b896
@namelessjon authored
View
9 app.rb
@@ -2,14 +2,19 @@
# Jonathan D. Stott <jonathan.stott@gmail.com>
require 'sinatra/base'
require 'mongo'
-require 'views'
+require 'black_book/views'
module BlackBook
class App < ::Sinatra::Base
register Mustache::Sinatra
- set :mustache, { :templates => 'templates' }
+ set :mustache, proc {
+ {
+ :namespace => ::BlackBook,
+ :templates => ::File.join(self.root, 'black_book', 'templates'),
+ }
+ }
helpers do
def addresses
View
0  templates/edit.html → black_book/templates/edit.html
File renamed without changes
View
0  templates/index.html → black_book/templates/index.html
File renamed without changes
View
0  templates/layout.html → black_book/templates/layout.html
File renamed without changes
View
0  templates/show.html → black_book/templates/show.html
File renamed without changes
View
8 black_book/views.rb
@@ -0,0 +1,8 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+require 'mustache/sinatra'
+require 'black_book/views/layout'
+require 'black_book/views/index'
+require 'black_book/views/person'
+require 'black_book/views/edit'
+require 'black_book/views/show'
View
27 black_book/views/edit.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+module BlackBook
+ module Views
+ class Edit < Person
+ def action
+ page ? "/#{page}" : '/'
+ end
+
+ def new?
+ !!@person['_id']
+ end
+
+ def new_or_edit
+ new? ? 'Editing' : 'New'
+ end
+
+ def button_text
+ new? ? "Update" : "Create"
+ end
+
+ def title
+ new? ? "Editing #{super}" : "New#{super}"
+ end
+ end
+ end
+end
View
11 black_book/views/index.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+module BlackBook
+ module Views
+ class Index < Layout
+ def addresses
+ @addresses
+ end
+ end
+ end
+end
View
13 black_book/views/layout.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+module BlackBook
+ module Views
+ class Layout < ::Mustache
+ self.template_extension = 'html'
+
+ def title
+ 'Addresses!'
+ end
+ end
+ end
+end
View
31 black_book/views/person.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+module BlackBook
+ module Views
+ 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
+ end
+end
View
16 black_book/views/show.rb
@@ -0,0 +1,16 @@
+#!/usr/bin/ruby
+# Jonathan D. Stott <jonathan.stott@gmail.com>
+module BlackBook
+ module Views
+ 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
+ end
+end
View
8 views.rb
@@ -1,8 +0,0 @@
-#!/usr/bin/ruby
-# Jonathan D. Stott <jonathan.stott@gmail.com>
-require 'mustache/sinatra'
-require 'views/layout'
-require 'views/index'
-require 'views/person'
-require 'views/edit'
-require 'views/show'
View
23 views/edit.rb
@@ -1,23 +0,0 @@
-#!/usr/bin/ruby
-# Jonathan D. Stott <jonathan.stott@gmail.com>
-class Edit < Person
- def action
- page ? "/#{page}" : '/'
- end
-
- def new?
- !!@person['_id']
- end
-
- def new_or_edit
- new? ? 'Editing' : 'New'
- end
-
- def button_text
- new? ? "Update" : "Create"
- end
-
- def title
- new? ? "Editing #{super}" : "New#{super}"
- end
-end
View
7 views/index.rb
@@ -1,7 +0,0 @@
-#!/usr/bin/ruby
-# Jonathan D. Stott <jonathan.stott@gmail.com>
-class Index < Layout
- def addresses
- @addresses
- end
-end
View
10 views/layout.rb
@@ -1,10 +0,0 @@
-#!/usr/bin/ruby
-# Jonathan D. Stott <jonathan.stott@gmail.com>
-class Layout < Mustache
- self.template_extension = 'html'
- self.template_path = '../templates'
-
- def title
- 'Addresses!'
- end
-end
View
27 views/person.rb
@@ -1,27 +0,0 @@
-#!/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
View
12 views/show.rb
@@ -1,12 +0,0 @@
-#!/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.