Skip to content

Instantly share code, notes, and snippets.

@podgorniy
Created December 22, 2011 16:40
Show Gist options
  • Save podgorniy/1510929 to your computer and use it in GitHub Desktop.
Save podgorniy/1510929 to your computer and use it in GitHub Desktop.
Простейший шаблонизатор
/**
* 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