Skip to content

Commit

Permalink
API name change: Changed .templates() to .template()
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisMoore committed Aug 9, 2010
1 parent 88e7520 commit 189c570
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ____________________________________________________________________
____________________________________________________________________

// Store a string as a compiled template for later use
$.templates( "myTmpl", "<span>${firstName}</span>" );
$.template( "myTmpl", "<span>${firstName}</span>" );

// Render stored template and insert after target.
$.tmpl( "myTmpl", dataObject )
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesCore/movies.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ <h1>Netflix: Book a Movie...</h1>
return;
}
var item = bookingTmplItems[booking.movie.Id],
tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).templates();
tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).template();
if ( item.tmpl !== tmpl) {
item.tmpl = tmpl;
item.update();
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies1.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ <h1>Netflix: Book a Movie...</h1>
return;
}
var item = bookingItem( booking ),
tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).templates();
tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).template();
if ( item.tmpl !== tmpl) {
item.tmpl = tmpl;
item.update();
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies2.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ <h1>Netflix: Book a Movie...</h1>
var item = bookingItem( booking ),
rendered = edit ? onBookingEditRendered : onBookingRendered;
if ( item.rendered !== rendered) {
item.tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).templates();
item.tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).template();
item.rendered = rendered;
item.update();
}
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies3.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h1>Netflix: Book a Movie...</h1>
var item = bookingItem( booking ),
rendered = edit ? onBookingEditRendered : onBookingRendered;
if ( item.rendered !== rendered) {
item.tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).templates();
item.tmpl = $( edit ? "#bookingEditTmpl" : "#bookingTitleTmpl" ).template();
item.rendered = rendered;
item.update();
}
Expand Down
Binary file modified demos/samplesCore/Interactive/resources/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 17 additions & 12 deletions demos/samplesCore/Interactive/resources/treeView.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@
.treeView li
{
list-style-type: none;
padding: 1px;
margin: 0;
padding: 2px;
}

.treeView li li
{
margin-left: 22px;
margin-left: 18px;
}

.treeView img
{
vertical-align: middle;
border: 0px;
margin-right:7px;
}

.folderItem
img.folder
{
cursor: pointer;
margin: 17px;
color:Blue;
text-decoration: underline;
font-style:italic;
width:15px;
height:14px;
}

img.expand
{
width:8px;
width:9px;
}

.treeView .folderItem
.treeView li.folderItem
{
cursor: pointer;
padding: 0px 0 3px 16px;
color:Blue;
text-decoration: underline;
font-style:italic;
margin-bottom: 4px;
}

.content_true
{
cursor: pointer;
font-weight: bold;
}

4 changes: 2 additions & 2 deletions demos/samplesCore/Interactive/tabsWrapNested.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ <h3>POST</h3>
</th>
{{/each}}
</tr>
<tr><td colspan="${tabCount}">
<tr><td colspan="${tabCount()}">
<div class="body">
{{html tabContent}}
{{html tabContent()}}
</div>
</td></tr>
</tbody></table>
Expand Down
4 changes: 2 additions & 2 deletions demos/samplesCore/Interactive/treeView.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ <h1>Tree View</h1>

<script id="folderTmpl" type="text/html">
<li class="content_${hasContent($item)}">
<img src="resources/${expanderImage}.png" />
<img src="resources/folder.png" />
<img class="expand" src="resources/${expanderImage}.png" />
<img class="folder" src="resources/folder.png" />
<span>${name}</span>
</li>
{{if expanded}}
Expand Down
4 changes: 2 additions & 2 deletions demos/samplesCore/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
.appendTo( "ul" );

// Store a string as a compiled template for later use
$.templates( "myTmpl", '<li>My template: <a href="${url}">${getName()}</a> {{if $item.showCities}}(${cityJoin()}){{/if}}</li>' );
$.template( "myTmpl", '<li>My template: <a href="${url}">${getName()}</a> {{if $item.showCities}}(${cityJoin()}){{/if}}</li>' );

// Render stored template and insert after target.
// Target wrapped set has more than one element, so rendered template cloned into two places in DOM
Expand All @@ -81,7 +81,7 @@
.appendTo( "ul" );

// Store a template declared in a script block as a named template for later use.
$( "#sometmpl" ).templates( "peopleList" );
$( "#sometmpl" ).template( "peopleList" );

// Use the named template
$.tmpl( "peopleList", arrayOfDataObjects )
Expand Down
4 changes: 2 additions & 2 deletions demos/samplesCore/composition.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
}

function getTemplate( key ) {
return $( "#tmpl" + key ).templates();
return $( "#tmpl" + key ).template();
}

$(function(){
// Create named template, to be used in composition below
$.templates( "citySeparator", '<tr class="citySeparator"><td colspan="2"></td></tr>' );
$.template( "citySeparator", '<tr class="citySeparator"><td colspan="2"></td></tr>' );

$( "#tmplPeople" )
.tmpl( people )
Expand Down
2 changes: 1 addition & 1 deletion demos/samplesTmplPlus/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
$("ul").append( tmpl, dataObject, null );

// Store a string as a compiled template for later use
$.templates( "myTmpl", '<li>My template: <a href="${url}">${getName()}</a> {{if $item.showCities}}(${cityJoin()}){{/if}}</li>' );
$.template( "myTmpl", '<li>My template: <a href="${url}">${getName()}</a> {{if $item.showCities}}(${cityJoin()}){{/if}}</li>' );

// Render stored template and insert after target.
// Target wrapped set has more than one element, so rendered template cloned into two places in DOM
Expand Down
2 changes: 1 addition & 1 deletion demos/samplesTmplPlus/composition.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}

function getTemplate( key ) {
return $( "#tmpl" + key ).templates();
return $( "#tmpl" + key ).template();
}

$(function(){
Expand Down
36 changes: 18 additions & 18 deletions jquery.tmpl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* jQuery Templating Plugin
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
Expand Down Expand Up @@ -83,8 +83,8 @@
},

// Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template.
templates: function( name ) {
return jQuery.templates( name, this[0] );
template: function( name ) {
return jQuery.template( name, this[0] );
},

domManip: function( args, table, callback, options ) {
Expand Down Expand Up @@ -121,7 +121,7 @@
if ( topLevel ) {
// This is a top-level tmpl call (not from a nested template using {{tmpl}})
parentItem = topTmplItem;
tmpl = jQuery.templates[tmpl] || jQuery.templates( null, tmpl );
tmpl = jQuery.template[tmpl] || jQuery.template( null, tmpl );
} else if ( !tmpl ) {
// The template item is already associated with DOM - this is a refresh.
// Re-evaluate rendered template for the parentItem
Expand Down Expand Up @@ -166,17 +166,17 @@
},

// Set:
// Use $.templates( name, tmpl ) to cache a named template,
// Use $.template( name, tmpl ) to cache a named template,
// where tmpl is a template string, a script element or a jQuery instance wrapping a script element, etc.
// Use $( "selector" ).templates( name ) to provide access by name to a script block template declaration.
// Use $( "selector" ).template( name ) to provide access by name to a script block template declaration.

// Get:
// Use $.templates( name ) to access a cached template.
// Also $( selectorToScriptBlock ).templates(), or $.templates( null, templateString )
// Use $.template( name ) to access a cached template.
// Also $( selectorToScriptBlock ).template(), or $.template( null, templateString )
// will return the compiled template, without adding a name reference.
// If templateString includes at least one HTML tag, $.templates( templateString ) is equivalent
// to $.templates( null, templateString )
templates: function( name, tmpl ) {
// If templateString includes at least one HTML tag, $.template( templateString ) is equivalent
// to $.template( null, templateString )
template: function( name, tmpl ) {
if (tmpl) {
// Compile template and associate with name
if ( typeof tmpl === "string" ) {
Expand All @@ -189,13 +189,13 @@
// If this is a template block, use cached copy, or generate tmpl function and cache.
tmpl = jQuery.data( tmpl, "tmpl" ) || jQuery.data( tmpl, "tmpl", buildTmplFn( tmpl.innerHTML ));
}
return typeof name === "string" ? (jQuery.templates[name] = tmpl) : tmpl;
return typeof name === "string" ? (jQuery.template[name] = tmpl) : tmpl;
}
// Return named compiled template
return typeof name !== "string" ? jQuery.templates( null, name ):
(jQuery.templates[name] ||
return typeof name !== "string" ? jQuery.template( null, name ):
(jQuery.template[name] ||
// If not in map, treat as a selector. (If integrated with core, use quickExpr.exec)
jQuery.templates( null, htmlExpr.test( name ) ? name : jQuery( name )));
jQuery.template( null, htmlExpr.test( name ) ? name : jQuery( name )));
},

encode: function( text ) {
Expand Down Expand Up @@ -456,15 +456,15 @@

function tiNest( tmpl, data, options ) {
// nested template, using {{tmpl}} tag
return jQuery.tmpl( jQuery.templates( tmpl ), data, options, this );
return jQuery.tmpl( jQuery.template( tmpl ), data, options, this );
}

function tiWrap( call, wrapped ) {
// nested template, using {{wrap}} tag
var options = call.options;
var options = call.options || {};
options.wrapped = wrapped;
// Apply the template, which may incorporate wrapped content,
return jQuery.tmpl( jQuery.templates( call.tmpl ), call.data, options, call.parent );
return jQuery.tmpl( jQuery.template( call.tmpl ), call.data, options, call.parent );
}

function tiHtml( filter, textOnly ) {
Expand Down
5 changes: 1 addition & 4 deletions jquery.tmplPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
dmArgs = jQuery.makeArray( arguments );

// Eval template to obtain fragment to clone and insert
dmArgs[0] = [ jQuery.tmpl( jQuery.templates( tmpl ), data, args[2], args[3] ) ];
dmArgs[0] = [ jQuery.tmpl( jQuery.template( tmpl ), data, args[2], args[3] ) ];

dmArgs[2] = function( fragClone ) {
// Handler called by oldManip when rendered template has been inserted into DOM.
Expand All @@ -90,6 +90,3 @@
}
});
})(jQuery);



0 comments on commit 189c570

Please sign in to comment.