https://github.com/raineorshine/striate
Whitespace-friendly templating
https://github.com/raineorshine/striate
Last synced: 3 months ago
JSON representation
Whitespace-friendly templating
- Host: GitHub
- URL: https://github.com/raineorshine/striate
- Owner: raineorshine
- License: isc
- Created: 2015-08-10T21:47:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T17:25:10.000Z (over 9 years ago)
- Last Synced: 2025-03-10T15:09:35.652Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# striate
[](https://gitter.im/metaraine/striate?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://npmjs.org/package/striate)
[](https://travis-ci.org/metaraine/striate)**striate** is a thin wrapper for [ejs](https://github.com/mde/ejs) that is smart about line breaks, so you don't have to worry so much about delimiter placement.
## Install
```sh
$ npm install --save striate
```## Usage
**striate** uses `>>` at the beginning of a line as the delimiter.
The entire line will be excluded from the output.
```js
var striate = require('striate')var input =
`var a = 10;>> if(b) {
var b = 20;
>> }var c = 30;`
var output1 = striate(input, { b: true })
/*
var a = 10;var b = 20;
var c = 30;
*/var output2 = striate(input, { b: false })
/*
var a = 10;var c = 30;
*/
```### API:
`var output = striate(input, data, options)`
* **input** - The input template (string)
* **data** - The data to be injected into the template (object)
* **options** - Options that are passed along to ejs (object)Options:
```js
{
// By default striate takes data and renders your template using ejs.
// Set to false to output an unrendered ejs template instead.
render: true,
// If you prefer to indent all lines of code between >> delimeters without
// it affecting the output, set this to true.
indent: false
}
```## Under the hood
**striate** transforms templates directly into ejs, but with whitespace placed correctly near delimiters.
```js
var a = 10;>> if(b) {
var b = 20;
>> }var c = 30;
```is exactly the same as the following [ejs]() code:
```js
var a = 10;<% if(b) {
%>var b = 20;
<% }
%>
var c = 30;
```*Note: **striate**'s functionality is similar to slurp syntax `<%_ ... _%>` [introduced in ejs](https://github.com/mde/ejs/pull/105), but better for nested indentation.*
## License
ISC © [Raine Lourie](https://github.com/metaraine)