1.0.0 • Published 4 years ago

rockplate v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

MIT License Build Status codecov.io Code Coverage dependencies Status devDependencies Status HitCount

Rockplate

Templating language for sensible humans

Rockplate Demo

Documentation and Demo

Click here for full documentation with demo and examples.

Quick Docs for the curious cats

Installation

npm install rockplate

Usage

TypeScript/JavaScript

import { Rockplate } from 'rockplate';

const template = 'My name is [my name]';
const schema = {
  my: {
    name: 'My Name',
  },
};
const rpl = new Rockplate(template, schema);
const output = rpl.parse({
  // you will get type hints
  // for properties in schema as you type
  my: {
    name: 'Safraz Razik',
  },
});
console.log(output); // My name is Safraz Razik

Syntax and Schema/Data structure

Limitations are good - for a templating language

Booleans

Values: true | false

{
  "order" : {
    "paid": true
  },
  "vegetables": {
    "fresh": true // example for " are " operator
  }

}

Syntax: [if order is paid] .... [end if]

Operators: is | are | is not | are not

[if order is paid]
  Paid
[else]
  Unpaid
[end if]
I eat
[if vegetables are fresh]
  healthy
[end if]
vegetables 🥕🥦🍅🍆🥝🥬🥒🌶

Identifers

Values: string | number or any printable value

{
  "order" : {
    "ref": "210045-674558-981560"
  }
}

Syntax: [order ref]

Thank you for your order [order ref]

Arrays

Value: Collection of Booleans or Identifers

{
  "orders" : [
    {
      "order" : {
        "status": "Paid",
        "ref": "210045-674558-981560"
      },
      "discount" : {
        "available": false,
        "amount": "5%"
      }
    }
  ]
}

Syntax: [repeat orders] .... [end repeat]

Your orders:
[repeat orders]

 Ref: [order ref]

 Status: [order status]

 [if discount is available]
   Discount: [discount amount]
 [end if]

[end repeat]