Permalink
Browse files

shaving a few extra bytes off the implementation, removing redundant …

…code
  • Loading branch information...
1 parent 8dca743 commit cf87ec1ef09b9500f28e645f3dc067459c367f23 @addyosmani committed Oct 16, 2011
Showing with 18 additions and 21 deletions.
  1. +3 −3 README.md
  2. +15 −18 microtemplatez.js
View
@@ -1,4 +1,4 @@
-A very compact micro-templating solution created for learning purposes. Currently 0.2KB minified
+A very compact micro-templating solution created for learning purposes. Currently under 180 bytes minified, 168 using a few other optimizations.
### Sample usage
@@ -134,7 +134,7 @@ console.log('Test:' + template);
</script>
```
-#184-byte version
+#168-byte version
```javascript
-function t(a,b){return a.replace(RegExp("{{\\s*([a-z0-9_][\\.a-z0-9_]*)\\s*}}","gi"),function(a,c){var d=c.split("."),e=d.length,f=b,g=0;for(;g<e;g++){f=f[d[g]];if(g===e-1)return f}})}
+function t(a,b){return a.replace(RegExp("{{\\s*([a-z0-9_][\\.a-z0-9_]*)\\s*}}","gi"),function(a,c){var d=c.split("."),e=d.length,f=b,g=0;while(e--)f=f[d[e]];return f})}
```
View
@@ -1,23 +1,20 @@
/*!
* Compact micro-templating implementation
-* http://addyosmani.com/
-* Licensed under the GPL
+* Copyright: Addy Osmani, 2011.
+* Licensed under MIT/GPL licenses
*/
-var templatez = (function(){
- return function(tmpl, data){
- return tmpl.replace((RegExp("{{\\s*([a-z0-9_][\\.a-z0-9_]*)\\s*}}", "gi")), function(tag, k){
- var p = k.split("."),
- len = p.length,
- temp = data,
- i = 0;
- for(; i<len; i++){
- temp = temp[p[i]];
- if (i === (len - 1)){
- return temp;
- }
- }
- });
- };
-}());
+function templatez(tmpl, data) {
+ return tmpl.replace((RegExp("{{\\s*([a-z0-9_][\\.a-z0-9_]*)\\s*}}", "gi")), function (tag, k) {
+ var p = k.split("."),
+ len = p.length,
+ temp = data,
+ i = 0;
+ for (; i < len; i++) {
+ temp = temp[p[i]];
+ }
+ return temp;
+ });
+};
+

0 comments on commit cf87ec1

Please sign in to comment.