mixin.attrs.js
7.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
function pug_attr(t, e, n, f) {
return e !== !1 && null != e && (e || "class" !== t && "style" !== t) ? e === !0 ? " " + (f ? t : t + '="' + t + '"') : ("function" == typeof e.toJSON && (e = e.toJSON()),
"string" == typeof e || (e = JSON.stringify(e), n || e.indexOf('"') === -1) ? (n && (e = pug_escape(e)),
" " + t + '="' + e + '"') : " " + t + "='" + e.replace(/'/g, "'") + "'") : "";
}
function pug_attrs(t, r) {
var a = "";
for (var s in t) if (pug_has_own_property.call(t, s)) {
var u = t[s];
if ("class" === s) {
u = pug_classes(u), a = pug_attr(s, u, !1, r) + a;
continue;
}
"style" === s && (u = pug_style(u)), a += pug_attr(s, u, !1, r);
}
return a;
}
function pug_classes(s, r) {
return Array.isArray(s) ? pug_classes_array(s, r) : s && "object" == typeof s ? pug_classes_object(s) : s || "";
}
function pug_classes_array(r, a) {
for (var s, e = "", u = "", c = Array.isArray(a), g = 0; g < r.length; g++) s = pug_classes(r[g]),
s && (c && a[g] && (s = pug_escape(s)), e = e + u + s, u = " ");
return e;
}
function pug_classes_object(r) {
var a = "", n = "";
for (var o in r) o && r[o] && pug_has_own_property.call(r, o) && (a = a + n + o,
n = " ");
return a;
}
function pug_escape(e) {
var a = "" + e, t = pug_match_html.exec(a);
if (!t) return e;
var r, c, n, s = "";
for (r = t.index, c = 0; r < a.length; r++) {
switch (a.charCodeAt(r)) {
case 34:
n = """;
break;
case 38:
n = "&";
break;
case 60:
n = "<";
break;
case 62:
n = ">";
break;
default:
continue;
}
c !== r && (s += a.substring(c, r)), c = r + 1, s += n;
}
return c !== r ? s + a.substring(c, r) : s;
}
var pug_has_own_property = Object.prototype.hasOwnProperty;
var pug_match_html = /["&<>]/;
function pug_merge(r, e) {
if (1 === arguments.length) {
for (var t = r[0], a = 1; a < r.length; a++) t = pug_merge(t, r[a]);
return t;
}
for (var g in e) if ("class" === g) {
var l = r[g] || [];
r[g] = (Array.isArray(l) ? l : [ l ]).concat(e[g] || []);
} else if ("style" === g) {
var l = pug_style(r[g]), n = pug_style(e[g]);
r[g] = l + n;
} else r[g] = e[g];
return r;
}
function pug_style(r) {
if (!r) return "";
if ("object" == typeof r) {
var t = "";
for (var e in r) pug_has_own_property.call(r, e) && (t = t + e + ":" + r[e] + ";");
return t;
}
return r += "", ";" !== r[r.length - 1] ? r + ";" : r;
}
function template(locals) {
var pug_html = "", pug_mixins = {}, pug_interp;
pug_mixins["centered"] = pug_interp = function(title) {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + "<div" + (' class="centered"' + pug_attr("id", attributes.id, true, false)) + ">";
if (title) {
pug_html = pug_html + "<h1" + pug_attr("class", pug_classes([ attributes.class ], [ true ]), false, false) + ">" + pug_escape(null == (pug_interp = title) ? "" : pug_interp) + "</h1>";
}
block && block();
if (attributes.href) {
pug_html = pug_html + '<div class="footer"><a' + pug_attr("href", attributes.href, true, false) + ">Back</a></div>";
}
pug_html = pug_html + "</div>";
};
pug_mixins["main"] = pug_interp = function(title) {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + '<div class="stretch">';
pug_mixins["centered"].call({
block: function() {
block && block();
},
attributes: pug_merge([ {
class: "highlight"
}, attributes ])
}, title);
pug_html = pug_html + "</div>";
};
pug_mixins["bottom"] = pug_interp = function() {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + "<div" + pug_attrs(pug_merge([ {
class: "bottom"
}, attributes ]), false) + ">";
block && block();
pug_html = pug_html + "</div>";
};
pug_html = pug_html + "<body>";
pug_mixins["centered"].call({
block: function() {
pug_html = pug_html + "Hello World";
},
attributes: {
id: "First"
}
});
pug_mixins["centered"].call({
block: function() {
pug_html = pug_html + "<p>Some important content.</p>";
},
attributes: {
id: "Second"
}
}, "Section 1");
pug_mixins["centered"].call({
block: function() {
pug_html = pug_html + "<p>Even more important content.</p>";
},
attributes: {
class: "foo bar",
id: "Third",
href: "menu.html"
}
}, "Section 2");
pug_mixins["main"].call({
block: function() {
pug_html = pug_html + "<p>Last content.</p>";
},
attributes: {
href: "#"
}
}, "Section 3");
pug_mixins["bottom"].call({
block: function() {
pug_html = pug_html + "<p>Some final words.</p>";
},
attributes: {
class: "foo bar",
name: "end",
id: "Last",
"data-attr": "baz"
}
});
pug_mixins["bottom"].call({
attributes: {
class: "class1 class2"
}
});
pug_html = pug_html + "</body>";
pug_mixins["foo"] = pug_interp = function() {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + "<div" + pug_attrs(pug_merge([ {
class: "thing",
attr1: "foo",
attr2: "bar"
}, attributes ]), false) + "></div>";
};
var val = "<biz>";
var classes = [ "foo", "bar" ];
pug_mixins["foo"].call({
attributes: {
class: pug_classes([ classes, "thunk" ], [ true, false ]),
attr3: "baz",
"data-foo": pug_escape(val),
"data-bar": val
}
});
pug_mixins["work_filmstrip_item"] = pug_interp = function(work) {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + "<div" + pug_attrs(attributes, false) + ">" + pug_escape(null == (pug_interp = work) ? "" : pug_interp) + "</div>";
};
pug_mixins["work_filmstrip_item"].call({
attributes: {
"data-profile": "profile",
"data-creator-name": "name"
}
}, "work");
pug_mixins["my-mixin"] = pug_interp = function(arg1, arg2, arg3, arg4) {
var block = this && this.block, attributes = this && this.attributes || {};
pug_html = pug_html + "<p>" + pug_escape(null == (pug_interp = arg1) ? "" : pug_interp) + "</p><p>" + pug_escape(null == (pug_interp = arg2) ? "" : pug_interp) + "</p><p>" + pug_escape(null == (pug_interp = arg3) ? "" : pug_interp) + "</p><p>" + pug_escape(null == (pug_interp = arg4) ? "" : pug_interp) + "</p>";
};
pug_mixins["foo"].call({
attributes: {
class: "baz",
attr3: "qux"
}
});
pug_mixins["my-mixin"]("1", "2", "3", "4");
return pug_html;
}