Skip to content

Commit eb72edb

Browse files
committed
Print out falsy values except undefined and null. Closes blueimp#35
1 parent 508e6ef commit eb72edb

File tree

11 files changed

+58
-30
lines changed

11 files changed

+58
-30
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-tmpl",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"title": "JavaScript Templates",
55
"description": "< 1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.",
66
"keywords": [

css/demo.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates Demo CSS 2.2.1
2+
* JavaScript Templates Demo CSS 2.4.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2013, Sebastian Tschan

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML>
22
<!--
33
/*
4-
* JavaScript Templates Demo 2.2.1
4+
* JavaScript Templates Demo 2.4.0
55
* https://github.com/blueimp/JavaScript-Templates
66
*
77
* Copyright 2011, Sebastian Tschan
@@ -76,7 +76,7 @@ <h4>Features</h4>
7676
</script>
7777
<script src="js/tmpl.js"></script>
7878
<!-- jQuery is not required by JavaScript Templates, but included for the demo -->
79-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
79+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
8080
<script src="js/demo.js"></script>
8181
</body>
8282
</html>

js/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
/*
3-
* JavaScript Templates Compiler 2.2.0
3+
* JavaScript Templates Compiler 2.4.0
44
* https://github.com/blueimp/JavaScript-Templates
55
*
66
* Copyright 2011, Sebastian Tschan

js/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates Demo JS 2.2.1
2+
* JavaScript Templates Demo JS 2.4.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2013, Sebastian Tschan

js/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates Runtime 2.2.0
2+
* JavaScript Templates Runtime 2.4.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -29,7 +29,7 @@
2929
"'" : "&#39;"
3030
};
3131
tmpl.encode = function (s) {
32-
return String(s).replace(
32+
return (s == null ? "" : "" + s).replace(
3333
tmpl.encReg,
3434
function (c) {
3535
return tmpl.encMap[c] || "";

js/tmpl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates 2.3.0
2+
* JavaScript Templates 2.4.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -48,7 +48,7 @@
4848
if (p2 === "=") {
4949
return "'+_e(" + p3 + ")+'";
5050
}
51-
return "'+" + p3 + "+'";
51+
return "'+(" + p3 + "==null?'':" + p3 + ")+'";
5252
}
5353
if (p4) { // evaluation start tag: {%
5454
return "';";
@@ -66,15 +66,15 @@
6666
"'" : "&#39;"
6767
};
6868
tmpl.encode = function (s) {
69-
return String(s).replace(
69+
return (s == null ? "" : "" + s).replace(
7070
tmpl.encReg,
7171
function (c) {
7272
return tmpl.encMap[c] || "";
7373
}
7474
);
7575
};
7676
tmpl.arg = "o";
77-
tmpl.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);}" +
77+
tmpl.helper = ",print=function(s,e){_s+=e?(s==null?'':s):_e(s);}" +
7878
",include=function(s,d){_s+=tmpl(s,d);}";
7979
if (typeof define === "function" && define.amd) {
8080
define(function () {

js/tmpl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-tmpl",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"title": "JavaScript Templates",
55
"description": "< 1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.",
66
"keywords": [
@@ -31,9 +31,9 @@
3131
}
3232
],
3333
"devDependencies": {
34-
"mocha": "1.11.0",
34+
"mocha": "1.12.1",
3535
"expect.js": "0.2.0",
36-
"uglify-js": "2.3.6"
36+
"uglify-js": "2.4.0"
3737
},
3838
"scripts": {
3939
"test": "mocha --reporter spec"

test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML>
22
<!--
33
/*
4-
* JavaScript Templates Test 2.2.0
4+
* JavaScript Templates Test 2.4.0
55
* https://github.com/blueimp/JavaScript-Templates
66
*
77
* Copyright 2011, Sebastian Tschan

0 commit comments

Comments
 (0)