Permalink
Browse files

Fixes for issues 87 (rendering null as "") and JsViews issue 48 - use…

… of link=false
  • Loading branch information...
1 parent 2eb692a commit 5f7636df8a325205888ab41179fbddc7cb0d94ab @BorisMoore committed Mar 21, 2012
Showing with 17 additions and 13 deletions.
  1. +9 −6 demos/step-by-step/11_default-values-scenario.html
  2. +8 −7 jsrender.js
@@ -13,11 +13,12 @@
<body>
<a href="index.html">Home</a><br />
-<!---------------------- First Example ---------------------->
-
<h3>Example Scenario: providing default values for data.</h3>
+<!---------------------- First Example ---------------------->
+
<div class="subhead">The simplest (and best) way: Javascript expression '||':</div>
+
<pre>
{{:languages||'Languages unavailable'}}
</pre>
@@ -29,6 +30,7 @@
<!---------------------- Second Example ---------------------->
<div class="subhead">Creating a special custom tag:</div>
+
<pre>
{{get languages defaultValue="No languages!"/}}
@@ -39,9 +41,14 @@
});
</pre>
+<table><tr class="header"><th>Title</th><th>{{get path default="..."}}</th></tr></tbody>
+ <tbody id="movieList2"></tbody>
+</table>
+
<!---------------------- Third Example ---------------------->
<div class="subhead">Creating a multi-purpose utility tag:</div>
+
<pre>
{{yesNo languages yes="Alternate languages available:" no="No alternate languages"/}}
@@ -60,10 +67,6 @@
<!------------------ Templates ------------------>
-<table><tr class="header"><th>Title</th><th>{{get path default="..."}}</th></tr></tbody>
- <tbody id="movieList2"></tbody>
-</table>
-
<script id="movieTemplate1" type="text/x-jsrender">
<tr>
<td>{{:title}}</td>
View
@@ -6,7 +6,7 @@
* Copyright 2012, Boris Moore
* Released under the MIT License.
*/
-// informal pre beta commit counter: 1
+// informal pre beta commit counter: 2
this.jsviews || this.jQuery && jQuery.views || (function( window, undefined ) {
@@ -158,7 +158,7 @@ function renderTag( tag, parentView, converter, content, tagObject ) {
}
ret = tagFn.apply( tagObject, args.length > 5 ? slice.call( args, 5 ) : [] );
- return ret || ( ret === undefined ? "" : ret.toString()); // (If ret is the value 0 or false or null, will render to string)
+ return ret || ( ret == undefined ? "" : ret.toString()); // (If ret is the value 0 or false, will render to string)
}
//=================
@@ -314,9 +314,10 @@ function renderContent( data, context, parentView, path, index ) {
// if no parentContext, use context, or default to {}
: context || {});
- if ( props.link !== undefined ) {
- // Override inherited value of link by an explicit setting in props: link=true or link=false
- context.link = props.link;
+ if ( props.link === FALSE ) {
+ // Override inherited value of link by an explicit setting in props: link=false
+ // The child views of an unlinked view are also unlinked. So setting child back to true will not have any effect.
+ context.link = FALSE;
}
if ( !tmpl.fn ) {
tmpl = templates[ tmpl ] || templates( tmpl );
@@ -489,7 +490,7 @@ function tmplFn( markup, tmpl, bind ) {
? (hasEncoder = TRUE, "e(" + params)
: converter
? (hasConverter = TRUE, 'c("' + converter + '",view,' + params)
- : (getsValue = TRUE, "((v=" + params + ')!==u?v:""')
+ : (getsValue = TRUE, "((v=" + params + ')!=u?v:""')
)
: (hasTag = TRUE, 't("' + tag + '",view,"' + (converter || "") + '",'
+ (content ? nested.length : '""') // For block tags, pass in the key (nested.length) to the nested content template
@@ -836,7 +837,7 @@ converters({
html: function( text ) {
// HTML encoding helper: Replace < > & and ' and " by corresponding entities.
// inspired by Mike Samuel <msamuel@google.com>
- return text !== undefined ? String( text ).replace( htmlSpecialChar, replacerForHtml ) : "";
+ return text != undefined ? String( text ).replace( htmlSpecialChar, replacerForHtml ) : "";
}
});

0 comments on commit 5f7636d

Please sign in to comment.