2.4.0-3 • Published 10 years ago
@nxus/renderer v2.4.0-3
@nxus/renderer
A rendering framework for Nxus applications.
Installation
In your Nxus application:
> npm install @nxus/renderer --saveUsage
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
typestring The type (e.g. 'html') of the contentcontentstring The contents to renderoptsobject Options for the renderer context
Returns Promise The rendered content
renderer
Provide a renderer for a particular type (file extension)
Parameters
typestring The type (e.g. 'html') this renderer should handlehandlerfunction 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