gulp-liquidr v2.0.1
Gulp Liquidr
gulp plugin for LiquidJs, current project https://github.com/icai/gulp-liquidr
Usage
Install
npm install gulp-liquidr --saveOptions
The full list of options for Liquid() is listed as following:
rootis 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["."]extnameis used to lookup the template file when filepath doesn't include an extension name. Eg: setting to".html"will allow including file by basename. Defaults to"".cacheindicates whether or not to cache resolved templates. Defaults tofalse.dynamicPartials: if set, treat<filepath>parameter in{%include filepath %},{%layout filepath%}as a variable, otherwise as a literal value. Defaults totrue.strict_filtersis used to enable strict filter existence. If set tofalse, undefined filters will be rendered as empty string. Otherwise, undefined filters will cause an exception. Defaults tofalse.strict_variablesis used to enable strict variable derivation. If set tofalse, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults tofalse.trim_tag_rightis used to strip blank characters (including,\t, and\r) from the right of tags ({% %}) until\n(inclusive). Defaults tofalse.trim_tag_leftis similiar totrim_tag_right, whereas the\nis exclusive. Defaults tofalse. See Whitespace Control for details.trim_value_rightis used to strip blank characters (including,\t, and\r) from the right of values ({{ }}) until\n(inclusive). Defaults tofalse.trim_value_leftis similiar totrim_value_right, whereas the\nis exclusive. Defaults tofalse. See Whitespace Control for details.greedyis used to specify whethertrim_left/trim_rightis greedy. When set totrue, all consecutive blank characters including\nwill be trimed regardless of line breaks. Defaults totrue.
The above is All Liquidjs initilization options.
tagsis used to Liquidjs instance to callregisterTagfiltersis used to Liquidjs instance to callregisterFilterdatais used to Liquidjs instance to callparseAndRenderwith stream
by the way, extname default is extname: '.html'.
Demo
gulp.task('example', () => {
return gulp.src([
'example/views/**/*.html', // scan
'!example/views/_includes/**/*.html', // filter
'!example/views/_layouts/**/*.html' // filter
])
.pipe(liquidjs({
root: [resolve('views/'), resolve('views/_includes/'), resolve('views/_layouts/')],
filters: {
'add': (initial, arg1, arg2) => initial + arg1 + arg2
},
tags: {
'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'
}
}
}
}))
.pipe(gulp.dest('.tmp'))
})License
Copyright (c) 2017 Terry Cai. Licensed under the MIT license.