styles.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. pug_html = pug_html + '<html><head><style>body {\n padding: 50px;\n}</style></head><body><div style="color:red;background:green"></div><div style="color:red;background:green;"></div><div' + pug_attrs({
  71. style: "color:red;background:green"
  72. }, false) + "></div><div" + pug_attrs({
  73. style: {
  74. color: "red",
  75. background: "green"
  76. }
  77. }, false) + "></div>";
  78. pug_mixins["div"] = pug_interp = function() {
  79. var block = this && this.block, attributes = this && this.attributes || {};
  80. pug_html = pug_html + "<div" + pug_attrs(attributes, false) + "></div>";
  81. };
  82. pug_mixins["div"].call({
  83. attributes: {
  84. style: "color:red;background:green"
  85. }
  86. });
  87. pug_mixins["div"].call({
  88. attributes: {
  89. style: "color:red;background:green;"
  90. }
  91. });
  92. var bg = "green";
  93. pug_html = pug_html + "<div" + pug_attr("style", pug_style({
  94. color: "red",
  95. background: bg
  96. }), true, false) + "></div><div" + pug_attrs({
  97. style: {
  98. color: "red",
  99. background: bg
  100. }
  101. }, false) + "></div>";
  102. pug_mixins["div"].call({
  103. attributes: {
  104. style: pug_escape(pug_style({
  105. color: "red",
  106. background: bg
  107. }))
  108. }
  109. });
  110. pug_html = pug_html + "</body></html>";
  111. return pug_html;
  112. }