mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
eslint
This commit is contained in:
+56
-56
@@ -1,68 +1,68 @@
|
||||
const Syntax = require('./syntax.js');
|
||||
const Promise = require('any-promise');
|
||||
const mapSeries = require('./util/promise.js').mapSeries;
|
||||
const RenderBreakError = require('./util/error.js').RenderBreakError;
|
||||
const RenderError = require('./util/error.js').RenderError;
|
||||
const assert = require('./util/assert.js');
|
||||
const Syntax = require('./syntax.js')
|
||||
const Promise = require('any-promise')
|
||||
const mapSeries = require('./util/promise.js').mapSeries
|
||||
const RenderBreakError = require('./util/error.js').RenderBreakError
|
||||
const RenderError = require('./util/error.js').RenderError
|
||||
const assert = require('./util/assert.js')
|
||||
|
||||
var render = {
|
||||
|
||||
renderTemplates: function(templates, scope) {
|
||||
assert(scope, 'unable to evalTemplates: scope undefined');
|
||||
renderTemplates: function (templates, scope) {
|
||||
assert(scope, 'unable to evalTemplates: scope undefined')
|
||||
|
||||
var html = '';
|
||||
return mapSeries(templates, (tpl) => {
|
||||
return renderTemplate.call(this, tpl)
|
||||
.then(partial => html += partial)
|
||||
.catch(e => {
|
||||
if (e instanceof RenderBreakError) {
|
||||
e.resolvedHTML = html;
|
||||
throw e;
|
||||
}
|
||||
throw new RenderError(e, tpl);
|
||||
});
|
||||
}).then(() => html);
|
||||
var html = ''
|
||||
return mapSeries(templates, (tpl) => {
|
||||
return renderTemplate.call(this, tpl)
|
||||
.then(partial => (html += partial))
|
||||
.catch(e => {
|
||||
if (e instanceof RenderBreakError) {
|
||||
e.resolvedHTML = html
|
||||
throw e
|
||||
}
|
||||
throw new RenderError(e, tpl)
|
||||
})
|
||||
}).then(() => html)
|
||||
|
||||
function renderTemplate(template) {
|
||||
if (template.type === 'tag') {
|
||||
return this.renderTag(template, scope)
|
||||
.then(partial => partial === undefined ? '' : partial);
|
||||
} else if (template.type === 'output') {
|
||||
return Promise.resolve()
|
||||
function renderTemplate (template) {
|
||||
if (template.type === 'tag') {
|
||||
return this.renderTag(template, scope)
|
||||
.then(partial => partial === undefined ? '' : partial)
|
||||
} else if (template.type === 'output') {
|
||||
return Promise.resolve()
|
||||
.then(() => this.evalOutput(template, scope))
|
||||
.then(partial => partial === undefined ? '' : stringify(partial));
|
||||
} else { // template.type === 'html'
|
||||
return Promise.resolve(template.value);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
renderTag: function(template, scope) {
|
||||
if (template.name === 'continue') {
|
||||
return Promise.reject(new RenderBreakError('continue'));
|
||||
}
|
||||
if (template.name === 'break') {
|
||||
return Promise.reject(new RenderBreakError('break'));
|
||||
}
|
||||
return template.render(scope);
|
||||
},
|
||||
|
||||
evalOutput: function(template, scope) {
|
||||
assert(scope, 'unable to evalOutput: scope undefined');
|
||||
return template.filters.reduce(
|
||||
(prev, filter) => filter.render(prev, scope),
|
||||
Syntax.evalExp(template.initial, scope));
|
||||
.then(partial => partial === undefined ? '' : stringify(partial))
|
||||
} else { // template.type === 'html'
|
||||
return Promise.resolve(template.value)
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
function factory() {
|
||||
var instance = Object.create(render);
|
||||
return instance;
|
||||
renderTag: function (template, scope) {
|
||||
if (template.name === 'continue') {
|
||||
return Promise.reject(new RenderBreakError('continue'))
|
||||
}
|
||||
if (template.name === 'break') {
|
||||
return Promise.reject(new RenderBreakError('break'))
|
||||
}
|
||||
return template.render(scope)
|
||||
},
|
||||
|
||||
evalOutput: function (template, scope) {
|
||||
assert(scope, 'unable to evalOutput: scope undefined')
|
||||
return template.filters.reduce(
|
||||
(prev, filter) => filter.render(prev, scope),
|
||||
Syntax.evalExp(template.initial, scope))
|
||||
}
|
||||
}
|
||||
|
||||
function stringify(val) {
|
||||
if (typeof val === 'string') return val;
|
||||
return JSON.stringify(val);
|
||||
function factory () {
|
||||
var instance = Object.create(render)
|
||||
return instance
|
||||
}
|
||||
|
||||
module.exports = factory;
|
||||
function stringify (val) {
|
||||
if (typeof val === 'string') return val
|
||||
return JSON.stringify(val)
|
||||
}
|
||||
|
||||
module.exports = factory
|
||||
|
||||
Reference in New Issue
Block a user