@nakedcreativity/cee-ms-node 0.3.8 → 0.3.10

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.
Files changed (2) hide show
  1. package/index.js +46 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -70,20 +70,17 @@ function ceems(config) {
70
70
  var page = scope.scopes[0]
71
71
 
72
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
73
  scope.push(site.navigation[page.path[0]]);
74
+ }else if(page.path && this.match[0] == 'page.path[1]' && site.navigation[page.path[1]]){
75
+ scope.push(site.navigation[page.path[1]]);
75
76
  }else if(site.navigation[this.match[0]]){
76
77
  scope.push(site.navigation[this.match[0]]);
77
78
  }else {
78
79
  return
79
80
  }
80
- // look for navigation that match the name of any part of the path?
81
-
82
- console.log('render ',this.match[1]+'.liquid')
83
81
 
84
82
  return engine.handleCache(this.match[1]+'.liquid')
85
83
  .then((templates) => {
86
-
87
84
  return engine.renderer.renderTemplates(templates, scope);
88
85
  })
89
86
  .then((html) => {
@@ -93,6 +90,50 @@ function ceems(config) {
93
90
  }
94
91
  });
95
92
 
93
+ this.engine.registerTag('page', {
94
+ parse: function(tagToken, remainTokens) {
95
+ this.match = tagToken.args.split(' '); // name // path[0] == navigation name
96
+ },
97
+ render: function(scope, hash){
98
+ // var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
99
+ var page = scope.scopes[0]
100
+
101
+ console.log('look for page with handle', this.match[0])
102
+ var site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
103
+ console.log(site)
104
+
105
+ if(site.pages[this.match[0]]){
106
+ var page = site.pages[this.match[0]]
107
+ console.log(page)
108
+ if(page.redirect){
109
+ res.redirect(parseInt(page.redirect.type), page.redirect.to)
110
+ }
111
+
112
+ var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
113
+ page.fullpath = site.pages[this.match[0]].url
114
+ page.path = page.fullpath.split('/')
115
+
116
+ scope.push(page)
117
+
118
+ return engine.handleCache(this.match[1]+'.liquid')
119
+ .then((templates) => {
120
+ return engine.renderer.renderTemplates(templates, scope);
121
+ })
122
+ .then((html) => {
123
+ scope.pop();
124
+ return html;
125
+ });
126
+
127
+ }else {
128
+ return
129
+ }
130
+
131
+
132
+
133
+ }
134
+ })
135
+
136
+
96
137
  this.app.listen(config.port, function () {});
97
138
 
98
139
  this.app.use((req, res, next)=>{
@@ -151,8 +192,6 @@ ceems.prototype.load = function(req, res){
151
192
 
152
193
  var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
153
194
  page.fullpath = this.site.pages[path].url
154
- console.log(this.site.pages[path])
155
- console.log('full path is', this.site.pages[path].url)
156
195
  page.path = page.fullpath.split('/')
157
196
  return page
158
197
 
@@ -171,7 +210,6 @@ ceems.prototype.load = function(req, res){
171
210
 
172
211
  ceems.prototype.render = function(req, res, page=null) {
173
212
 
174
- console.log('render fn')
175
213
  if(!page){
176
214
  page = this.load(req, res)
177
215
  }
@@ -223,7 +261,6 @@ ceems.prototype.render = function(req, res, page=null) {
223
261
  this.engine.parseAndRender(moduleTemplate, scope)
224
262
  .then(function(html){
225
263
 
226
-
227
264
  if(req.query.edit != null){
228
265
  var $ = cheerio.load(html);
229
266
 
@@ -231,8 +268,6 @@ ceems.prototype.render = function(req, res, page=null) {
231
268
  if(module._id){
232
269
  $.root().children().attr('data-module-id', module._id);
233
270
  }
234
-
235
-
236
271
  html = $.html()
237
272
  }
238
273
 
@@ -288,7 +323,6 @@ ceems.prototype.render = function(req, res, page=null) {
288
323
  })
289
324
  })
290
325
 
291
- console.log('render finished page')
292
326
  var scope = page
293
327
  if(this.site && this.site.navigation)
294
328
  scope.navigation = this.site.navigation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {