Skip to content

Instantly share code, notes, and snippets.

@nebulous
Created May 29, 2015 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebulous/c4aabfa5a46183b490f0 to your computer and use it in GitHub Desktop.
Save nebulous/c4aabfa5a46183b490f0 to your computer and use it in GitHub Desktop.
Simple jQuery plugin for Jemplate rendering
(function($) {
/* Simplistic jQuery plugin for Jemplate v0.01
http://github.com/nebulous
*/
$.fn.jemplate = function(tmplin, datain) {
var data_url;
if (typeof(tmplin) == "object") {
datain = tmplin.stash || tmplin || {};
tmplin = datain.jemplate || '';
}
if (typeof(datain) == "string") {
data_url = datain;
datain = {};
}
return this.each(function(idx, obj) {
var $obj = $(obj);
var data = $.extend({}, $obj.data(), datain);
var tmpl = tmplin || data['jemplate'];
var method = data['method'] || 'html';
if (typeof tmpl === undefined) return this;
if (data_url) {
$.getJSON(data_url, function(data) {
var output = Jemplate.process(tmpl, data);
$obj[method](output);
});
} else {
var output = Jemplate.process(tmpl, data);
$obj[method](output);
}
});
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment