Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 19, 2014 01:20
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 devdays/74ec77de3ad64744132b to your computer and use it in GitHub Desktop.
Save devdays/74ec77de3ad64744132b to your computer and use it in GitHub Desktop.
Single Page App - Sammy with LoDash
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery', 'sammy', 'underscore'], factory);
} else {
(window.Sammy = window.Sammy || {}).Tmpl =
factory(window.jQuery, window.Sammy, window._);
}
}(function ($, Sammy, _) {
// `Sammy.LoDash` is a wrapper around the underscore/lodash templating engine. // http://lodash.com/docs#template
Sammy.LoDash = function (app, method_alias) {
// *Helper:* Uses _.template to parse a template and interpolate // and work with the passed data
// * `template` A String template that will be compiled by _.template()
// * `data` An Object containing the replacement values for the template.
// data is extended with the <tt>EventContext</tt> allowing you to call // its methods within the template.
//
var template = function (template, data) {
data = $.extend({}, this, data);
var results = _.template(template, data);
return results;
};
// set the default method name/extension
if (!method_alias) { method_alias = 'lodash'; }
// create the helper at the method alias
app.helper(method_alias, template);
};
return Sammy.LoDash;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment