Permalink
Browse files

Merge pull request #2 from OnePrism/master

extract regex
  • Loading branch information...
2 parents 9b1889c + 161592d commit 6692b6c5eb1f69d919f7c74a2c02ff9b9ec1d14e @defkode defkode committed Mar 10, 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 6692b6c

Please sign in to comment.