@nakedcreativity/cee-ms-node 0.3.9 → 0.3.11

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 +71 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -66,27 +66,21 @@ function ceems(config) {
66
66
  this.match = tagToken.args.split(' '); // name // path[0] == navigation name
67
67
  },
68
68
  render: function(scope, hash){
69
- var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
69
+ //var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
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]]);
75
74
  }else if(page.path && this.match[0] == 'page.path[1]' && site.navigation[page.path[1]]){
76
- console.log('navigation exists for ', this.match[0])
77
75
  scope.push(site.navigation[page.path[1]]);
78
76
  }else if(site.navigation[this.match[0]]){
79
77
  scope.push(site.navigation[this.match[0]]);
80
78
  }else {
81
79
  return
82
80
  }
83
- // look for navigation that match the name of any part of the path?
84
-
85
- console.log('render ',this.match[1]+'.liquid')
86
81
 
87
82
  return engine.handleCache(this.match[1]+'.liquid')
88
83
  .then((templates) => {
89
-
90
84
  return engine.renderer.renderTemplates(templates, scope);
91
85
  })
92
86
  .then((html) => {
@@ -96,6 +90,76 @@ function ceems(config) {
96
90
  }
97
91
  });
98
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 path', this.match[0])
102
+
103
+ if(site.pages[this.match[0]]){
104
+ var page = site.pages[this.match[0]]
105
+ console.log(page)
106
+ if(page.redirect){
107
+ res.redirect(parseInt(page.redirect.type), page.redirect.to)
108
+ }
109
+
110
+ var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
111
+ page.fullpath = site.pages[this.match[0]].url
112
+ page.path = page.fullpath.split('/')
113
+
114
+ console.log(page)
115
+ scope.push(page)
116
+
117
+ return engine.handleCache(this.match[1]+'.liquid')
118
+ .then((templates) => {
119
+ return engine.renderer.renderTemplates(templates, scope);
120
+ })
121
+ .then((html) => {
122
+ scope.pop();
123
+ return html;
124
+ });
125
+
126
+ }else {
127
+ return
128
+ }
129
+
130
+
131
+
132
+ }
133
+ })
134
+
135
+ this.engine.registerTag('blog', {
136
+ parse: function(tagToken, remainTokens) {
137
+ this.match = tagToken.args.split(' ')
138
+ },
139
+ render: function(scope, hash){
140
+
141
+ console.log('render blog', this.match[0])
142
+ console.log(site.blogs[this.match[0]])
143
+
144
+ if(!site.blogs[this.match[0]]){
145
+ console.log('no match')
146
+ return
147
+ }
148
+ console.log(this.match[1], 'look for liquid template')
149
+ scope.push(site.blogs[this.match[0]])
150
+ return engine.handleCache(this.match[1]+'.liquid')
151
+ .then((templates) => {
152
+ return engine.renderer.renderTemplates(templates, scope);
153
+ })
154
+ .then((html) => {
155
+ scope.pop();
156
+ return html;
157
+ });
158
+ }
159
+
160
+ })
161
+
162
+
99
163
  this.app.listen(config.port, function () {});
100
164
 
101
165
  this.app.use((req, res, next)=>{
@@ -154,8 +218,6 @@ ceems.prototype.load = function(req, res){
154
218
 
155
219
  var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
156
220
  page.fullpath = this.site.pages[path].url
157
- console.log(this.site.pages[path])
158
- console.log('full path is', this.site.pages[path].url)
159
221
  page.path = page.fullpath.split('/')
160
222
  return page
161
223
 
@@ -174,7 +236,6 @@ ceems.prototype.load = function(req, res){
174
236
 
175
237
  ceems.prototype.render = function(req, res, page=null) {
176
238
 
177
- console.log('render fn')
178
239
  if(!page){
179
240
  page = this.load(req, res)
180
241
  }
@@ -226,7 +287,6 @@ ceems.prototype.render = function(req, res, page=null) {
226
287
  this.engine.parseAndRender(moduleTemplate, scope)
227
288
  .then(function(html){
228
289
 
229
-
230
290
  if(req.query.edit != null){
231
291
  var $ = cheerio.load(html);
232
292
 
@@ -234,8 +294,6 @@ ceems.prototype.render = function(req, res, page=null) {
234
294
  if(module._id){
235
295
  $.root().children().attr('data-module-id', module._id);
236
296
  }
237
-
238
-
239
297
  html = $.html()
240
298
  }
241
299
 
@@ -291,7 +349,6 @@ ceems.prototype.render = function(req, res, page=null) {
291
349
  })
292
350
  })
293
351
 
294
- console.log('render finished page')
295
352
  var scope = page
296
353
  if(this.site && this.site.navigation)
297
354
  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.9",
3
+ "version": "0.3.11",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {