Skip to content

Instantly share code, notes, and snippets.

@semanticpixel
Created August 16, 2018 16:21
Show Gist options
  • Save semanticpixel/f2a6d0429670d3fe589b4e857b57117a to your computer and use it in GitHub Desktop.
Save semanticpixel/f2a6d0429670d3fe589b4e857b57117a to your computer and use it in GitHub Desktop.
experiment-helper
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
imageURL: 'img/test.png',
styles: {
height: '300px',
'background-image': 'url(img/test.png)',
}
});
import Ember from 'ember';
import { htmlSafe } from '@ember/string';
const GLUE = ':';
const SEPARATOR = ';';
function joinStyles(styles) {
return Object.keys(styles)
.map(style => `${style}${GLUE}${styles[style]}`)
.join(SEPARATOR);
}
export function myHelper(params, hash) {
const styles = joinStyles(hash);
return htmlSafe(styles);
}
export default Ember.Helper.helper(myHelper);
import Ember from 'ember';
const GLUE = '=';
const SEPARATOR = ' ';
function joinParams(params) {
return Object.keys(params)
.map(param => `${param}${GLUE}${params[param]}`)
}
export function myOtherHelper(params) {
const obj = params[0];
console.log(joinParams(obj))
return joinParams(obj);
}
export default Ember.Helper.helper(myOtherHelper);
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{my-helper height='300px' background-image=(concat 'url(' imageURL ')')}}
<br/>
{{log styles}}
<br/>
{{my-helper (my-other-helper styles)}}
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment