Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
shopify-liquid
Advanced tools
Liquid implementation for Node.js. All tags and filters listed in Shopify Documentation shall be implemented.
Shopify liquid is used by Jekyll and Github Pages.
Installation:
npm install --save shopify-liquid
Parse and Render:
var Liquid = require('shopify-liquid');
var engine = Liquid();
engine.parseAndRender('{{name | capitalize}}', {name: 'alice'}); // Alice
Caching templates:
var tpl = engine.parse('{{name | capitalize}}');
engine.render(tpl, {name: 'alice'}); // Alice
var engine = Liquid({
root: path.resolve(__dirname, 'views/'), // for layouts and partials
extname: '.liquid',
cache: false
});
// equivalent to: engine.renderFile("hello", {name: 'alice'});
var html = engine.renderFile("hello.liquid", {name: 'alice'});
cache
default to false
, extname
default to .liquid
, root
default to ""
.
app.engine('liquid', engine.express());
app.set('views', './views'); // specify the views directory
app.set('view engine', 'liquid'); // register the template engine
// file: color.liquid
color: '{{ color }}' shape: '{{ shape }}'
// file: theme.liquid
{% assign shape = 'circle' %}
{% include 'color' %}
{% include 'color' with 'red' %}
{% include 'color', color: 'yellow', shape: 'square' %}
The output will be:
color: '' shape: 'circle'
color: 'red' shape: 'circle'
color: 'yellow' shape: 'square'
// file: default-layout.liquid
Header
{% block content %}My default content{% endblock %}
Footer
// file: page.liquid
{% layout "default-layout" %}
{% block content %}My page content{% endblock %}
The output of page.liquid
:
Header
My page content
Footer
// Usage: {{ name | uppper }}
engine.registerFilter('upper', function(v){
return v.toUpperCase();
});
See existing filter implementations: https://github.com/harttle/shopify-liquid/blob/master/filters.js
// Usage: {% upper name%}
engine.registerTag('upper', {
parse: function(tagToken, remainTokens) {
this.str = tagToken.args; // name
},
render: function(scope, hash) {
var str = Liquid.evalValue(this.str, scope); // 'alice'
return str.toUpperCase(); // 'Alice'
}
});
See existing tag implementations: https://github.com/harttle/shopify-liquid/blob/master/tags/
Documentation: https://shopify.github.io/liquid/basics/operators/
==
, !=
, >
, <
, >=
, <=
, or
, and
, contains
.
Documentation: https://shopify.github.io/liquid/basics/introduction/#tags
Tag | Document | Source | Test |
---|---|---|---|
case/when | Document | Source | Test |
if | Document | Source | Test |
unless | Document | Source | Test |
elsif/else | Document | Source | Test |
for | Document | Source | Test |
break | Document | Source | Test |
continue | Document | Source | Test |
for: limit,offset,range,reversed | Document | Source | Test |
cycle | Document | Source | Test |
cycle: group | Document | Source | Test |
tablerow | Document | Source | Test |
tablerow: cols,limit,offset,range | Document | Source | Test |
assign | Document | Source | Test |
capture | Document | Source | Test |
increment | Document | Source | Test |
decrement | Document | Source | Test |
raw | Document | Source | Test |
comment | Document | Source | Test |
include | Document | Source | Test |
layout, block | Document | Source | Test |
Documentation: https://shopify.github.io/liquid/basics/introduction/#filters
harttle/shopify-liquid do NOT support async rendering, this is by design.
The primary principle of harttle/shopify-liquid is EASY TO EXTEND. Async rendering introduces extra complexity in both implementation and extension.
For template-driven projects, checkout these Liquid-like engines:
FAQs
A feature-rich Liquid template engine for Node.js and browsers, with compliance with the Ruby version.
The npm package shopify-liquid receives a total of 14 weekly downloads. As such, shopify-liquid popularity was classified as not popular.
We found that shopify-liquid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.