Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/herber/twz

🧙 Magic templates
https://github.com/herber/twz

magic template template-engine

Last synced: 2 days ago
JSON representation

🧙 Magic templates

Awesome Lists containing this project

README

        

# Twz [![Build Status](https://travis-ci.org/herber/twz.svg?branch=master)](https://travis-ci.org/herber/twz) [![codecov](https://codecov.io/gh/herber/twz/badge.svg?branch=master)](https://codecov.io/gh/herber/twz?branch=master)

> 🧙 Magic templates

## Features
- Tiny at just 23 loc
- Based on tagged template literals

## Install

```
$ npm install twz
```

## Usage

```js
const twz = require('twz');

twz('

${ emoji }

')({ emoji: '🧙' });
```

## Examples

### List

```js
const twz = require('twz');

const listTemplate = '

    ${ list.map(n => `
  • ${n}
  • `).join('')
';

twz(listTemplate)({ list: [ '1', '2', '3' ] });
// =>


  • 1

  • 2

  • 3


```

### Heading

```js
const twz = require('twz');

twz('

${ name }

')({ name: 'my name' });
```

## API

### twz(input)(data)

Returns the rendered template `string`.

#### input

Type: `string`

A twz string.

#### data

Type: `object`

An object representing the template's data.

### twz.file(path)(data)

Returns a `promise`

#### path

Type: `string`

The template's path.

#### data

Type: `object`

An object representing the template's data.

### twz.fileSync(path)(data)

Returns the rendered template `string`.

#### path

Type: `string`

The template's path.

#### data

Type: `object`

An object representing the template's data.

## License

MIT © [Tobias Herber](http://tobihrbr.com)