/striate

Whitespace-friendly templating

Primary LanguageJavaScriptISC LicenseISC

striate

Join the chat at https://gitter.im/metaraine/striate npm version Build Status

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.

Install

$ 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.

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:

{
  // 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.

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.

License

ISC © Raine Lourie