@nakedcreativity/cee-ms-node 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +39 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,6 +6,10 @@ var Liquid = require('nakedcreativity-liquid');
|
|
|
6
6
|
var cheerio = require('cheerio');
|
|
7
7
|
var bodyParser = require("body-parser");
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
var site;
|
|
11
|
+
var engine;
|
|
12
|
+
|
|
9
13
|
function ceems(config) {
|
|
10
14
|
|
|
11
15
|
this.app = express()
|
|
@@ -21,6 +25,7 @@ function ceems(config) {
|
|
|
21
25
|
extname: '.liquid',
|
|
22
26
|
cache: true
|
|
23
27
|
});
|
|
28
|
+
engine = this.engine
|
|
24
29
|
|
|
25
30
|
this.config = config;
|
|
26
31
|
|
|
@@ -32,6 +37,7 @@ function ceems(config) {
|
|
|
32
37
|
this.app.set('views', this.viewsPath());
|
|
33
38
|
this.app.set('view engine', 'liquid');
|
|
34
39
|
|
|
40
|
+
|
|
35
41
|
|
|
36
42
|
// register region and module tags
|
|
37
43
|
this.engine.registerTag('region', {
|
|
@@ -39,7 +45,7 @@ function ceems(config) {
|
|
|
39
45
|
this.name = tagToken.args; // name
|
|
40
46
|
},
|
|
41
47
|
render: function(scope, hash) {
|
|
42
|
-
console.log(this.name)
|
|
48
|
+
console.log('render region',this.name)
|
|
43
49
|
var str = Liquid.evalValue('regions.'+this.name, scope);
|
|
44
50
|
return Promise.resolve(str);
|
|
45
51
|
}
|
|
@@ -56,24 +62,29 @@ function ceems(config) {
|
|
|
56
62
|
});
|
|
57
63
|
|
|
58
64
|
this.engine.registerTag('navigation', {
|
|
59
|
-
parse: (tagToken, remainTokens)
|
|
60
|
-
|
|
65
|
+
parse: function(tagToken, remainTokens) {
|
|
66
|
+
this.match = tagToken.args.split(' '); // name // path[0] == navigation name
|
|
61
67
|
},
|
|
62
|
-
render: (scope, hash)
|
|
63
|
-
var filepath = Liquid.evalValue('
|
|
68
|
+
render: function(scope, hash){
|
|
69
|
+
var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
|
|
64
70
|
var page = scope.scopes[0]
|
|
65
71
|
|
|
66
|
-
if(page.path && this.site.navigation[page.path[0]]){
|
|
67
|
-
console.log('navigation exists for ',
|
|
72
|
+
if(page.path && this.match[0] == 'page.path[0]' && site.navigation[page.path[0]]){
|
|
73
|
+
console.log('navigation exists for ', this.match[0])
|
|
74
|
+
scope.push(site.navigation[page.path[0]]);
|
|
75
|
+
}else if(site.navigation[this.match[0]]){
|
|
76
|
+
scope.push(site.navigation[this.match[0]]);
|
|
68
77
|
}else {
|
|
69
78
|
return
|
|
70
79
|
}
|
|
71
80
|
// look for navigation that match the name of any part of the path?
|
|
72
81
|
|
|
73
|
-
|
|
82
|
+
console.log('render ',this.match[1]+'.liquid')
|
|
83
|
+
|
|
84
|
+
return engine.handleCache(this.match[1]+'.liquid')
|
|
74
85
|
.then((templates) => {
|
|
75
|
-
|
|
76
|
-
return
|
|
86
|
+
|
|
87
|
+
return engine.renderer.renderTemplates(templates, scope);
|
|
77
88
|
})
|
|
78
89
|
.then((html) => {
|
|
79
90
|
scope.pop();
|
|
@@ -105,8 +116,7 @@ function ceems(config) {
|
|
|
105
116
|
this.app.post(/draft\/(.*)/, (req, res)=>{
|
|
106
117
|
|
|
107
118
|
// validate authorisation JWT here
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
|
|
110
120
|
//console.log(req.body.page)
|
|
111
121
|
req.query.edit = true;
|
|
112
122
|
|
|
@@ -127,6 +137,7 @@ ceems.prototype.load = function(req, res){
|
|
|
127
137
|
this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
|
|
128
138
|
//this.pages_map = _.indexBy(this.site.pages, 'url');
|
|
129
139
|
|
|
140
|
+
site = this.site //????
|
|
130
141
|
|
|
131
142
|
if(this.site.pages[path]){
|
|
132
143
|
var page = this.site.pages[path]
|
|
@@ -136,6 +147,10 @@ ceems.prototype.load = function(req, res){
|
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
|
|
150
|
+
page.fullpath = this.site.pages[path].url
|
|
151
|
+
console.log(this.site.pages[path])
|
|
152
|
+
console.log('full path is', this.site.pages[path].url)
|
|
153
|
+
page.path = page.fullpath.split('/')
|
|
139
154
|
return page
|
|
140
155
|
|
|
141
156
|
}
|
|
@@ -150,6 +165,7 @@ ceems.prototype.load = function(req, res){
|
|
|
150
165
|
|
|
151
166
|
ceems.prototype.render = function(req, res, page=null) {
|
|
152
167
|
|
|
168
|
+
console.log('render fn')
|
|
153
169
|
if(!page){
|
|
154
170
|
page = this.load(req, res)
|
|
155
171
|
}
|
|
@@ -193,9 +209,11 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
193
209
|
// to-do: we need to give module access to entire page object, and therefore the 'sitemap' and other site information
|
|
194
210
|
var scope = module.content
|
|
195
211
|
scope.page = page
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
212
|
+
if (this.site){
|
|
213
|
+
scope.site = this.site.site
|
|
214
|
+
scope.pages = this.site.pages
|
|
215
|
+
scope.navigation = this.site.navigation
|
|
216
|
+
}
|
|
199
217
|
this.engine.parseAndRender(moduleTemplate, scope)
|
|
200
218
|
.then(function(html){
|
|
201
219
|
|
|
@@ -264,7 +282,12 @@ ceems.prototype.render = function(req, res, page=null) {
|
|
|
264
282
|
})
|
|
265
283
|
})
|
|
266
284
|
|
|
267
|
-
|
|
285
|
+
console.log('render finished page')
|
|
286
|
+
var scope = page
|
|
287
|
+
scope.navigation = this.site.navigation
|
|
288
|
+
|
|
289
|
+
//console.log(scope)
|
|
290
|
+
res.render(page.template, scope, function(err, html){
|
|
268
291
|
if(err){
|
|
269
292
|
console.log(err)
|
|
270
293
|
}
|