@nakedcreativity/cee-ms-node 0.3.34 → 0.3.36

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 +113 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -357,28 +357,51 @@ function ceems(config) {
357
357
  if(!site.blogs[this.match[0]]){
358
358
  return
359
359
  }
360
+
361
+ // loop over articles, push articles that match tag or pagination, into array
362
+
360
363
  var blog = site.blogs[this.match[0]]
364
+ var pagination = 1
365
+
361
366
  if(scope.scopes[0].page && scope.scopes[0].page.pagination){
362
- blog.pagination = scope.scopes[0].page.pagination
363
- }else {
364
- blog.pagination = 1
367
+ pagination = scope.scopes[0].page.pagination
365
368
  }
366
369
 
367
- blog.articlesPerPage = parseInt(articlesPerPage);
370
+ articlesPerPage = parseInt(articlesPerPage)
371
+ var start = articlesPerPage * (pagination - 1)
372
+ var end = start + articlesPerPage
368
373
 
369
- blog.start = articlesPerPage * (blog.pagination - 1)
370
- blog.end = blog.start + articlesPerPage
371
-
372
- blog.lastPage = Math.ceil(blog.articles.length / articlesPerPage)
373
-
374
- scope.push(blog)
374
+ var lastPage = Math.ceil(blog.articles.length / articlesPerPage)
375
375
 
376
376
  // is page greater than the number of articles?
377
377
  // throw a 404
378
- if(blog.start >= blog.articles.length){
378
+ if(start >= blog.articles.length){
379
379
  throw new Error('This page does not exist')
380
380
  }
381
381
 
382
+ var articles = []
383
+
384
+
385
+ // if tag set, create filtered array of articles
386
+ if(this.match[3]){
387
+ var tag = Liquid.lexical.parseLiteral(this.match[3])
388
+
389
+ blog.articles.forEach((article) => {
390
+ if (article.tags && article.tags.indexOf(tag) > -1){
391
+ articles.push(article)
392
+ }
393
+ })
394
+ }else {
395
+ articles = blog.articles
396
+ }
397
+
398
+ // slice original blog array to send just current page of articles to liquid
399
+ blog.articles = articles.slice(start,end)
400
+ blog.pagination = pagination
401
+ blog.lastPage = lastPage
402
+ scope.push(blog)
403
+
404
+
382
405
  return engine.handleCache(this.match[1]+'.liquid')
383
406
  .then((templates) => {
384
407
  return engine.renderer.renderTemplates(templates, scope);
@@ -518,12 +541,69 @@ ceems.prototype.render = function(req, res, page=null) {
518
541
  console.log('pagination, ', page.pagination)
519
542
 
520
543
  var renderedRegions = {}
544
+ var renderedColumns = {}
545
+ var renderedModules = {}
546
+
521
547
  var jobs = []
522
548
 
523
549
  // load page data
524
550
  _.each(page.regions, function(region, key){
525
551
 
526
552
  renderedRegions[key] = []
553
+ console.log(key)
554
+
555
+ if(region.containers){
556
+
557
+ region.containers.forEach((container, index)=>{
558
+
559
+ console.log(container)
560
+ if(container.module){
561
+
562
+ var html = `{% ${container.module} %}`
563
+
564
+ }else {
565
+
566
+
567
+ if(!container.class) {
568
+ container.class = 'container'
569
+ }
570
+
571
+ var html = ''
572
+ if(container.wrapper){
573
+ html += `<div class="${container.wrapper}">`
574
+ }
575
+
576
+ html += `<div class="${container.class}">`
577
+
578
+ container.rows.forEach(row=>{
579
+
580
+ html += `<div class="row ${row.class}">`
581
+ row.columns.forEach(column=>{
582
+
583
+ var modules = _.reduce(column.modules, (modules, id)=>{
584
+ return modules + '{% '+id+' %}'
585
+ }, '')
586
+ html += `<div class="col ${column.class}">${modules}</div>` // inserts placeholder in format {% id %}
587
+
588
+ })
589
+
590
+ html += `</div>`
591
+
592
+ })
593
+ if(container.wrapper){
594
+ html += `</div>`
595
+ }
596
+ html += `</div>`
597
+
598
+ }
599
+
600
+ renderedRegions[key][index] = html
601
+
602
+ })
603
+ }
604
+
605
+ console.log(renderedRegions)
606
+
527
607
  _.each(region.modules, function(module, index){
528
608
 
529
609
  var moduleTemplate = fs.readFileSync('./views/'+module.type+'.liquid');
@@ -539,7 +619,7 @@ ceems.prototype.render = function(req, res, page=null) {
539
619
  scope.navigation = this.site.navigation
540
620
  }
541
621
  this.engine.parseAndRender(moduleTemplate, scope)
542
- .then(function(html){
622
+ .then(html => {
543
623
 
544
624
  if(req.query.edit != null){
545
625
  var $ = cheerio.load(html);
@@ -549,10 +629,15 @@ ceems.prototype.render = function(req, res, page=null) {
549
629
  $.root().children().attr('data-module-id', module._id);
550
630
  }
551
631
  html = $.html()
552
- }
553
-
554
- renderedRegions[key][index] = html
555
- return resolve();
632
+ }
633
+
634
+ if(region.containers){
635
+ renderedModules[module._id] = html
636
+ }else {
637
+ renderedRegions[key][index] = html
638
+ }
639
+ return resolve();
640
+
556
641
  })
557
642
  .catch(error=>{
558
643
  reject(error)
@@ -560,6 +645,8 @@ ceems.prototype.render = function(req, res, page=null) {
560
645
  }))
561
646
 
562
647
  }, this)
648
+
649
+
563
650
  }, this)
564
651
 
565
652
  // loop through each module not in a region and generate HTML
@@ -605,10 +692,20 @@ ceems.prototype.render = function(req, res, page=null) {
605
692
  _.each(renderedRegions, function(region, key){
606
693
  page.regions[key] = ''
607
694
  _.each(region, function(html){
695
+
696
+ // items in rendered columns to place
697
+ if(Object.keys(renderedModules).length > 0){
698
+ _.each(renderedModules, (moduleHtml, key)=>{
699
+ html = html.replace(new RegExp('{%\\s'+key+'\\s%}','g'), moduleHtml)
700
+ })
701
+
702
+ }
703
+
608
704
  page.regions[key] += html
609
705
  })
610
706
  })
611
707
 
708
+
612
709
  var scope = page
613
710
  if(this.site && this.site.navigation)
614
711
  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.34",
3
+ "version": "0.3.36",
4
4
  "description": "Cee.ms for Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {