Browse files

Add deep getter/setter

  • Loading branch information...
1 parent bd21a05 commit f4af78a85612c63aaf57080a99295d62cc9257b7 Tarkus Liu committed May 25, 2012
View
13 app.coffee
@@ -18,6 +18,7 @@ app.use express.session
maxAge: new Date Date.now() + 7200000
store: new SessionStore {client: require('./lib/helper').connectRedis()}
app.use assets()
+app.use express.static __dirname + '/assets'
app.set 'view engine', 'jade'
@@ -28,7 +29,6 @@ app.helpers
app.dynamicHelpers
user: (req, res) ->
- console.log "1"
req.session
app.param 'model', (req, res, next, name) ->
@@ -55,9 +55,16 @@ app.get '/login', (req, res) ->
app.post '/login', (req, res) ->
username = req.body.username
password = req.body.password
- if username is "admin" and password is "redis"
+ if typeof instance.login is 'function'
+ login = instance.login(username, password)
+ else
+ login = username is instance.get("login", "user") and \
+ password is instance.get("login", "password")
+ if login
req.session.auth = true
- res.redirect '/dashboard'
+ res.redirect '/dashboard'
+ else
+ res.redirect '/login'
app.get '/logout', (req, res) ->
req.session.destroy()
View
8 lib/helper.coffee
@@ -10,3 +10,11 @@ exports.connectRedis = (config) ->
else
redis = require('redis').createClient()
redis
+
+exports.isObject = (v) ->
+ return Object.prototype.toString.call(v) is '[object Object]' or \
+ Object.prototype.toString.call(v) is '[object Function]'
+
+exports.isArray = (v) ->
+ return if Object.prototype.toString.call(v) is '[object Array]'
+
View
36 lib/nohm-instance.coffee
@@ -3,19 +3,11 @@ path = require 'path'
{Nohm} = require 'nohm'
helper = require './helper'
-isObject = (v) ->
- return Object.prototype.toString.call(v) is '[object Object]' or \
- Object.prototype.toString.call(v) is '[object Function]'
-
-isArray = (v) ->
- return if Object.prototype.toString.call(v) is '[object Array]'
-
class NohmInstance
conf:
- login:
- user: 'admin'
- password: 'nohm'
+ login: (username, password) ->
+ return true
redis:
host: 'localhost'
port: '6379'
@@ -25,21 +17,33 @@ class NohmInstance
models: []
- config: (name, value) ->
- unless value?
- return if @conf.name? then @conf.name else null
+ get: () ->
+ c = @conf
+ for arg in arguments
+ return null unless c[arg]?
+ c = c[arg]
+ c
- @conf.name = value
+ set: () ->
+ return @conf if arguments.length < 2
+ node = @conf
+ for arg, k in arguments
+ unless node[arg]?
+ if k is arguments.length - 2
+ node[arg] = arguments[arguments.length - 1]
+ break
+ node[arg] = {}
+ node = node[arg]
@setupNohm()
@conf
setupNohm: ->
models = []
- unless isArray(@conf.models)
+ unless helper.isArray(@conf.models)
@conf.models = [@conf.models]
for v in @conf.models
- if isObject(v)
+ if helper.isObject(v)
models.push v
continue
View
4 package.json
@@ -21,9 +21,9 @@
"redis": "*",
"nohm": "git+ssh://git@github.com:tarkus/nohm.git",
"stylus": "*",
- "nib": "*",
"qs": "*",
- "async": "*"
+ "async": "*",
+ "should": ""
},
"devDependencies": {},
"optionalDependencies": {},
View
5 test/mocha.opts
@@ -0,0 +1,5 @@
+--require should
+--reporter spec
+--compilers coffee:coffee-script
+--ui bdd
+--watch
View
0 views/includes/command.jd
No changes.
View
6 views/includes/model_list.jade
@@ -1,3 +1,7 @@
ul.nav.nav-pills.nav-stacked
+ li.nav-header Models
- for (name in models)
- li(class=(model_name == name) && 'active'): a(href="/model/#{name}") #{name}
+ li(class=(model_name == name) && 'active')
+ a(href="/model/#{name}")
+ i.icon-home
+ #{name}
View
0 views/includes/persistent.jd
No changes.
View
11 views/layout.jade
@@ -33,15 +33,14 @@ body
li: a(href="/dashboard") Dashboard
li: a(href="/command") Command
li: a(href="/persistent") Persistent
- li.dropdown
- a.dropdown-toggle(data-toggle="dropdown", href="#") localhost
- b.caret
- ul.dropdown-menu
- li: a(href="/timeline") localhost
- li: a(href="/timeline") remote
ul.nav.pull-right
li: a(href="/logout") Logout
!= body
+ script(id="command-tpl", type="template")
+ include includes/command.jd
+ script(id="persistent-tpl", type="template")
+ include includes/persistent.jd
+
| </html>
View
2 views/model_overview.jade
@@ -1,7 +1,7 @@
.container
.row-fluid
- .span3
+ .span3.well
include includes/model_list.jade
.span9

0 comments on commit f4af78a

Please sign in to comment.