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

https://github.com/macdonaldr93/liquidlite

Liquid (Lite) is a minimal Shopify Liquid compiler for the browser.
https://github.com/macdonaldr93/liquidlite

html liquid liquid-templating-engine shopify shopify-theme template template-engine

Last synced: about 1 month ago
JSON representation

Liquid (Lite) is a minimal Shopify Liquid compiler for the browser.

Awesome Lists containing this project

README

          

# ๐Ÿ’ง Liquid (Lite)

![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/%40bloombug/liquidlite) ยท ![tests](https://github.com/macdonaldr93/liquidlite/actions/workflows/test.yml/badge.svg)

Liquid (Lite) is a minimal Shopify Liquid compiler for the browser.

## Getting started

```bash
# for npm
npm install @bloombug/liquidlite
# for yarn
yarn add @bloombug/liquidlite
```

```js
import {compile} from '@bloombug/liquidlite';

const template = `

Hi, my name is {{ name }}.

`;
const variables = {name: 'Ryan'};

compile(template, variables);
//

Hi, my name is Ryan.


```

## Why build a compiler for a subset of liquid?

Liquid is a popular templating language and used to build Shopify themes. I've often needed a basic templating language to load in some dynamic content, but I don't want to use a different syntax like handlebars.

This project started because I was always including this snippet of code:

```js
export function compile(template, context) {
let output = template;

for (const variable in context) {
const value = context[variable];

if (typeof value === 'string') {
output = output
.replaceAll(`{{${variable}}}`, value)
.replaceAll(`{{ ${variable} }}`, value);
}
}

return output;
}
```

It's not the best, but it was largely working for what I needed.

It finally got to a point where I need some control flow statements. And there you have it, `liquidlite`.

## Supported features

| Feature | Symbol | Support |
| ------------------------ | ----------- | ------- |
| objects | `{{ }}` | โœ… |
| equals | `==` | โœ… |
| greater than | `>` | โœ… |
| less than | `<` | โœ… |
| greater than or equal to | `>=` | โœ… |
| less than or equal to | `<=` | โœ… |
| logical or | `or` | โŒ |
| logical and | `and` | โŒ |
| contains | `contains` | โŒ |
| control flow if | `if` | โœ… |
| control flow unless | `unless` | โŒ |
| control flow elsif | `elsif` | โŒ |
| control flow else | `else` | โŒ |
| control flow case | `case` | โŒ |
| iteration for | `for` | โŒ |
| template comment | `comment` | โŒ |
| template inline comment | `#` | โŒ |
| template raw | `raw` | โŒ |
| template liquid | `liquid` | โŒ |
| template echo | `echo` | โŒ |
| template render | `render` | โŒ |
| template include | `include` | โŒ |
| variable assign | `assign` | โŒ |
| variable capture | `capture` | โŒ |
| variable increment | `increment` | โŒ |
| variable decrement | `decrement` | โŒ |
| filters | `\|` | โŒ |