lookback / meteor-emails

Improved Meteor emails with templating, previews and automated CSS/SCSS inlining.

Home Page:https://atmospherejs.com/lookback/emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature suggestion] handlebar/blaze helpers on server

thebarty opened this issue · comments

Hi guys,

having handlebar helpers available would really enhance SSR from right the start.... right now I keep on manually copying the stuff I need into the global TemplateHelpers.

Those guys here make Blaze really fun:
https://github.com/raix/Meteor-handlebar-helpers

even cooler (but unfortunatly NOT available yet in meteor): https://github.com/assemble/handlebars-helpers

Probably a fork of raix:handlebar-helpers that exports the helpers on the client might do it, but those helpers would probably still have to be attached to SSR (https://github.com/raix/Meteor-handlebar-helpers/blob/master/package.js#L22)

What exact helpers do you need?

Right now I am using those here, but using blaze the whole handlebars-helper package is a real benefit:

  // a quick and dirty copy of the helpers we need right now
  $eq: function(a, b) {
    if (a===b) {
      return true
    } else {
      return false
    }
  },
  // copied from https://github.com/raix/Meteor-handlebar-helpers/blob/11212952089e2f357422e393c6513cd891dd97a1/helpers.operators.js
  $mapped(arr) {
    if(!Array.isArray(arr)){
      try {
        arr = arr.fetch()
      }
      catch (e){
        console.log("Error in $mapped: perhaps you aren't sending in a collection or array.")
        return [];
      }
    }

    var $length = arr.length;

    var mappedArray = arr.map(function(item,index) {
      item.$length = $length;
      item.$index = index;
      item.$first = index === 0;
      item.$last  = index === $length-1;
      item.$secondLast  = index === $length-2;
      return item;
    });

    return mappedArray || [];
  },
  /**
   * Greater than, used in template like $gt variable 1
   * @param  {[type]} a [description]
   * @param  {[type]} b [description]
   * @return {[type]}   [description]
   */
  $gt: function(a, b) {
    if (a>b) {
      return true
    } else {
      return false
    }
  },
  $or(a, b) {
    return (a || b)
  },

Hm, I'm not sure I wanna pull in another dependency. No users of this email package have asked specifically about more template helpers. You can easily depend on a helpers package in your Meteor app and just pass the helpers along to Mailer on init.