striate is a thin wrapper for ejs that is smart about line breaks, so you don't have to worry so much about delimiter placement.
$ npm install --save striate
striate uses >>
at the beginning of a line as the delimiter.
The entire line will be excluded from the output.
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;
*/
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:
{
// 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
}
striate transforms templates directly into ejs, but with whitespace placed correctly near delimiters.
var a = 10;
>> if(b) {
var b = 20;
>> }
var c = 30;
is exactly the same as the following ejs code:
var a = 10;
<% if(b) {
%>var b = 20;
<% }
%>
var c = 30;
Note: striate's functionality is similar to slurp syntax <%_ ... _%>
introduced in ejs, but better for nested indentation.
ISC © Raine Lourie