mixins.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. function pug_escape(e) {
  2. var a = "" + e, t = pug_match_html.exec(a);
  3. if (!t) return e;
  4. var r, c, n, s = "";
  5. for (r = t.index, c = 0; r < a.length; r++) {
  6. switch (a.charCodeAt(r)) {
  7. case 34:
  8. n = "&quot;";
  9. break;
  10. case 38:
  11. n = "&amp;";
  12. break;
  13. case 60:
  14. n = "&lt;";
  15. break;
  16. case 62:
  17. n = "&gt;";
  18. break;
  19. default:
  20. continue;
  21. }
  22. c !== r && (s += a.substring(c, r)), c = r + 1, s += n;
  23. }
  24. return c !== r ? s + a.substring(c, r) : s;
  25. }
  26. var pug_match_html = /["&<>]/;
  27. function template(locals) {
  28. var pug_html = "", pug_mixins = {}, pug_interp;
  29. pug_mixins["comment"] = pug_interp = function(title, str) {
  30. var block = this && this.block, attributes = this && this.attributes || {};
  31. pug_html = pug_html + '<div class="comment"><h2>' + pug_escape(null == (pug_interp = title) ? "" : pug_interp) + '</h2><p class="body">' + pug_escape(null == (pug_interp = str) ? "" : pug_interp) + "</p></div>";
  32. };
  33. pug_mixins["comment"] = pug_interp = function(title, str) {
  34. var block = this && this.block, attributes = this && this.attributes || {};
  35. pug_html = pug_html + '<div class="comment"><h2>' + pug_escape(null == (pug_interp = title) ? "" : pug_interp) + '</h2><p class="body">' + pug_escape(null == (pug_interp = str) ? "" : pug_interp) + "</p></div>";
  36. };
  37. pug_html = pug_html + '<div id="user"><h1>Tobi</h1><div class="comments">';
  38. pug_mixins["comment"]("This", "is regular, javascript");
  39. pug_html = pug_html + "</div></div>";
  40. pug_mixins["list"] = pug_interp = function() {
  41. var block = this && this.block, attributes = this && this.attributes || {};
  42. pug_html = pug_html + "<ul><li>foo</li><li>bar</li><li>baz</li></ul>";
  43. };
  44. pug_html = pug_html + "<body>";
  45. pug_mixins["list"]();
  46. pug_mixins["list"]();
  47. pug_html = pug_html + "</body>";
  48. pug_mixins["foobar"] = pug_interp = function(str) {
  49. var block = this && this.block, attributes = this && this.attributes || {};
  50. pug_html = pug_html + '<div id="interpolation">' + pug_escape(null == (pug_interp = str + "interpolated") ? "" : pug_interp) + "</div>";
  51. };
  52. var suffix = "bar";
  53. pug_mixins["foo" + suffix]("This is ");
  54. return pug_html;
  55. }