mixin.blocks.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. function pug_attr(t, e, n, f) {
  2. return !1 !== e && null != e && (e || "class" !== t && "style" !== t) ? !0 === e ? " " + (f ? t : t + '="' + t + '"') : ("function" == typeof e.toJSON && (e = e.toJSON()),
  3. "string" == typeof e || (e = JSON.stringify(e), n || -1 === e.indexOf('"')) ? (n && (e = pug_escape(e)),
  4. " " + t + '="' + e + '"') : " " + t + "='" + e.replace(/'/g, "'") + "'") : "";
  5. }
  6. function pug_escape(e) {
  7. var a = "" + e, t = pug_match_html.exec(a);
  8. if (!t) return e;
  9. var r, c, n, s = "";
  10. for (r = t.index, c = 0; r < a.length; r++) {
  11. switch (a.charCodeAt(r)) {
  12. case 34:
  13. n = "&quot;";
  14. break;
  15. case 38:
  16. n = "&amp;";
  17. break;
  18. case 60:
  19. n = "&lt;";
  20. break;
  21. case 62:
  22. n = "&gt;";
  23. break;
  24. default:
  25. continue;
  26. }
  27. c !== r && (s += a.substring(c, r)), c = r + 1, s += n;
  28. }
  29. return c !== r ? s + a.substring(c, r) : s;
  30. }
  31. var pug_match_html = /["&<>]/;
  32. function template(locals) {
  33. var pug_html = "", pug_mixins = {}, pug_interp;
  34. pug_mixins["form"] = pug_interp = function(method, action) {
  35. var block = this && this.block, attributes = this && this.attributes || {};
  36. pug_html = pug_html + "<form" + (pug_attr("method", method, true, false) + pug_attr("action", action, true, false)) + ">";
  37. var csrf_token_from_somewhere = "hey";
  38. pug_html = pug_html + "<input" + (' type="hidden" name="_csrf"' + pug_attr("value", csrf_token_from_somewhere, true, false)) + "/>";
  39. block && block();
  40. pug_html = pug_html + "</form>";
  41. };
  42. pug_html = pug_html + "<html><body>";
  43. pug_mixins["form"].call({
  44. block: function() {
  45. pug_html = pug_html + '<input type="text" name="query" placeholder="Search"/><input type="submit" value="Search"/>';
  46. }
  47. }, "GET", "/search");
  48. pug_html = pug_html + "</body></html><html><body>";
  49. pug_mixins["form"].call({
  50. block: function() {
  51. pug_html = pug_html + '<input type="text" name="query" placeholder="Search"/><input type="submit" value="Search"/>';
  52. }
  53. }, "POST", "/search");
  54. pug_html = pug_html + "</body></html><html><body>";
  55. pug_mixins["form"]("POST", "/search");
  56. pug_html = pug_html + "</body></html>";
  57. pug_mixins["bar"] = pug_interp = function() {
  58. var block = this && this.block, attributes = this && this.attributes || {};
  59. pug_html = pug_html + '<div id="bar">';
  60. block && block();
  61. pug_html = pug_html + "</div>";
  62. };
  63. pug_mixins["foo"] = pug_interp = function() {
  64. var block = this && this.block, attributes = this && this.attributes || {};
  65. pug_html = pug_html + '<div id="foo">';
  66. pug_mixins["bar"].call({
  67. block: function() {
  68. block && block();
  69. }
  70. });
  71. pug_html = pug_html + "</div>";
  72. };
  73. pug_mixins["foo"].call({
  74. block: function() {
  75. pug_html = pug_html + "<p>one</p><p>two</p><p>three</p>";
  76. }
  77. });
  78. pug_mixins["baz"] = pug_interp = function() {
  79. var block = this && this.block, attributes = this && this.attributes || {};
  80. pug_html = pug_html + '<div id="baz">';
  81. block && block();
  82. pug_html = pug_html + "</div>";
  83. };
  84. pug_mixins["baz"].call({
  85. block: function() {
  86. pug_html = pug_html + pug_escape(null == (pug_interp = "123") ? "" : pug_interp);
  87. }
  88. });
  89. return pug_html;
  90. }