Skip to content

Commit

Permalink
Moved some private helper functions out of inner function scopes, for
Browse files Browse the repository at this point in the history
memory optimization.

Added support for white space after target in tmpl tag, e.g. ${ foo } or
${ foo(x) }

Added support for targets that include '.'s and calls to functions, e.g.
${foo.toLowerCase()}

Added support for implicit passing of $data to nested tmpl when no
parameters, so that {{tmpl "#myTmpl"}} is equivalent to
{{tmpl() "#myTmpl"}}, to {{tmpl(null) "#myTmpl"}}, and to
{{tmpl($data) "#myTmpl"}}, and so allows myTmpl to bind to the same data
as the parent template.
(But {{tmpl(foo) "#myTmpl"}} or {{tmpl({}) "#myTmpl"}} will replace the
inherited $data value.)

Added support for inserting a template without data, using
$( "#tmpl" ).tmpl(null).appendTo( "#container" ); - which is equivalent to
$( "#tmpl" ).tmpl( {} ).appendTo( "#container" );
  • Loading branch information
BorisMoore committed Jul 11, 2010
1 parent 8fc69f4 commit a702bbf
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 126 deletions.
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies1.html
Expand Up @@ -91,7 +91,7 @@ <h1>Netflix: Book a Movie...</h1>
</script>

<script id="bookingEditTmpl" type="text/html">
{{tmpl(this.data, {mode: "Edit"}) "#bookingTitleTmpl"}}
{{tmpl($data, {mode: "Edit"}) "#bookingTitleTmpl"}}
<tr class="bookingEdit">
<td colspan="4">
<div class="fields">
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies2.html
Expand Up @@ -90,7 +90,7 @@ <h1>Netflix: Book a Movie...</h1>
</script>

<script id="bookingEditTmpl" type="text/html">
{{tmpl(this.data, {mode: "Edit"}) "#bookingTitleTmpl"}}
{{tmpl($data, {mode: "Edit"}) "#bookingTitleTmpl"}}
<tr class="bookingEdit">
<td colspan="4">
<div class="fields">
Expand Down
2 changes: 1 addition & 1 deletion demos/movies/PagesTmplPlus/movies3.html
Expand Up @@ -90,7 +90,7 @@ <h1>Netflix: Book a Movie...</h1>
</script>

<script id="bookingEditTmpl" type="text/html">
{{tmpl(this.data, {mode: "Edit"}) "#bookingTitleTmpl"}}
{{tmpl($data, {mode: "Edit"}) "#bookingTitleTmpl"}}
<tr class="bookingEdit">
<td colspan="4">
<div class="fields">
Expand Down
2 changes: 1 addition & 1 deletion demos/samplesCore/parameters.html
Expand Up @@ -76,7 +76,7 @@
{{if getCityCount(startIndex, endIndex)}}
<tr class="${alternate}"><td colspan="3"><i>Favorite Cities</i></td></tr>
{{each getCities(startIndex, endIndex)}}
{{tmpl({}, {type:"city"}) "#tmplSeparator"}}
{{tmpl(null, {type:"city"}) "#tmplSeparator"}}
<tr class="${alternate}">
<td>${$index + 1}</td>
<td><b>${name}</b></td>
Expand Down
2 changes: 1 addition & 1 deletion demos/samplesTmplPlus/composition.html
Expand Up @@ -67,7 +67,7 @@

<script id="tmplPeople" type="text/html">
{{tmpl "#tmplSeparator"}}
<tr class="${alternate(this.data, people)}"><td colspan="2"><a href="${url}">${getName}</a></td></tr>
<tr class="${alternate($data, people)}"><td colspan="2"><a href="${url}">${getName}</a></td></tr>
{{if cities}}
{{tmpl(cities) getTemplate("City")}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion demos/samplesTmplPlus/parameters.html
Expand Up @@ -76,7 +76,7 @@
{{if getCityCount(startIndex, endIndex)}}
<tr class="${alternate}"><td colspan="3"><i>Favorite Cities</i></td></tr>
{{each getCities(startIndex, endIndex)}}
{{tmpl({}, {type:"city"}) "#tmplSeparator"}}
{{tmpl(null, {type:"city"}) "#tmplSeparator"}}
<tr class="${alternate}">
<td>${$index + 1}</td>
<td><b>${name}</b></td>
Expand Down

7 comments on commit a702bbf

@Svish
Copy link

@Svish Svish commented on a702bbf Jul 12, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update and Replace are not working for me anymore and I found out that it probably is because my ctxs array is empty. Before I updated to your latest version of jquery-tmpl, I did to add now things:

$('#items').append('#item-template', newItems,
    {
        newCtxs: itemCtxs,
        rendered: onItemRendered,
    });

But when I check the itemCtxs afterwards, it is still empty now. How should I get a hold of these Ctxs now? Since it seems like I need them in a handy array to be able to use tmplCmd 'replace' and 'update' for example.

@BorisMoore
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newCtxs: itemCtxs feature has been removed for now. See:
http://github.com/nje/jquery-tmpl/commit/395b3593225f96c5325816d63c9f042a2a1310fc "Removed the newCtxs feature, to simplify implementation for appendTo"

It may come back in a future update, but in the meantime, take a look at the different movie samples, to show alternative ways of getting the ctxs array that you need.

@Svish
Copy link

@Svish Svish commented on a702bbf Jul 12, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, missed that comment. Would an easy replacement be something like this?

$.makeArray($('.rendered-item').map(function() {return $(this).tmpl()}))

Or is there more to the Ctxs array than that? Would be nice with some simpler more specific samples than that movie example. I find it a bit difficult to pull out things from it. For example it could be nice to just have a "sort" example and a "update one of several rendered items" and stuff like that. But I guess that comes with documentation and such when/if that comes?

@BorisMoore
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that should work fine, if you want the full set of rendered items, not just the last ones you appended. In most scenarios, e.g. appendTo under a container element, getting all the items will be what you want...

On more simple examples for the many different scenarios, yes, I agree. We hope to add them along with documentation, before too long...

@BorisMoore
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this commit has some issues, and should not be used. Instead, use the later updated version which replaces it:
http://github.com/nje/jquery-tmpl/commit/fbe824114bd494c20d642bb36ca0a57a6e659371

@BorisMoore
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Svish - that newCtxs feature is back in now, in the latest commit:
http://github.com/nje/jquery-tmpl/commit/a02d273a0dece498d6d2d9d0f1e24b37046e0c7e

@Svish
Copy link

@Svish Svish commented on a702bbf Jul 14, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BorisMoore - Thanks for letting me know!

Please sign in to comment.