@nakedcreativity/cee-ms-node 0.3.3 → 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.
Files changed (2) hide show
  1. package/index.js +34 -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();
@@ -126,6 +137,7 @@ ceems.prototype.load = function(req, res){
126
137
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
127
138
  //this.pages_map = _.indexBy(this.site.pages, 'url');
128
139
 
140
+ site = this.site //????
129
141
 
130
142
  if(this.site.pages[path]){
131
143
  var page = this.site.pages[path]
@@ -135,6 +147,10 @@ ceems.prototype.load = function(req, res){
135
147
  }
136
148
 
137
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('/')
138
154
  return page
139
155
 
140
156
  }
@@ -149,6 +165,7 @@ ceems.prototype.load = function(req, res){
149
165
 
150
166
  ceems.prototype.render = function(req, res, page=null) {
151
167
 
168
+ console.log('render fn')
152
169
  if(!page){
153
170
  page = this.load(req, res)
154
171
  }
@@ -195,6 +212,7 @@ ceems.prototype.render = function(req, res, page=null) {
195
212
  if (this.site){
196
213
  scope.site = this.site.site
197
214
  scope.pages = this.site.pages
215
+ scope.navigation = this.site.navigation
198
216
  }
199
217
  this.engine.parseAndRender(moduleTemplate, scope)
200
218
  .then(function(html){
@@ -264,7 +282,12 @@ ceems.prototype.render = function(req, res, page=null) {
264
282
  })
265
283
  })
266
284
 
267
- res.render(page.template, page, function(err, html){
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
  }
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.4",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {