@nakedcreativity/cee-ms-node 0.3.23 → 0.3.25

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 +55 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -160,19 +160,23 @@ function ceems(config) {
160
160
  render: function(scope, hash){
161
161
  // var filepath = Liquid.evalValue(this.match[1]+'.liquid', scope);
162
162
 
163
- //console.log('look for data collection', this.match[0])
164
-
165
- if(site.collections[this.match[0]]){
166
- //console.log(site.collections[this.match[0]]._id)
167
- var collection = JSON.parse(fs.readFileSync('./data/'+site.collections[this.match[0]]._id+'.json', 'utf8'));
163
+ var collectionName = Liquid.evalValue(this.match[0], scope)
164
+
165
+ if(site.collections[collectionName]){
166
+ //console.log(site.collections[collection]._id)
167
+ var collection = JSON.parse(fs.readFileSync('./data/'+site.collections[collectionName]._id+'.json', 'utf8'));
168
168
 
169
169
  var scopeObj = {}
170
- scopeObj[this.match[0]] = collection.data
170
+ scopeObj['collection'] = collection
171
171
  scope.push(scopeObj)
172
172
 
173
173
  //console.log(scope)
174
-
175
- return engine.handleCache(this.match[1]+'.liquid')
174
+ var template = Liquid.lexical.parseLiteral(this.match[1])
175
+ if (!template) {
176
+ template = this.match[1]
177
+ }
178
+
179
+ return engine.handleCache(template+'.liquid')
176
180
  .then((templates) => {
177
181
  return engine.renderer.renderTemplates(templates, scope);
178
182
  })
@@ -186,6 +190,39 @@ function ceems(config) {
186
190
  }
187
191
  }
188
192
  })
193
+
194
+ this.engine.registerTag('external', {
195
+ parse: function (tagToken, remainTokens) {
196
+ this.match = tagToken.args.split(' '); // name // path[0] == navigation name
197
+ },
198
+ render: function (scope, hash) {
199
+
200
+ var filepath = Liquid.lexical.parseLiteral(this.match[0])
201
+ var jsonData = JSON.parse(fs.readFileSync(filepath, 'utf8'))
202
+
203
+ var scopeObj = {}
204
+ scopeObj['external'] = jsonData
205
+ scope.push(scopeObj)
206
+
207
+ //console.log(scope)
208
+ var template = Liquid.lexical.parseLiteral(this.match[1])
209
+ if (!template) {
210
+ template = this.match[1]
211
+ }
212
+
213
+ return engine.handleCache(template + '.liquid')
214
+ .then((templates) => {
215
+ return engine.renderer.renderTemplates(templates, scope);
216
+ })
217
+ .then((html) => {
218
+ scope.pop();
219
+ return html;
220
+ });
221
+
222
+ }
223
+ })
224
+
225
+
189
226
  this.engine.registerFilter('active', (path, match, cssClass) => {
190
227
 
191
228
  var regex = new RegExp("^"+match)
@@ -212,6 +249,11 @@ function ceems(config) {
212
249
  render: function(scope, hash) {
213
250
  var image = Liquid.evalExp(this.args[0], scope);
214
251
  //console.log(image)
252
+
253
+ if(!image){
254
+ return Promise.resolve('')
255
+ }
256
+
215
257
  if(this.args[1] && image.variants && image.variants[this.args[1]]){
216
258
  var src = image.variants[this.args[1]]
217
259
  }else {
@@ -228,6 +270,11 @@ function ceems(config) {
228
270
  },
229
271
  render: function(scope, hash) {
230
272
  var image = Liquid.evalExp(this.args[0], scope);
273
+
274
+ if(!image){
275
+ return Promise.resolve('')
276
+ }
277
+
231
278
  //console.log(image)
232
279
  if(this.args[1] && image.variants && image.variants[this.args[1]]){
233
280
  var src = image.variants[this.args[1]]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedcreativity/cee-ms-node",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {