rosid-handler-sightly v1.1.1
rosid-handler-sightly
A function that loads an Sightly file and transforms it to HTML.
Install
npm install rosid-handler-sightlyUsage
API
const handler = require('rosid-handler-sightly')
const str = await render(pathToHTL, {data: data})Rosid
Add the following object to your rosidfile.js or routes array. rosid-handler-sightly will transform all matching HTL files in your source folder to HTML.
{
"name" : "HTL",
"path" : "[^_]*.{html,htl}*",
"handler" : "rosid-handler-sightly"
}<!-- index.html / index.htl -->
<h1>Hello ${'World'}</h1><!-- index.html (output) -->
<h1>Hello World</h1>Parameters
filePath{String}Path to file.opts{?Object}Options. -optimize{?Boolean}- Optimize output. Defaults tofalse. -data{?Object|String}- Data used to render the template. Defaults to{}. -localOverwrites{?Boolean}- Enable or disable custom data per file. Defaults totrue.
Returns
{Promise<String|Buffer>}The transformed file content.
Miscellaneous
Data
The data in opts.data will be used to render your template. opts.data can either be an object (the data) or a string (path to data file). rosid-handler-sightly tries to require the path when a string is specified instead of an object. The path must be absolute or relative to the current working directory.
Custom data per file
Create a file with the name filename.data.json or filename.data.js along your filename.htl to add or overwrite data from opts.data. You can disable this behaviour with the localOverwrites option.
Environment
rosid-handler-sightly passes a variable called environment to your template. environment is prod when opts.optimize is true and dev when opts.optimize is false.