Created
December 22, 2011 16:40
-
-
Save podgorniy/1510929 to your computer and use it in GitHub Desktop.
Простейший шаблонизатор
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using yajt('<div class="$class_name$">$data$</div>', {class_name: 'main', data: 'Hello, world'}) | |
* @param {String} template string | |
* @param {Object} data key-value data storage | |
* @return {String} | |
*/ | |
function yajt (template, data) { | |
"use strict"; | |
var res; | |
res = template.replace(/\$([^\$]+)?\$/g, function (match_string, param_name) { | |
return data[param_name]; | |
}); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment