nire0510
2/29/2016 - 11:21 AM

Ember helper: safe binding of inline style

Ember helper: safe binding of inline style

import Ember from 'ember';

export function inlineStyle(params, hash) {
  let strInnerStyle = '';

  for (let key in hash) {
    if (hash.hasOwnProperty(key)) {
      hash[key] = (key === 'background-image') ? `url(${hash[key]})` : `${hash[key]}`;

      strInnerStyle += `${key}: ${hash[key]}; `;
    }
  }

  return new Ember.Handlebars.SafeString(strInnerStyle);
}

export default Ember.Helper.helper(inlineStyle);