@nxus/renderer
v2.4.0-3
Published
Rendering framework for Nxus applications/
Downloads
1
Readme
@nxus/renderer
A rendering framework for Nxus applications.
Installation
In your Nxus application:
> npm install @nxus/renderer --save
Usage
Defining a renderer
app.get('renderer').renderer(type, handler);
Where type
is usually the filename extension and handler
returns the rendered text when called with contents to render and an optional opts
object.
Rendering a string
app.get('renderer').render(type, text).then((renderedText) => {console.log(renderedText)});
You can pass an optional arugment opts
for options to pass to the renderer.
app.get('renderer').render(type, text, {title: 'My Title'}).then((renderedText) => {console.log(renderedText)});
Rendering a file
app.get('renderer').renderFile(type, filename).then((renderedText) => {});
You can pass an optional arugment opts
for options to pass to the renderer.
API
Renderer
Renderer renders different files and content using common rendering engines, like EJS and MarkDown.
render
Request rendered content based on type
Parameters
type
string The type (e.g. 'html') of the contentcontent
string The contents to renderopts
object Options for the renderer context
Returns Promise The rendered content
renderer
Provide a renderer for a particular type (file extension)
Parameters
type
string The type (e.g. 'html') this renderer should handlehandler
function Function to receive (content, options) and return rendered content
renderFile
Provide a renderer for a particular type (file extension)
Parameters
Returns Promise The rendered content