Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Fixes for JsRender issue 87 (rendering null as "") and JsViews issue …
Browse files Browse the repository at this point in the history
…48 - use of link=false
  • Loading branch information
BorisMoore committed Mar 21, 2012
1 parent 0811873 commit dbdc49c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
18 changes: 11 additions & 7 deletions jquery.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright 2012, Boris Moore
* Released under the MIT License.
*/
// informal pre beta commit counter: 0
// informal pre beta commit counter: 2

this.jQuery && jQuery.link || (function( global, undefined ) {
// global is the this object, which is window when running in the usual browser environment.
Expand Down Expand Up @@ -319,13 +319,17 @@ function view_removeViews( index, itemsCount ) {
// view.removeViews( index ) removes the child view with specified index or key
// view.removeViews( index, count ) removes the specified nummber of child views, starting with the specified index
function removeView( index ) {
var view = views[ index ],
var parentElViews, i,
view = views[ index ],
node = view.prevNode,
nextNode = view.nextNode,
nodes = [ node ],
parentElViews = parentElViews || jsViewsData( view.nextNode.parentNode, viewStr ),
i = parentElViews.length;

nodes = [ node ];
if ( !nextNode ) {
// this view has not been linked, so nothing to remove.
return;
}
parentElViews = parentElViews || jsViewsData( nextNode.parentNode, viewStr );
i = parentElViews.length;
if ( i ) {
view.removeViews();
}
Expand Down Expand Up @@ -431,7 +435,7 @@ function linkViews( node, parent, nextNode, depth, data, context, prevNode, inde
// Convert to data-link="{:expression}", or for inputs, data-link="{:expression:}" for (default) two-way binding
linkMarkup = delimOpen1 + ":" + linkMarkup + ($.nodeName( node, "input" ) ? ":" : "") + delimClose0;
}
while( tokens = rTag.exec( linkMarkup )) {
while( tokens = rTag.exec( linkMarkup )) { // TODO require } to be followed by whitespace or $, and remove the \}(!\}) option.
// Iterate over the data-link expressions, for different target attrs, e.g. <input data-link="{:firstName:} title{:~description(firstName, lastName)}"
// tokens: [all, attr, tag, converter, colon, html, code, linkedParams]
attr = tokens[ 1 ];
Expand Down
15 changes: 8 additions & 7 deletions jsrender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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)
}

//=================
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) : "";
}
});

Expand Down

0 comments on commit dbdc49c

Please sign in to comment.