forked from HenrikJoreteg/ICanHaz.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICanHaz.min.js
18 lines (12 loc) · 1.23 KB
/
ICanHaz.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
ICanHaz.js version 0.6 -- by @HenrikJoreteg
Licensed under the "You should follow @HenrikJoreteg on Twitter to use this" license. (Because, apparently I'm a twitter whore like that)
This is a simple template storage and retrieval system.
Templates are stored in the document as script elements with type="text/html". Cheers to @jeresig for this idea.
They are processed through Moustache.js for templating.
Dependencies:
- Mustache.js
- jQuery
Documentation at: http://github.com/HenrikJoreteg/ICanHaz.js
*/
var ich;(function(b){function a(){var d=this,c={cache:{},partials:{}};this.VERSION="0.6";this.addTemplate=function(e,f){if(c.cache.hasOwnProperty(e)){throw"ICanHaz error? Yes. You've already got a template by the name: \""+e+'"'}else{c.cache[e]=f;d[e]=function(i,h){i=i||{};var g=Mustache.to_html(c.cache[e],i,c.partials);return h?g:b(g)}}};this.addPartial=function(e,f){if(c.partials.hasOwnProperty(e)){throw'ICanHaz error? Yes. You\'ve already got a partial by the name: " + name + "'}else{c.partials[e]=f}};b('script[type="text/html"]').each(function(){var e=b(this),f=e.attr("id"),h=e.html().trim(),g=e.attr("class").toLowerCase()==="partial";if(g){d.addPartial(f,h)}else{d.addTemplate(f,h)}e.remove()})}b(function(){ich=new a()})})(jQuery);