Any advances on John Resig's "JavaScript Micro-Templating"?

Viewed 8293

So I've seen this post on JavaScript Micro-Templating by John Resig and I have a need for a micro-templating engine like this.

But he saids in the post that he'll keep a more-refined version in his Secrets of the JavaScript ninja book and also mentions that he'd like to see it evolves.

So I'm wondering, is there a more stable/advanced version of this Micro-templating engine by John Resig? If so, how can I obtain it? That JavaScript book is not available in my country.

8 Answers

One minor improvement/customization that I've made is allow for hyphens in the id of the template. With the original code, this will not work:

<script type="text/html" id="my-awesome-template">
  <!-- template contents -->
</script>

It will actually just try to template the string "my-awesome-template", which will obviously just return "my-awesome-template".

To fix this, I modified the regex here in line 9 or so where it says

var fn = !/\W/.test(str) ?

to the following:

var fn = !/[^a-zA-Z0-9_-]/.test(str) ?
Related