Permalink
Browse files

extract regexp

- Cache regex
- Replace " with '
- Change nano definition to be within 'fn'
  • Loading branch information...
1 parent 9b1889c commit 161592dda28981c59c8c89d8052a493ed1fc3493 Joseph Clay committed Feb 25, 2013
Showing with 10 additions and 9 deletions.
  1. +10 −9 jquery.nano.js
View
@@ -1,11 +1,12 @@
/* Nano Templates (Tomasz Mazur, Jacek Becela) */
-(function($){
- $.nano = function(template, data) {
- return template.replace(/\{([\w\.]*)\}/g, function (str, key) {
- var keys = key.split("."), value = data[keys.shift()];
- $.each(keys, function () { value = value[this]; });
- return (value === null || value === undefined) ? "" : value;
- });
- };
-})(jQuery);
+(function($) {
+ var _regex = /\{([\w\.]*)\}/g;
+ $.fn.nano = function(template, data) {
+ return template.replace(_regex, function (str, key) {
+ var keys = key.split('.'), value = data[keys.shift()];
+ $.each(keys, function() { value = value[this]; });
+ return (value === null || value === undefined) ? '' : value;
+ });
+ };
+}(jQuery));

0 comments on commit 161592d

Please sign in to comment.