Skip to content

Commit

Permalink
chore(devenv): fix full-render demo (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh committed May 30, 2018
1 parent 8788c1b commit f16bc90
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tools/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ const promiseCache = Promise.all([fractal.load(), loadContents(path.resolve(__di

/**
* @param {Object} [options] The options.
* @param {string} [options.preview] The preview Handlebars template name to force. Useful to force an empty preview.
* @param {string} [options.defaultPreview] The preview Handlebars template name working as the default one.
* @param {string} [options.layout] The Handlebars template name to lay out stuffs.
* @param {boolean} [options.concat] Setting `true` here returns rendered contents all concatenated, instead of returning a map.
* @param {string} [handle]
* The internal component name seen in Fractal.
* Can be of a component or of a variant, or left empty.
* Leaving `handle` empty renders all components.
* @returns {string|Map<Variant, string>} The list of rendered template, keyed by Fractal `Variant` object.
*/
const renderComponent = ({ preview, defaultPreview, concat } = {}, handle) =>
const renderComponent = ({ layout, concat } = {}, handle) =>
promiseCache.then(({ componentSource, contents }) => {
const renderedItems = new Map();
componentSource.forEach(metadata => {
Expand All @@ -88,10 +87,10 @@ const renderComponent = ({ preview, defaultPreview, concat } = {}, handle) =>
const filteredItems = !handle || handle === metadata.handle ? items : items.filter(item => handle === item.handle);
filteredItems.forEach(item => {
const { handle: itemHandle, baseHandle, context } = item;
const template = contents.get(itemHandle) || contents.get(baseHandle);
const template = contents.get(item.preview) || contents.get(itemHandle) || contents.get(baseHandle);
if (template) {
const body = template(context);
const layoutTemplate = contents.get(preview || item.preview || defaultPreview);
const layoutTemplate = contents.get(layout);
renderedItems.set(item, !layoutTemplate ? body : layoutTemplate(Object.assign({ body }, context)));
}
});
Expand Down

0 comments on commit f16bc90

Please sign in to comment.