Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
shopify-liquid
Advanced tools
A feature-rich Liquid template engine for Node.js and browsers, with compliance with the Ruby version.
A feature-rich Liquid template engine for Node.js and browsers, with compliance with the Ruby version. New to Liquid? Here's a live demo: http://harttle.com/shopify-liquid/
The Liquid template engine is implemented in Ruby originally, which is used by Jekyll and Github Pages.
Features:
Installation:
npm install --save shopify-liquid
Parse and Render:
var Liquid = require('shopify-liquid');
var engine = Liquid();
engine.parseAndRender('{{name | capitalize}}', {name: 'alice'})
.then(function(html){
// html === 'Alice'
});
Caching templates:
var tpl = engine.parse('{{name | capitalize}}');
engine.render(tpl, {name: 'alice'})
.then(function(html){
// html === 'Alice'
});
var engine = Liquid({
root: path.resolve(__dirname, 'views/'), // for layouts and includes
extname: '.liquid',
cache: false,
strict_filters: false, // default: false
strict_variables: false // default: false
});
engine.renderFile("hello.liquid", {name: 'alice'})
.then(function(html){
// html === 'Alice'
});
// equivalent to:
engine.renderFile("hello", {name: 'alice'})
.then(function(html){
// html === 'Alice'
});
root
is a directory or an array of directories to resolve layouts and includes, as well as the filename passed in when calling .renderFile()
.
If an array, the files are looked up in the order they occur in the array.
Defaults to process.cwd()
extname
is used to lookup the template file when filepath doesn't include an extension name. Defaults to .liquid
cache
indicates whether or not to cache resolved templates. Defaults to false
.
strict_filters
is used to enable strict filter existence. If set to false
, undefined filters will be rendered as empty string. Otherwise, undefined filters will cause an exception. Defaults to false
.
strict_variables
is used to enable strict variable derivation.
If set to false
, undefined variables will be rendered as empty string.
Otherwise, undefined variables will cause an exception. Defaults to false
.
// register liquid engine
app.engine('liquid', engine.express({
strict_variables: true, // Default: fasle
strict_filters: true // Default: false
}));
app.set('views', './views'); // specify the views directory
app.set('view engine', 'liquid'); // set to default
There's an Express demo here.
When using with Express.js, partials(includes and layouts) will be looked up in
both Liquid root
and Express views
directories.
Download the dist files and import into your HTML.
And window.Liquid
is what you want. There's also a demo.
<html lang="en">
<head>
<script src="dist/liquid.min.js"></script>
</head>
<body>
<script>
var engine = window.Liquid();
var src = '{{ name | capitalize}}';
var ctx = {
name: 'welcome to Shopify Liquid'
};
engine.parseAndRender(src, ctx)
.then(function(html) {
// html === Welcome to Shopify Liquid
});
</script>
</body>
</html>
Note: In IE and Android UC browser, you need a Promise implementation registered to any-promise.
// 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 Promise.resolve(str.toUpperCase()); // 'Alice'
}
});
See existing tag implementations: https://github.com/harttle/shopify-liquid/blob/master/tags/
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 20 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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.