10.0.0 • Published 4 years ago

rosid-handler-ejs v10.0.0

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

rosid-handler-ejs

Travis Build Status Coverage Status Dependencies Greenkeeper badge

A function that loads an EJS file and transforms it to HTML.

Install

npm install rosid-handler-ejs

Usage

API

const handler = require('rosid-handler-ejs')

handler('index.ejs').then((data) => {})
handler('index.xml').then((data) => {})
handler('index.ejs', { optimize: true }).then((data) => {})
handler('index.ejs', { data: { key: 'value' } }).then((data) => {})
handler('index.ejs', { data: 'data.json' }).then((data) => {})

Rosid

Add the following object to your rosidfile.json, rosidfile.js or routes array. rosid-handler-ejs will transform all matching EJS files in your source folder to HTML.

{
	"name"    : "EJS",
	"path"    : "[^_]*.{html,ejs}*",
	"handler" : "rosid-handler-ejs"
}
<!-- index.ejs -->
<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 to false. - data {?Object|String} - Data used to render the template. Defaults to {}. - localOverwrites {?Boolean} - Enable or disable custom data per file. Defaults to true.

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-ejs 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.ejs to add or overwrite data from opts.data. You can disable this behaviour with the localOverwrites option.

Environment

rosid-handler-ejs passes a variable called environment to your template. environment is prod when opts.optimize is true and dev when opts.optimize is false.

10.0.0

4 years ago

9.2.0

5 years ago

9.1.0

5 years ago

9.0.0

6 years ago

8.0.4

7 years ago

8.0.3

7 years ago

8.0.2

7 years ago

8.0.1

7 years ago

8.0.0

7 years ago

7.0.4

7 years ago

7.0.3

7 years ago

7.0.2

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.0.0

7 years ago

5.1.1

7 years ago

5.1.0

7 years ago

5.0.0

7 years ago

5.0.0-beta.1

7 years ago

5.0.0-beta.0

7 years ago

4.0.0

7 years ago

3.1.0

7 years ago

3.0.0

8 years ago

3.0.0-beta.0

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.1.0-beta.1

8 years ago

2.1.0-beta.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago