Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Breaking API change: $.render( data, template, ... ) is now consisten…

…t with

$.link( data, template ... ). (Previously: $.render( template, data, ... ).
Added MIT copyright information.
  • Loading branch information...
commit 73c3b623c6130d5b60f19a4e9f9cc993903bafed 1 parent 09e5f23
@BorisMoore authored
View
20 MIT-LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Boris Moore https://github.com/BorisMoore/jsviews
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
2  demos/step-by-step/02_compiling-templates-from-strings.html
@@ -36,7 +36,7 @@
$( this ).text( details ? "Show titles only" : "Show full details" );
/* Render using the other named template */
var templateName = details ? "detailTemplate" : "titleTemplate";
- $( "#movieList" ).html( $.render( templateName, movies ));
+ $( "#movieList" ).html( $.render( movies, templateName ));
}
$( "#switchBtn" ).click( switchTemplates );
View
8 demos/step-by-step/08_custom-tags.html
@@ -22,11 +22,11 @@
if ( this.reverse ) {
// Render in reverse order
for ( var l = array.length, i = l; i; i-- ) {
- ret += $.render( this.tmpl, array[ i - 1 ]);
+ ret += $.render( array[ i - 1 ], this.tmpl );
}
} else {
// Render in original order
- ret += $.render( this.tmpl, array );
+ ret += $.render( array, this.tmpl );
}
return ret;
}
@@ -64,11 +64,11 @@
if ( this.reverse ) {
// Render in reverse order
for ( var l = array.length, i = l; i; i-- ) {
- ret += $.render( this.tmpl, array[ i - 1 ]);
+ ret += $.render( array[ i - 1 ], this.tmpl );
}
} else {
// Render in original order
- ret += $.render( this.tmpl, array );
+ ret += $.render( array, this.tmpl );
}
return ret;
}
View
6 demos/step-by-step/12_without-jquery.html
@@ -39,11 +39,11 @@
if ( this.reverse ) {
// Render in reverse order
for ( var l = array.length, i = l; i; i-- ) {
- ret += $.render( this.tmpl, array[ i - 1 ]);
+ ret += $.render( array[ i - 1 ], this.tmpl );
}
} else {
// Render in original order
- ret += $.render( this.tmpl, array );
+ ret += $.render( array, this.tmpl );
}
return ret;
}
@@ -73,7 +73,7 @@
document.getElementById( "movieList" ).innerHTML =
"<table><tbody class='header'><tr><th>Title</th><th>Original order</th><th>Reverse order</th></tr></tbody><tbody>"
- + $.render( "movieTemplate", movies )
+ + $.render( movies, "movieTemplate" )
+ "</tbody></table>"
</script>
View
13 jsrender.js
@@ -1,6 +1,9 @@
/*! JsRender v1.0pre - (jsrender.js version: does not require jQuery): http://github.com/BorisMoore/jsrender */
/*
* Optimized version of jQuery Templates, for rendering to string, using 'codeless' markup.
+ *
+ * Copyright 2011, Boris Moore
+ * Released under the MIT License.
*/
window.JsViews || window.jQuery && jQuery.views || (function( window, undefined ) {
@@ -33,7 +36,7 @@ if ( jQuery ) {
// Use first wrapped element as template markup.
// Return string obtained by rendering the template against data.
render: function( data, context, parentView, path ) {
- return render( this[0], data, context, parentView, path );
+ return render( data, this[0], context, parentView, path );
},
// Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
@@ -119,7 +122,7 @@ $.extend({
}
}
view.onElse = undefined; // If condition satisfied, so won't run 'else'.
- return render( presenter.tmpl, view.data, view.ctx, view);
+ return render( view.data, presenter.tmpl, view.ctx, view);
};
return view.onElse( this, arguments );
},
@@ -134,11 +137,11 @@ $.extend({
content = this.tmpl,
view = this._view;
for ( i = 0; i < l; i++ ) {
- result += args[ i ] ? render( content, args[ i ], view.ctx, view, this._path, this._tag ) : "";
+ result += args[ i ] ? render( args[ i ], content, view.ctx, view, this._path, this._tag ) : "";
}
return l ? result
// If no data parameter, use the current $data from view, and render once
- : result + render( content, view.data, view.ctx, view, this._path, this._tag );
+ : result + render( view.data, content, view.ctx, view, this._path, this._tag );
},
"=": function( value ) {
return value;
@@ -286,7 +289,7 @@ $.extend({
// render
//===============
- render: render = function( tmpl, data, context, parentView, path, tagName ) {
+ render: render = function( data, tmpl, context, parentView, path, tagName ) {
// Render template against data as a tree of subviews (nested template), or as a string (top-level template).
// tagName parameter for internal use only. Used for rendering templates registered as tags (which may have associated context objects)
var i, l, dataItem, arrayView, content, result = "";
Please sign in to comment.
Something went wrong with that request. Please try again.