@communities-webruntime/services
Version:
If you would like to run Lightning Web Runtime without the CLI, we expose some of our programmatic APIs available in Node.js. If you're looking for the CLI documentation [you can find that here](https://www.npmjs.com/package/@communities-webruntime/cli).
47 lines • 1.79 kB
JavaScript
/** @hidden */
/**
* Copyright (c) 2019, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import pretty from 'pretty';
import { component } from '../template-generators/template-utils.js';
import { DEFAULT_ATTRIBUTES, generateAttributesJS } from './attributes-js-generator.js';
export { generateAttributesJS };
/**
* Generate an LWC template for a provided component
*
* @param {object*} cmp - The top level component to render an LWC template for
* @param {boolean} isThemeLayout - Whether that component is a theme layout or not
*/
export function template(cmp, isThemeLayout, isRenderDesignMode = false) {
const result = component({
cmp,
isThemeLayout,
regionName: null,
// regionKey: null,
attributeSet: {},
isTopLevel: true,
isRenderDesignMode,
});
const attributesVal = generateAttributesJS(result.attributes.attributes);
return {
html: pretty(`<template lwc:render-mode="light">${result.html}</template>`, { ocd: true }),
attributes: attributesVal,
};
}
/**
* Generates javascript which imports an HTML file and exports the HTML as default
*
* @param {string} moduleName - The name of the view, used to specify the import location of the HTML
* @param {string} attributesVal - The attribute set value of the view, used to inject component attribute values during runtime
*/
export function javascript(moduleName, attributesVal) {
return `import html from './${moduleName}.html'
export default {
"html": html,
"attributes": ${attributesVal || DEFAULT_ATTRIBUTES}
}`;
}
//# sourceMappingURL=view-template-generator.js.map