Simple image host.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context.js 739B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function templatify(str, args) {
  2. if (args == undefined)
  3. return str;
  4. for (var i in args) {
  5. str = str.split("{{"+i+"}}").join(args[i]);
  6. }
  7. return str;
  8. }
  9. module.exports = function(options) {
  10. this.req = options.req;
  11. this.res = options.res;
  12. this.templates = options.templates;
  13. this.views = options.views;
  14. this.conf = options.conf;
  15. }
  16. module.exports.prototype = {
  17. end: function(str) {
  18. this.res.end(str);
  19. },
  20. template: function(name, args) {
  21. var str = this.templates[name];
  22. if (!str)
  23. throw new Error("No such template: "+name);
  24. return templatify(str, args);
  25. },
  26. view: function(name, args) {
  27. var str = this.views[name];
  28. if (!str)
  29. throw new Error("No such view: "+name);
  30. return templatify(str, args);
  31. }
  32. }