You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sadly, it's not possible to generate the DOM for an Ember component in this manner using public API's.
For reference, our renderer for fastboot looks something like this:
importEmberfrom'ember';importRendererfrom'ember-mobiledoc-dom-renderer';importComponentfrom'ember-component';importcomputedfrom'ember-computed';importinjectfrom'ember-service/inject';importcreateComponentCardfrom'ember-mobiledoc-editor/utils/create-component-card';import{optimizedUrl}from'../services/cloudinary';exportconstcards=['image-card','images-card','video-card'];const{ uuid }=Ember;const{ camelize }=Ember.String;constCARD_ELEMENT_CLASS='__rendered-mobiledoc-card';constCARD_TAG_NAME='div';constUUID_PREFIX='__rendered-mobiledoc-entity-';exportdefaultComponent.extend({tagName: '',cardNames: cards,fastboot: inject(),isFastBoot: computed.readOnly('fastboot.isFastBoot'),// When in FastBoot mode, where rendering the Mobiledoc is a one-shot// operation, we can build the DOM directly and return the serialized value// as this computed property. This lets us insert the raw HTML into the// rendered output.renderedMobiledoc: computed(function(){let_this=this;letSimpleDOM=FastBoot.require('simple-dom');letdoc=newSimpleDOM.Document();letcards=this.get('cardNames').map(cardName=>createComponentCard(cardName,doc));letmobiledoc=this.get('mobiledoc');letrenderer=newRenderer({
cards,dom: doc,cardOptions: {addComponent({env, options, payload}){let{name: cardName, dom }=env;letdomForCard=camelize('domFor-'+cardName);// it is not possible to generate DOM for an Ember component without using// a template so we need to hand-craft the mobiledoc card components// when in the fastboot runtimeletelement=_this[domForCard](dom,payload);letcard={
cardName,destinationElementId: element.getAttribute('id'),
payload
};return{ card, element };},removeComponent: Ember.K}});let{ result, teardown }=renderer.render(mobiledoc);letHTMLSerializer=newSimpleDOM.HTMLSerializer(SimpleDOM.voidMap);letserialized=HTMLSerializer.serialize(result);// Immediately teardown once we've serializedteardown();returnserialized;}),domForImagesCard(doc,payload){letclassNames=[CARD_ELEMENT_CLASS,`${CARD_ELEMENT_CLASS}-images-card`];letparent=createElement(doc,CARD_TAG_NAME,classNames);letel1=createElement(doc,'div',['images-card']);letel2=createElement(doc,'div');el1.appendChild(el2);payload.images.forEach(image=>{letdiv=createElement(doc,'div');letimg=createElement(doc,'img');img.setAttribute('src',optimizedUrl(image.url));div.appendChild(img);el2.appendChild(div);});parent.appendChild(el1);if(payload.caption){letp=createElement(doc,'p',['caption']);letcaption=doc.createTextNode(payload.caption);p.appendChild(caption);parent.appendChild(p);}returnparent;},domForVideoCard(doc,payload){letclassNames=[CARD_ELEMENT_CLASS,`${CARD_ELEMENT_CLASS}-video-car`];letparent=createElement(doc,CARD_TAG_NAME,classNames);letposterUrl=payload.posterUrl;letel1=createElement(doc,'div',['video-card']);letel2=createElement(doc,'div',['lazyLoad-container']);if(posterUrl){el2.setAttribute('style',`background-image:url("${optimizedUrl(posterUrl)}")`);}el1.appendChild(el2);parent.appendChild(el1);returnparent;}});functiongenerateUuid(){return`${UUID_PREFIX}${uuid()}`;}functioncreateElement(dom,tagName,classNames=[]){letel=dom.createElement(tagName);el.setAttribute('id',generateUuid());el.setAttribute('class',classNames.join(' '));returnel;}exportfunctionbuildMobiledoc(initialString=""){return{"version": "0.3.0","atoms": [],"cards": [],"markups": [],"sections": [[1,"p",[[0,[],0,initialString]]]]};}
The text was updated successfully, but these errors were encountered:
The mobiledoc-dom-renderer takes a dom argument which is then available on the env passed to the card hook. You should be able to thread through a document or simple dom instance there, and then your cards can be generic. I'll ping you on Slack.
@habdelra as we discussed on that hangout last week, you should have no problem getting fastboot happy with the ember-mobiledoc-dom-renderer 0.5.2 (with ember-wormhole 0.4.0, fastboot compat). Please give it a try!
Closing this for now but we can reopen if something was missed :-)
This is kinda related to issue #50, but a very specific scenario. For FastBoot we use the mobiledoc DOM renderer with SimpleDOM. This means that we are not using this particular component to render our mobiledoc component cards https://github.com/bustlelabs/ember-mobiledoc-dom-renderer/blob/master/addon/components/render-mobiledoc.js (we do use this component to render component when running from the browser though). As such, when constructing the renderer, we need to provide
cardOptions.addComponent
to instruct the renderer on how to assemble the DOM for the component card, as cards are rendered thusly: https://github.com/bustlelabs/ember-mobiledoc-editor/blob/master/addon/utils/create-component-card.js#L22.Sadly, it's not possible to generate the DOM for an Ember component in this manner using public API's.
For reference, our renderer for fastboot looks something like this:
The text was updated successfully, but these errors were encountered: