@nakedcreativity/cee-ms-node 0.1.4 → 0.2.1

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 +26 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -67,7 +67,26 @@ function ceems(config) {
67
67
 
68
68
 
69
69
  this.app.get(/(.*)/, (req, res)=>{
70
+
71
+ this.render(req,res);
72
+
73
+ })
74
+
75
+ this.app.post(/draft\/(.*)/, (req, res)=>{
76
+
77
+ // validate authorisation JWT here
78
+ this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
79
+ console.log(req.body.page)
80
+ req.query.edit = true;
81
+ this.render(req,res, req.body.page);
82
+
83
+ })
70
84
 
85
+ }
86
+
87
+ ceems.prototype.render = function(req, res, page=null) {
88
+
89
+ if(!page){
71
90
  this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
72
91
  this.pages_map = _.indexBy(this.site.pages, 'url');
73
92
 
@@ -83,22 +102,7 @@ function ceems(config) {
83
102
  }else{
84
103
  res.status(404).send('Sorry, this page does not exist');
85
104
  }
86
-
87
- this.render(page,req,res);
88
-
89
- })
90
-
91
- this.app.post(/draft\/(.*)/, (req, res)=>{
92
-
93
- // validate authorisation JWT here
94
- this.site = JSON.parse(fs.readFileSync('./pages/site.json', 'utf8'));
95
- this.render(req.body.page,req,res);
96
-
97
- })
98
-
99
- }
100
-
101
- ceems.prototype.render = function(page, req, res) {
105
+ }
102
106
 
103
107
  // get any external data, and save this into the page
104
108
  _.each(page.external, function(ext, key){
@@ -138,7 +142,10 @@ ceems.prototype.render = function(page, req, res) {
138
142
  var $ = cheerio.load(html);
139
143
 
140
144
  $.root().children().attr('data-module-type', module.type);
141
- $.root().children().attr('data-module-id', module.id);
145
+ if(module._id){
146
+ $.root().children().attr('data-module-id', module._id);
147
+ }
148
+
142
149
 
143
150
  html = $.html()
144
151
  }
@@ -171,7 +178,7 @@ ceems.prototype.render = function(page, req, res) {
171
178
  if(req.query.edit != null){
172
179
  var $ = cheerio.load(html);
173
180
  $.root().children().attr('data-module-type', module.type);
174
- $.root().children().attr('data-module-id', module.id);
181
+ $.root().children().attr('data-module-id', module._id);
175
182
  //console.log($.root().children())
176
183
 
177
184
  html = $.html()
@@ -200,7 +207,7 @@ ceems.prototype.render = function(page, req, res) {
200
207
  console.log(err)
201
208
  }
202
209
  //res.header('X-FRAME-OPTIONS', 'allow-from http://localhost:3002');
203
- console.log(res)
210
+ //console.log(res)
204
211
  res.send(html)
205
212
  })
206
213
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {