mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix string type checking and circular reference, working on #81
This commit is contained in:
+8
-8
@@ -1,6 +1,7 @@
|
||||
const Syntax = require('./syntax.js')
|
||||
const mapSeries = require('./util/promise.js').mapSeries
|
||||
const RenderBreakError = require('./util/error.js').RenderBreakError
|
||||
const _ = require('./util/underscore.js')
|
||||
const RenderError = require('./util/error.js').RenderError
|
||||
const assert = require('./util/assert.js')
|
||||
|
||||
@@ -27,9 +28,7 @@ var render = {
|
||||
return this.renderTag(template, scope)
|
||||
.then(partial => partial === undefined ? '' : partial)
|
||||
} else if (template.type === 'value') {
|
||||
return Promise.resolve()
|
||||
.then(() => this.evalValue(template, scope))
|
||||
.then(partial => partial === undefined ? '' : stringify(partial))
|
||||
return this.renderValue(template, scope)
|
||||
} else { // template.type === 'html'
|
||||
return Promise.resolve(template.value)
|
||||
}
|
||||
@@ -46,6 +45,12 @@ var render = {
|
||||
return template.render(scope)
|
||||
},
|
||||
|
||||
renderValue: function (template, scope) {
|
||||
return Promise.resolve()
|
||||
.then(() => this.evalValue(template, scope))
|
||||
.then(partial => partial === undefined ? '' : _.stringify(partial))
|
||||
},
|
||||
|
||||
evalValue: function (template, scope) {
|
||||
assert(scope, 'unable to evalValue: scope undefined')
|
||||
return template.filters.reduce(
|
||||
@@ -59,9 +64,4 @@ function factory () {
|
||||
return instance
|
||||
}
|
||||
|
||||
function stringify (val) {
|
||||
if (typeof val === 'string') return val
|
||||
return JSON.stringify(val)
|
||||
}
|
||||
|
||||
module.exports = factory
|
||||
|
||||
Reference in New Issue
Block a user