render undefined to ''

This commit is contained in:
harttle
2016-06-26 12:52:37 +08:00
parent a0feabce5b
commit a482b4abe5
4 changed files with 7 additions and 6 deletions
+2 -4
View File
@@ -102,9 +102,7 @@ Footer
* It's possible to define multiple blocks. * It's possible to define multiple blocks.
* block name is optional when there's only one block. * block name is optional when there's only one block.
## Extension ## Register Filters
Register Filters:
```javascript ```javascript
// Usage: {{ name | uppper }} // Usage: {{ name | uppper }}
@@ -115,7 +113,7 @@ engine.registerFilter('upper', function(v){
> See existing filter implementations: <https://github.com/harttle/shopify-liquid/blob/master/filters.js> > See existing filter implementations: <https://github.com/harttle/shopify-liquid/blob/master/filters.js>
Register Tags: ## Register Tags
```javascript ```javascript
// Usage: {% upper name%} // Usage: {% upper name%}
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "shopify-liquid", "name": "shopify-liquid",
"version": "1.1.7", "version": "1.1.8",
"description": "A Shopify Liquid Implementation in Node.js", "description": "A Shopify Liquid Implementation in Node.js",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
+1 -1
View File
@@ -21,7 +21,7 @@ var render = {
break; break;
case 'output': case 'output':
var val = this.evalOutput(template, scope); var val = this.evalOutput(template, scope);
html += stringify(val); html += val === undefined ? '' : stringify(val);
} }
}); });
return html; return html;
+3
View File
@@ -32,6 +32,9 @@ describe('liquid', function() {
it('should output array', function() { it('should output array', function() {
engine.parseAndRender('{{arr}}', ctx).should.equal('[-2,"a"]'); engine.parseAndRender('{{arr}}', ctx).should.equal('[-2,"a"]');
}); });
it('should output undefined to empty', function() {
engine.parseAndRender('foo{{zzz}}bar', ctx).should.equal('foobar');
});
it('should parse html', function() { it('should parse html', function() {
(function() { (function() {
engine.parse('{{obj}}'); engine.parse('{{obj}}');