Last active
September 12, 2017 17:10
-
-
Save joeljuca/cd6eccd288c31e43661df30ed9cd859f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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