github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/utils/properties/style-string.js (about)

     1  import Ember from 'ember';
     2  
     3  const { computed } = Ember;
     4  
     5  // An Ember.Computed property for transforming an object into an
     6  // html compatible style attribute
     7  //
     8  // ex. styleProps: { color: '#FF0', border-width: '1px' }
     9  //     styleStr: styleStringProperty('styleProps') // color:#FF0;border-width:1px
    10  export default function styleStringProperty(prop) {
    11    return computed(prop, function() {
    12      const styles = this.get(prop);
    13      let str = '';
    14  
    15      if (styles) {
    16        str = Object.keys(styles)
    17          .reduce(function(arr, key) {
    18            const val = styles[key];
    19            arr.push(key + ':' + (typeof val === 'number' ? val.toFixed(2) + 'px' : val));
    20            return arr;
    21          }, [])
    22          .join(';');
    23      }
    24  
    25      return str.htmlSafe();
    26    });
    27  }