﻿(function($) {
	$.buildMarkup = function(dataSource, template) {
		var html = "";
		if(template && dataSource) {
			template = template.replace("%7B", "{").replace("%7D", "}");
			if(dataSource.length == undefined)
				dataSource = [dataSource];
			
			var expr = new RegExp("\{([^\}]+)\}", "g");
			$.each(dataSource, function(n, d) {
				html += template.replace(expr, function(match, $1) {
					return (d[$1] == null) ? "" : d[$1];
				});
			});
		}
		return html;
	};
	$.fn.appendTemplate = function(dataSource, template) {
		return this.empty().append($.buildMarkup(dataSource, template));
	};
})(jQuery)