Gottwik / Enduro

Minimalistic, lean & mean, node.js cms
http://www.endurojs.com/
MIT License
690 stars 121 forks source link

Enduro helpers on content update #274

Open DJercic opened 6 years ago

DJercic commented 6 years ago

I've created a site in enduro and I wrote a few helpers that relay on options.fn and options.inverse. Everything works fine when I start the server (development and production mode), but when the content gets updated in the cms/* folder, helper instead of an usual content (helper works on if/else principle) returns a string "[Object]".

Is this caused by my helpers or the enduro itself has a bug? Any ideas would be welcomed.

Node version: v8.11.1 enduro version: 1.4.46

Helper code:

function compare(a, operator, b, options) {

if (arguments.length < 4) {
  throw new Error('handlebars Helper {{compare}} expects 4 arguments');
}

var result;
switch (operator) {
  case '==':
    result = a == b;
    break;
  case '===':
    result = a === b;
    break;
  case '!=':
    result = a != b;
    break;
  case '!==':
    result = a !== b;
    break;
  case '<':
    result = a < b;
    break;
  case '>':
    result = a > b;
    break;
  case '<=':
    result = a <= b;
    break;
  case '>=':
    result = a >= b;
    break;
  case 'typeof':
    result = typeof a === b;
    break;
  default: {
    throw new Error('helper {{compare}}: invalid operator: `' + operator + '`');
  }
}    
if (result) {
    return options.fn(this);
} else {
    return options.inverse(this);
}
};
enduro.templating_engine.registerHelper("compare", compare);