ritz078 / embed-js

🌻 A lightweight plugin to embed emojis, media, maps, tweets, code and more. ✨
https://codesandbox.io/s/Wp5OlNMn
MIT License
1.27k stars 88 forks source link

Render embeds with template #203

Closed ansydor closed 7 years ago

ansydor commented 7 years ago

In general, embeds renders with fixed layout.

<div class="ejs-embed ejs-instagram">
<iframe src="https://www.instagram.com/p/-mIWFsIVV-/embed/" height="600"></iframe>
</div>

But It's good to have an ability to change it. Maybe to set a template to render with. Maybe some event where URL comes and render html can be changed. Like:

onEmbed: function(item){
    return '<div>' + item.url + '</div>'
}
ritz078 commented 7 years ago

Well that is actually supported but not properly documented.

const ejs = new EmbedJS(options, template)

Here template is an object containing the render methods just like https://github.com/ritz078/embed.js/blob/master/src/js/modules/template.js

But I see there is an error in https://github.com/ritz078/embed.js/blob/master/src/js/main.js#L163

instead of

this.options.template = template || renderer;

it should actually extend

this.options.template = deepExtend(renderer, template);

Here renderer is the default template object and its should merge with template.

Would you like to send a PR ? Or else I will do it when there's time.