# rosid-handler-ejs

> Load EJS templates and render them

Latest version **10.0.0** (published 2020-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install rosid-handler-ejs
pnpm add rosid-handler-ejs
yarn add rosid-handler-ejs
bun add rosid-handler-ejs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2020-03-20 |
| First published | 2015-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | electerious |
| Keywords | rosid, handler, transform, compile, ejs, html |

## Links

- npm: https://www.npmjs.com/package/rosid-handler-ejs
- Repository: https://github.com/electerious/rosid-handler-ejs
- Issues: https://github.com/electerious/rosid-handler-ejs/issues
- npm.io page: https://npm.io/package/rosid-handler-ejs

## Dependencies (4)

- [ejs](https://npm.io/package/ejs.md) ^3.0.1
- [locate-path](https://npm.io/package/locate-path.md) ^5.0.0
- [require-data](https://npm.io/package/require-data.md) ^1.0.0
- [continuous-stealthy-require](https://npm.io/package/continuous-stealthy-require.md) ^1.0.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 10.0.0 (latest) — 2020-03-20
- 5.0.0-beta.1 (beta) — 2017-02-02
- 9.2.0 — 2019-01-09
- 9.1.0 — 2018-12-20
- 9.0.0 — 2018-08-25
- 8.0.4 — 2017-10-14
- 8.0.3 — 2017-10-03
- 8.0.2 — 2017-08-08
- 8.0.1 — 2017-07-23
- 8.0.0 — 2017-07-19
- 7.0.4 — 2017-06-30
- 7.0.3 — 2017-06-30
- 7.0.2 — 2017-06-30
- 7.0.1 — 2017-06-10
- 7.0.0 — 2017-03-20
- … 19 more at https://npm.io/package/rosid-handler-ejs/versions

## README

# rosid-handler-ejs

[![Travis Build Status](https://travis-ci.org/electerious/rosid-handler-ejs.svg?branch=master)](https://travis-ci.org/electerious/rosid-handler-ejs) [![Coverage Status](https://coveralls.io/repos/github/electerious/rosid-handler-ejs/badge.svg?branch=master)](https://coveralls.io/github/electerious/rosid-handler-ejs?branch=master)  [![Dependencies](https://david-dm.org/electerious/rosid-handler-ejs.svg)](https://david-dm.org/electerious/rosid-handler-ejs#info=dependencies) [![Greenkeeper badge](https://badges.greenkeeper.io/electerious/rosid-handler-ejs.svg)](https://greenkeeper.io/)

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

## Install

```
npm install rosid-handler-ejs
```

## Usage

### API

```js
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](https://github.com/electerious/Rosid/blob/master/docs/Routes.md). `rosid-handler-ejs` will transform all matching EJS files in your source folder to HTML.

```json
{
	"name"    : "EJS",
	"path"    : "[^_]*.{html,ejs}*",
	"handler" : "rosid-handler-ejs"
}
```

```html
<!-- index.ejs -->
<h1>Hello <%= 'World' %></h1>
```

```html
<!-- 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](#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`.

---
_Source: https://npm.io/package/rosid-handler-ejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
