2019-02-25 18:04:49 +07:00
|
|
|
module.exports = function createCard(card) {
|
2019-09-20 14:31:42 +01:00
|
|
|
const {name, type, config = {}} = card;
|
2019-02-25 18:04:49 +07:00
|
|
|
|
|
|
|
return {
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
render({env, payload, options}) {
|
|
|
|
const {dom} = env;
|
|
|
|
const cleanName = name.replace(/^card-/, '');
|
|
|
|
|
|
|
|
const cardOutput = card.render({env, payload, options});
|
|
|
|
|
|
|
|
if (!cardOutput) {
|
|
|
|
return cardOutput;
|
|
|
|
}
|
|
|
|
|
2019-09-20 14:31:42 +01:00
|
|
|
if (config.commentWrapper) {
|
|
|
|
const beginComment = dom.createComment(`kg-card-begin: ${cleanName}`);
|
|
|
|
const endComment = dom.createComment(`kg-card-end: ${cleanName}`);
|
|
|
|
const fragment = dom.createDocumentFragment();
|
2019-02-25 18:04:49 +07:00
|
|
|
|
2019-09-20 14:31:42 +01:00
|
|
|
fragment.appendChild(beginComment);
|
|
|
|
fragment.appendChild(cardOutput);
|
|
|
|
fragment.appendChild(endComment);
|
2019-02-25 18:04:49 +07:00
|
|
|
|
2019-09-20 14:31:42 +01:00
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cardOutput;
|
2019-02-25 18:04:49 +07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|