Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Created July 25, 2014 15:41
Show Gist options
  • Save ttepasse/32f3e6c13d114da2b556 to your computer and use it in GitHub Desktop.
Save ttepasse/32f3e6c13d114da2b556 to your computer and use it in GitHub Desktop.
function buildTemplate (spec, template) {
return function (context) {
var allParamsExist = spec.every(function (key) {
return context.hasOwnProperty(key) && (context[key] !== undefined)
})
if (!allParamsExist) {
throw "Context object misses needed parameters"
}
// return Mustache.render(template, context)
return allParamsExist;
}
}
var templateString = "Langer Templatestring, den ich hier nicht abtippen will";
// Beispiel
var reminder = buildTemplate(["id", "activity", "has_attendees"], templateString)
console.log( reminder({ id: 1, activity: {}, has_attendees: false }) );
// -> true
console.log(reminder({
foo: "foo",
bar: "bar",
baz: "baz"
}));
// -> Exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment