Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Last active September 12, 2017 17:10
Show Gist options
  • Save joeljuca/cd6eccd288c31e43661df30ed9cd859f to your computer and use it in GitHub Desktop.
Save joeljuca/cd6eccd288c31e43661df30ed9cd859f to your computer and use it in GitHub Desktop.
const TEMPLATE = [
'<div class="MyComponent @classes" @attributes>',
' <p>',
' @message',
' </p>',
'</div>'
].join('\n').concat('\n')
const defaultParams = {
classes: '',
attributes: '',
message: ''
}
export function render (params) {
params = Object.assign({}, defaultParams, params)
if (params.attributes) {
params.attributes = Object.keys(params.attributes)
.reduce((html, key) => {
return html + `${key}="${params.attributes[key}"`
}, '')
}
return TEMPLATE
.replace('classes', params.classes)
.replace('attributes', params.attributes)
.replace('message', params.message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment