Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@reboot-ui/liquidjs

harttle46MIT9.7.0TypeScript support: included

Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.

liquid, template engine, express, jinja, shopify

readme

@reboot-ui/liquidjs

NOTICE This repo is one fork version for liquidjs, only serve for reboot-ui's requirements. If necessary, we are happly to re-contribute feature/bugfix to orignal repo :)

semver of @reboot-ui/liquidjs would keep same major/minor with the original repo, all synchronization/modification would be reflected in patch of version.

npm version downloads

liquidjs

npm version downloads Build Status Coveralls dependencies semantic-release GitHub issues GitHub contributors David David Dev DUB license Commitizen friendly open collective

A shopify compatible Liquid template engine in pure JavaScript. The purpose of this repo is to provide a standard Liquid implementation for the JavaScript community. All features, filters and tags in shopify/liquid are supposed to be built in LiquidJS, though there are still some differences and limitations (see below).

Version 9 has published, see how to migrate to 9.0.0!

Get Started

Install via npm:

npm install --save liquidjs
var { Liquid } = require('liquidjs');
var engine = new Liquid();

engine
    .parseAndRender('{{name | capitalize}}', {name: 'alice'})
    .then(console.log);     // outputs 'Alice'

Or include the UMD build, a live demo is available on jsfiddle: https://jsfiddle.net/x43eb0z6/. You may need a Promise polyfill for Node.js < 4 and ES5 browsers like IE and Android UC.

<script src="//unpkg.com/liquidjs/dist/liquid.min.js"></script>     <!--for production-->
<script src="//unpkg.com/liquidjs/dist/liquid.js"></script>         <!--for development-->

Also available from CLI:

echo '{{"hello" | capitalize}}' | npx liquidjs

For detailed documents, see:

  • The Wiki Page contains tutorials and advanced topics.
  • The API Reference provides detailed descriptions for classes, methods and properties.

Differences and Limitations

  • Dynamic file locating (enabled by default), that means layout/partial names are treated as variables in liquidjs. See #51.
  • Truthy and Falsy. All values except undefined, null, false are truthy, whereas in Ruby Liquid all except nil and false are truthy. See #26.
  • Number. In JavaScript we cannot distinguish or convert between float and integer, see #59. And when applied size filter, numbers always return 0, which is 8 for integer in ruby, cause they do not have a length property.
  • .to_liquid() is replaced by .toLiquid()
  • .to_s() is replaced by JavaScript .toString()

Features that available on shopify website but not on shopify/liquid repo will not be implemented in this repo, but there're some plugins available: https://github.com/harttle/liquidjs/wiki/Plugins

  • gulp-liquidjs: A shopify compatible Liquid template engine for Gulp using liquidjs.
  • grunt-liquify: A Grunt task to process Liquid using liquidjs. Use it to add Liquid magic to your scripts and css assets.
  • react-liquid: Liquid templating language component for React
  • @11ty/eleventy: A simpler static site generator. An alternative to Jekyll. Written in JavaScript. Transforms a directory of templates (of varying types) into HTML.

Contribute Guidelines

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind are welcome! Thanks goes to these wonderful people:


Jun Yang

🚧 💻

chenos

💻

Zach Leatherman

🐛

Tim Hardy

💻

Paul Robert Lloyd

💻 🐛

Alec Larson

💻

Patrick Malouin

💻 📖

jaswrks

💻

三三

💻 🤔

ssendev

💻 📖

wojtask9

💻

Andrew Barclay

💻

Cory Mawhorter

💻

Mehdi Jaffery

💻

Robin Bijlani

💻 🐛

Ryan Kennedy

💻

Sami Kukkonen

💻

Scott Santucci

💻

Steven

💡 💻

azu

📖

Joonas

💻

Jamel A.

💻

Brandon Pittman

💻

tgrandgent

💻

Martin Schuster

💻

donate to liquidjs collective

changelog

9.7.0 (2020-02-07)

Bug Fixes

Features

9.6.2 (2020-01-10)

Performance Improvements

  • prevent multiple case evaluations (807e840)

9.6.1 (2020-01-04)

Bug Fixes

  • add this to fs references in parseFile (4b079c5)

9.6.0 (2019-12-15)

Features

9.5.0 (2019-12-12)

Features

9.4.2 (2019-11-15)

Bug Fixes

  • reading .first, .last of Array, closes #175 (f82da11)

9.4.1 (2019-11-15)

Bug Fixes

  • remove node dependencies for esm bundle, see #173 (04df929)

9.4.0 (2019-11-14)

Features

  • add ability to pass JSON context to CLI (9504e4e)

9.3.1 (2019-11-09)

Bug Fixes

  • liquidjs command in /bin/liquid.js, fixes #169 (0073b90)

9.3.0 (2019-11-07)

Features

  • support require.resolve for lookup, see #168 (2dd4355)

9.1.1 (2019-10-10)

Performance Improvements

  • add string flattening to reduce retained memory (node only) (3ad512c)

9.1.0 (2019-10-07)

Features

  • alias getTemplate() to parseFile() (6b83788)

9.0.1 (2019-10-02)

Bug Fixes

9.0.0 (2019-08-26)

Bug Fixes

  • break/continue omitting output before them, #123 (ae45c46)
  • reactjs demo during yarn install, fixes #145 (b65df44)

Code Refactoring

  • return value of Tag#render is no longer used (8028f82)

Features

  • renderSync, parseAndRenderSync and renderFileSync, see #48 (7fb01ad)

Performance Improvements

BREAKING CHANGES

  • Tag#render now returns void, use emitter argument to write rendered html.
  • ship to Node.js 8, the dist/liquid.cjs.js (main) nolonger supports Node.js 6, other bundles are also provided via dist/liquid.esm.js, dist/liquid.js (ES5 umd) and liquid.min.js (minified ES5 umd)
  • remove default export, now should be used like import {Liquid} from 'liquidjs'

8.5.3 (2019-08-25)

Bug Fixes

  • escape filter when input is undefined (a00945c)

8.5.2 (2019-08-09)

Bug Fixes

8.5.1 (2019-08-05)

Bug Fixes

8.5.0 (2019-08-01)

Features

8.4.1 (2019-07-22)

Bug Fixes

  • some filters on undefined variable throws, #140 (6e6ea0a)

8.4.0 (2019-07-06)

Features

8.3.0 (2019-06-27)

Features

8.2.4 (2019-06-17)

Performance Improvements

  • improve getTemplate() when cache is enabled (1ffba2b)

8.2.3 (2019-05-19)

Bug Fixes

8.2.2 (2019-05-12)

Bug Fixes

8.2.1 (2019-04-26)

Bug Fixes

  • default filter is not working with an empty string, #122 (6075c0a)

8.2.0 (2019-04-17)

Features

  • pass context to filters (00bc1ef)

8.1.0 (2019-04-02)

Features

8.0.3 (2019-04-01)

Bug Fixes

8.0.2 (2019-03-25)

Performance Improvements

  • use polymophism instead duck test (82d7673)

8.0.1 (2019-03-22)

Bug Fixes

  • incorrect scope when using assign with for, fixes #115 (defbb58)

8.0.0 (2019-03-10)

Code Refactoring

  • use camelCase for JavaScript APIs (64e0c87)

Features

  • promise support for drops, working on #65 (4a8088d)

BREAKING CHANGES

  • Options and method names in JavaScript API are now renamed to cammelCase, for a complete list see #109

7.5.1 (2019-03-05)

Bug Fixes

7.5.0 (2019-03-01)

Features

7.4.0 (2019-02-28)

Bug Fixes

  • math filters now return number, resolves #110 (b4acdb4)

Features

7.3.1 (2019-02-25)

Bug Fixes

  • #108: remove absolute path in emitted d.ts (53a835a), closes #108

7.3.0 (2019-02-24)

Features

  • nil/null/empty/blank literals, resolves #102 (88c9e96)

7.2.2 (2019-02-23)

Bug Fixes

  • filters break when argument contains [()|, fixes #89 (e977669)

7.2.1 (2019-02-22)

Bug Fixes

  • default length for truncate and truncatewords (56c7992)

7.2.0 (2019-02-20)

Features

  • override output/tag delimiter, fixes #54 (d20a043)

BREAKING CHANGES

  • trim_value_left option renamed to trim_output_left, trim_value_right option renamed to trim_output_right

7.1.0 (2019-02-20)

Features

  • throw an Error if delimiter not matched (c33d8f6)

7.0.0 (2019-02-14)

chore

  • TypeScript: ship Liquid to class (1cc7249)

BREAKING CHANGES

  • TypeScript: calling Liquid() without new now becomes invalid

6.4.3 (2019-02-13)

Bug Fixes

  • better index.d.ts and a demo (2015f68), closes #98

6.4.2 (2019-01-28)

Bug Fixes

  • CI: e2e not building cjs (dde7b3b)

6.4.1 (2019-01-28)

Bug Fixes