Created
July 25, 2014 15:41
-
-
Save ttepasse/32f3e6c13d114da2b556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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