attrs.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_attrs(t, r) {
  7. var a = "";
  8. for (var s in t) if (pug_has_own_property.call(t, s)) {
  9. var u = t[s];
  10. if ("class" === s) {
  11. u = pug_classes(u), a = pug_attr(s, u, !1, r) + a;
  12. continue;
  13. }
  14. "style" === s && (u = pug_style(u)), a += pug_attr(s, u, !1, r);
  15. }
  16. return a;
  17. }
  18. function pug_classes(s, r) {
  19. return Array.isArray(s) ? pug_classes_array(s, r) : s && "object" == typeof s ? pug_classes_object(s) : s || "";
  20. }
  21. function pug_classes_array(r, a) {
  22. for (var s, e = "", u = "", c = Array.isArray(a), g = 0; g < r.length; g++) (s = pug_classes(r[g])) && (c && a[g] && (s = pug_escape(s)),
  23. e = e + u + s, u = " ");
  24. return e;
  25. }
  26. function pug_classes_object(r) {
  27. var a = "", n = "";
  28. for (var o in r) o && r[o] && pug_has_own_property.call(r, o) && (a = a + n + o,
  29. n = " ");
  30. return a;
  31. }
  32. function pug_escape(e) {
  33. var a = "" + e, t = pug_match_html.exec(a);
  34. if (!t) return e;
  35. var r, c, n, s = "";
  36. for (r = t.index, c = 0; r < a.length; r++) {
  37. switch (a.charCodeAt(r)) {
  38. case 34:
  39. n = "&quot;";
  40. break;
  41. case 38:
  42. n = "&amp;";
  43. break;
  44. case 60:
  45. n = "&lt;";
  46. break;
  47. case 62:
  48. n = "&gt;";
  49. break;
  50. default:
  51. continue;
  52. }
  53. c !== r && (s += a.substring(c, r)), c = r + 1, s += n;
  54. }
  55. return c !== r ? s + a.substring(c, r) : s;
  56. }
  57. var pug_has_own_property = Object.prototype.hasOwnProperty;
  58. var pug_match_html = /["&<>]/;
  59. function pug_style(r) {
  60. if (!r) return "";
  61. if ("object" == typeof r) {
  62. var t = "";
  63. for (var e in r) pug_has_own_property.call(r, e) && (t = t + e + ":" + r[e] + ";");
  64. return t;
  65. }
  66. return r + "";
  67. }
  68. function template(locals) {
  69. var pug_html = "", pug_mixins = {}, pug_interp;
  70. var locals_for_with = locals || {};
  71. (function(Date) {
  72. pug_html = pug_html + '<a href="/contact">contact</a><a class="button" href="/save">save</a><a' + (pug_attr("foo", true, true, false) + pug_attr("bar", true, true, false) + pug_attr("baz", true, true, false)) + '></a><a foo="foo, bar, baz" bar="1"></a><a foo="((foo))" bar="1"></a><select><option' + (' value="foo"' + pug_attr("selected", true, true, false)) + ">Foo</option><option" + (pug_attr("selected", true, true, false) + ' value="bar"') + '>Bar</option></select><a foo="class:"></a><input pattern="\\S+"/><a href="/contact">contact</a><a class="button" href="/save">save</a><a' + (pug_attr("foo", true, true, false) + pug_attr("bar", true, true, false) + pug_attr("baz", true, true, false)) + '></a><a foo="foo, bar, baz" bar="1"></a><a foo="((foo))" bar="1"></a><select><option' + (' value="foo"' + pug_attr("selected", true, true, false)) + ">Foo</option><option" + (pug_attr("selected", true, true, false) + ' value="bar"') + '>Bar</option></select><a foo="class:"></a><input pattern="\\S+"/><foo terse="true"></foo><foo' + pug_attr("date", new Date(0), true, false) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo><foo" + (pug_attr("abc", true, true, false) + pug_attr("def", true, true, false)) + "></foo>";
  73. var attrs = {
  74. foo: "bar",
  75. bar: "<baz>"
  76. };
  77. pug_html = pug_html + "<div" + pug_attrs(attrs, false) + '></div><a foo="foo" bar="bar"></a><a foo="foo" bar="bar"></a>';
  78. }).call(this, "Date" in locals_for_with ? locals_for_with.Date : typeof Date !== "undefined" ? Date : undefined);
  79. return pug_html;
  80. }