nxus-renderer

3.0.0 • Public • Published

nxus-renderer

Build Status

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 content
  • content string The contents to render
  • opts object=(default {}) 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 handle
  • handler function Function to receive (content, options) and return rendered content

renderFile

Provide a renderer for a particular type (file extension)

Parameters

  • filename string Path to content to render
  • opts object=(default {}) Options for the renderer context

Returns Promise The rendered content

Package Sidebar

Install

npm i nxus-renderer

Weekly Downloads

1

Version

3.0.0

License

MIT

Last publish

Collaborators

  • mjreich