@nakedcreativity/cee-ms-node 0.3.3 → 0.3.5

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 +37 -11
  2. 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
- this.match = tagToken.args; // name // path[0] == navigation name
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('submenu.liquid', scope);
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 ', page.path[0])
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
- return this.engine.handleCache('submenu.liquid')
82
+ console.log('render ',this.match[1]+'.liquid')
83
+
84
+ return engine.handleCache(this.match[1]+'.liquid')
74
85
  .then((templates) => {
75
- scope.push(this.site.navigation[page.path[0]]);
76
- return this.engine.renderer.renderTemplates(templates, scope);
86
+
87
+ return engine.renderer.renderTemplates(templates, scope);
77
88
  })
78
89
  .then((html) => {
79
90
  scope.pop();
@@ -123,9 +134,13 @@ function ceems(config) {
123
134
  ceems.prototype.load = function(req, res){
124
135
 
125
136
  var path = req._parsedUrl.pathname.substring(1)
137
+ if(path == '')
138
+ path = 'home'
139
+
126
140
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
127
141
  //this.pages_map = _.indexBy(this.site.pages, 'url');
128
142
 
143
+ site = this.site //????
129
144
 
130
145
  if(this.site.pages[path]){
131
146
  var page = this.site.pages[path]
@@ -135,6 +150,10 @@ ceems.prototype.load = function(req, res){
135
150
  }
136
151
 
137
152
  var page = JSON.parse(fs.readFileSync('./pages/'+page._id+'.json', 'utf8'));
153
+ 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
+ page.path = page.fullpath.split('/')
138
157
  return page
139
158
 
140
159
  }
@@ -149,6 +168,7 @@ ceems.prototype.load = function(req, res){
149
168
 
150
169
  ceems.prototype.render = function(req, res, page=null) {
151
170
 
171
+ console.log('render fn')
152
172
  if(!page){
153
173
  page = this.load(req, res)
154
174
  }
@@ -195,6 +215,7 @@ ceems.prototype.render = function(req, res, page=null) {
195
215
  if (this.site){
196
216
  scope.site = this.site.site
197
217
  scope.pages = this.site.pages
218
+ scope.navigation = this.site.navigation
198
219
  }
199
220
  this.engine.parseAndRender(moduleTemplate, scope)
200
221
  .then(function(html){
@@ -264,7 +285,12 @@ ceems.prototype.render = function(req, res, page=null) {
264
285
  })
265
286
  })
266
287
 
267
- res.render(page.template, page, function(err, html){
288
+ console.log('render finished page')
289
+ var scope = page
290
+ scope.navigation = this.site.navigation
291
+
292
+ //console.log(scope)
293
+ res.render(page.template, scope, function(err, html){
268
294
  if(err){
269
295
  console.log(err)
270
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {