mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feature: support static filepath resolving by options.dynamicPartials,
fix #51
This commit is contained in:
@@ -86,6 +86,8 @@ Defaults to `["."]`
|
||||
|
||||
* `cache` indicates whether or not to cache resolved templates. Defaults to `false`.
|
||||
|
||||
* `dynamicPartials`: if set, treat `<filepath>` parameter in `{%include filepath %}`, `{%layout filepath%}` as a variable, otherwise as a literal value. Defaults to `true`.
|
||||
|
||||
* `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.
|
||||
|
||||
@@ -115,6 +115,7 @@ function factory (options) {
|
||||
root: ['.'],
|
||||
cache: false,
|
||||
extname: '',
|
||||
dynamicPartials: true,
|
||||
trim_tag_right: false,
|
||||
trim_tag_left: false,
|
||||
trim_value_right: false,
|
||||
|
||||
@@ -172,6 +172,7 @@ function matchRightBracket (str, begin) {
|
||||
|
||||
exports.factory = function (ctx, opts) {
|
||||
var defaultOptions = {
|
||||
dynamicPartials: true,
|
||||
strict_variables: false,
|
||||
strict_filters: false,
|
||||
blocks: {},
|
||||
|
||||
+4
-1
@@ -16,7 +16,10 @@ module.exports = function (liquid) {
|
||||
}
|
||||
},
|
||||
render: function (scope, hash) {
|
||||
var filepath = Liquid.evalValue(this.value, scope)
|
||||
var filepath = this.value
|
||||
if (scope.opts.dynamicPartials) {
|
||||
filepath = Liquid.evalValue(this.value, scope)
|
||||
}
|
||||
|
||||
var originBlocks = scope.opts.blocks
|
||||
var originBlockMode = scope.opts.blockMode
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ module.exports = function (liquid) {
|
||||
this.tpls = liquid.parser.parse(remainTokens)
|
||||
},
|
||||
render: function (scope, hash) {
|
||||
var layout = Liquid.evalValue(this.layout, scope)
|
||||
var layout = scope.opts.dynamicPartials ? Liquid.evalValue(this.layout, scope) : this.layout
|
||||
|
||||
// render the remaining tokens immediately
|
||||
scope.opts.blockMode = 'store'
|
||||
|
||||
@@ -88,4 +88,14 @@ describe('tags/include', function () {
|
||||
return expect(liquid.renderFile('personInfo.html', ctx)).to
|
||||
.eventually.equal('This is a person <p>Joe Shmoe<br/>City: Dallas</p>')
|
||||
})
|
||||
|
||||
it('should support static filename', function () {
|
||||
var staticLiquid = new Liquid({dynamicPartials: false, root: '/'})
|
||||
mock({
|
||||
'/with.html': 'X{% include color.html shape: "rect" %}Y',
|
||||
'/color.html': 'shape:{{shape}}'
|
||||
})
|
||||
return expect(staticLiquid.renderFile('with.html')).to
|
||||
.eventually.equal('Xshape:rectY')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -96,4 +96,13 @@ describe('tags/layout', function () {
|
||||
return expect(liquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackredA')
|
||||
})
|
||||
it('should support static filename', function () {
|
||||
mock({
|
||||
'/parent.html': '{{color}}{%block%}{%endblock%}',
|
||||
'/main.html': '{% layout parent.html color:"black"%}{%block%}A{%endblock%}'
|
||||
})
|
||||
var staticLiquid = Liquid({ root: '/', dynamicPartials: false })
|
||||
return expect(staticLiquid.renderFile('/main.html')).to
|
||||
.eventually.equal('blackA')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user