-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.coffee
More file actions
39 lines (32 loc) · 869 Bytes
/
db.coffee
File metadata and controls
39 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local_data={}
_ = require 'underscore'
stringify = (data,spaces)->
if _.isArray(data)
code=""
data.forEach (elem)->
if(code isnt "")
code+="\n"
code+=spaces+elem
code
else
spaces+data
module.exports =
init_db:(config, data)->
local_data = data
#read_db:(config, group, template, cb)->
# if(local_data.hasOwnProperty group) and (local_data[group].hasOwnProperty template)
# cb null, local_data[group][template]
# else
# cb ("Template not found for "+group+"/"+template)
read_db:(config, context, path_list, cb)->
val=local_data
err=null
path_list.forEach (elem)->
if val.hasOwnProperty elem
val=val[elem]
else
err="template doesn't exist."
if (_.isObject val) and (!_.isArray val)
cb err, val
else
cb err, (stringify val,context.spaces)