hogan-express icon indicating copy to clipboard operation
hogan-express copied to clipboard

Lambdas/filters down seem to work

Open konsumer opened this issue 10 years ago • 1 comments

The argument doesn;t seem to be coming through. I tried with code like this:

var colorPop = function(c){
  console.log('color', c);
  c = c || '#000000';
  var color = new Chromath(c);
  return (color.hsv().v >= 50) ? Chromath.darken(color, 0.5).toString() : Chromath.lighten(color, 0.5).toString();
};
router.post('/', function(req, res, next) {
  var voteIn = {
    'ip': req.headers['x-forwarded-for'] || req.connection.remoteAddress,
    'attention': req.body.attention,
    'meditation': req.body.meditation,
    'delta': req.body.delta,
    'theta': req.body.theta,
    'lowAlpha': req.body.lowAlpha,
    'highAlpha': req.body.highAlpha,
    'lowBeta': req.body.lowBeta,
    'highBeta': req.body.highBeta,
    'lowGamma': req.body.lowGamma,
    'highGamma': req.body.highGamma
  };
  var vote = new Vote(voteIn);

  vote.save(function(err, vote){
    if (err) return next(err);
    Vote.find({}, function(err, votes){
      if (err) return next(err);
      if (!votes.length) return next(new Error('No one has voted.'));
      res.render('votes', {votes:votes,lambdas:{colorPop:colorPop}});
    });
  });
});
{{#votes}}
        <ul class="list-inline">
            <li style="color:{{#lambdas.colorPop}}{{attention}}{{/lambdas.colorPop}};background-color:{{attention}}">attention</li>
            <li style="color:{{#lambdas.colorPop}}{{meditation}}{{/lambdas.colorPop}};background-color:{{meditation}}">meditation</li>
            <li style="color:{{#lambdas.colorPop}}{{delta}}{{/lambdas.colorPop}};background-color:{{delta}}">delta</li>
            <li style="color:{{#lambdas.colorPop}}{{theta}}{{/lambdas.colorPop}};background-color:{{theta}}">theta</li>
            <li style="color:{{#lambdas.colorPop}}{{lowAlpha}}{{/lambdas.colorPop}};background-color:{{lowAlpha}}">lowAlpha</li>
            <li style="color:{{#lambdas.colorPop}}{{highAlpha}}{{/lambdas.colorPop}};background-color:{{highAlpha}}">highAlpha</li>
            <li style="color:{{#lambdas.colorPop}}{{lowBeta}}{{/lambdas.colorPop}};background-color:{{lowBeta}}">lowBeta</li>
            <li style="color:{{#lambdas.colorPop}}{{highBeta}}{{/lambdas.colorPop}};background-color:{{highBeta}}">highBeta</li>
            <li style="color:{{#lambdas.colorPop}}{{lowGamma}}{{/lambdas.colorPop}};background-color:{{lowGamma}}">lowGamma</li>
            <li style="color:{{#lambdas.colorPop}}{{highGamma}}{{/lambdas.colorPop}};background-color:{{highGamma}}">highGamma</li>
        </ul>
    {{/votes}}

konsumer avatar Feb 18 '15 03:02 konsumer

@konsumer It's possible something is broken with lambdas provided directly in the data passed to render. We've only ever used lambdas defined on app.settings. We set all our lambdas up right away in our main app. I know the code tries to merge lambdas from various places but possibly that doesn't (or never) worked. This module is no longer maintained (as far as I can tell), but I've migrated it here and published it as hogan-xpress. You're welcome to try your use case with that code and open an issue there if it still exists.

tandrewnichols avatar Jul 18 '17 00:07 tandrewnichols