-
Notifications
You must be signed in to change notification settings - Fork 46
/
html_generators.js
324 lines (264 loc) · 10.7 KB
/
html_generators.js
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
"use strict";
var HtmlGenerator = new Blockly.Generator('HTML');
HtmlGenerator.ORDER_ATOMIC = 0;
HtmlGenerator.ORDER_NONE = 0;
HtmlGenerator.init = function(workspace) {};
HtmlGenerator.finish = function(code) {return code;};
HtmlGenerator.scrub_ = function(block, code) {
var nextBlock = block.nextConnection && block.nextConnection.targetBlock();
var nextCode = HtmlGenerator.blockToCode(nextBlock);
return code + nextCode;
};
function removeIndentAndTrailingNewline() {
}
HtmlGenerator['baseframe'] = function(block) {
var statements_head = HtmlGenerator.statementToCode(block, 'head');
var statements_body = HtmlGenerator.statementToCode(block, 'body');
var code = '<!DOCTYPE HTML>\n<html>\n<head>\n <meta charset="utf-8">\n'
+ statements_head
+ "</head>\n\n<body>\n"
+ statements_body
+ "</body>\n</html>\n";
return code;
};
HtmlGenerator['html'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<!DOCTYPE HTML>\n<html>\n' + statements_content + '</html>\n';
return code;
};
HtmlGenerator['body'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<body>\n' + statements_content + '</body>\n';
return code;
};
HtmlGenerator['head'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<head>\n <meta charset="utf-8">\n' + statements_content + '</head>\n';
return code;
};
HtmlGenerator['title'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
if (statements_content != "")
document.getElementById('title').innerText = statements_content;
else
document.getElementById('title').innerText = "untitled web page";
var code = '<title>' + statements_content.trim() + '</title>\n';
return code;
};
HtmlGenerator['paragraph'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<p>\n' + statements_content + '</p>\n';
return code;
};
HtmlGenerator['plaintext'] = function(block) {
var text_content = block.getFieldValue('content');
var code = text_content + '\n';
return code;
};
HtmlGenerator['division'] = function(block) {
var value_name = HtmlGenerator.valueToCode(block, 'NAME', HtmlGenerator.ORDER_ATOMIC);
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<div' + value_name + '>\n' + statements_content + '</div>\n';
return code;
};
HtmlGenerator['style'] = function(block) {
var statements_name = HtmlGenerator.statementToCode(block, 'NAME');
var code = ' style="' + statements_name.trim() + '"';
return [code, HtmlGenerator.ORDER_NONE];
};
HtmlGenerator['color'] = function(block) {
var colour_name = block.getFieldValue('NAME');
var code = 'color: ' + colour_name + ';';
return code;
};
HtmlGenerator['bgcolour'] = function(block) {
var colour_name = block.getFieldValue('NAME');
var code = 'background-color: ' + colour_name + ';';
return code;
};
HtmlGenerator['genericstyle'] = function(block) {
var text_property = block.getFieldValue('property');
var text_value = block.getFieldValue('value');
var code = text_property + ': ' + text_value + ';';
return code;
};
HtmlGenerator['generictag'] = function(block) {
var text_name = block.getFieldValue('NAME');
var value_name = HtmlGenerator.valueToCode(block, 'NAME', HtmlGenerator.ORDER_ATOMIC);
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<' + text_name + value_name + '>\n' + statements_content + '</' + text_name + '>\n';
return code;
};
HtmlGenerator['more_attributes'] = function(block) {
var value_name1 = HtmlGenerator.valueToCode(block, 'NAME1', HtmlGenerator.ORDER_ATOMIC);
var value_name2 = HtmlGenerator.valueToCode(block, 'NAME2', HtmlGenerator.ORDER_ATOMIC);
var value_name3 = HtmlGenerator.valueToCode(block, 'NAME3', HtmlGenerator.ORDER_ATOMIC);
var code = value_name1 + value_name2 + value_name3;
return [code, HtmlGenerator.ORDER_NONE];
};
HtmlGenerator['genericattribute'] = function(block) {
var text_attribute = block.getFieldValue('attribute');
var text_value = block.getFieldValue('value');
var code = ' ' + text_attribute + '="' + text_value + '"';
return [code, HtmlGenerator.ORDER_NONE];
};
HtmlGenerator['link'] = function(block) {
var text_name = block.getFieldValue('NAME');
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<a href="' + text_name + '">' + statements_content.trim() + '</a>\n';
return code;
};
HtmlGenerator['span'] = function(block) {
var value_name = HtmlGenerator.valueToCode(block, 'NAME', HtmlGenerator.ORDER_ATOMIC);
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<span' + value_name + '>' + statements_content.trim() + '</span>\n';
return code;
};
HtmlGenerator['image'] = function(block) {
var text_image = block.getFieldValue('IMAGE');
var text_alt = block.getFieldValue('ALT');
var code = '<img src="' + text_image + '" alt="' + text_alt + '">\n';
return code;
};
HtmlGenerator['emphasise'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<em>' + statements_content.trim() + '</em>\n';
return code;
};
HtmlGenerator['strong'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<strong>' + statements_content.trim() + '</strong>\n';
return code;
};
HtmlGenerator['headline'] = function(block) {
var dropdown_name = block.getFieldValue('NAME');
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<' + dropdown_name + '>' + statements_content.trim() + '</' + dropdown_name + '>\n';
return code;
};
HtmlGenerator['linebreak'] = function(block) {
var code = '<br>\n';
return code;
};
HtmlGenerator['horizontalbreak'] = function(block) {
var code = '<hr>\n';
return code;
};
HtmlGenerator['unorderedlist'] = function(block) {
var statements_name = HtmlGenerator.statementToCode(block, 'NAME');
var code = '<ul>\n' + statements_name + '</ul>\n';
return code;
};
HtmlGenerator['orderedlist'] = function(block) {
var statements_name = HtmlGenerator.statementToCode(block, 'NAME');
var code = '<ol>\n' + statements_name + '</ol>\n';
return code;
};
HtmlGenerator['listelement'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<li>' + statements_content + '</li>\n';
return code;
};
HtmlGenerator['inserted'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<ins>' + statements_content.trim() + '</ins>\n';
return code;
};
HtmlGenerator['deleted'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<del>' + statements_content.trim() + '</del>\n';
return code;
};
HtmlGenerator['super'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<sup>' + statements_content.trim() + '</sup>\n';
return code;
};
HtmlGenerator['sub'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<sub>' + statements_content.trim() + '</sub>\n';
return code;
};
HtmlGenerator['code'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<code>\n' + statements_content + '</code>\n';
return code;
};
HtmlGenerator['quote'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<q>' + statements_content.trim() + '</q>\n';
return code;
};
HtmlGenerator['blockquote'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<blockquote>\n' + statements_content + '</blockquote>\n';
return code;
};
HtmlGenerator['sample'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<samp>\n' + statements_content + '</samp>\n';
return code;
};
HtmlGenerator['keyboard'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<kbd>\n' + statements_content + '</kbd>\n';
return code;
};
HtmlGenerator['variable'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<var>' + statements_content.trim() + '</var>\n';
return code;
};
HtmlGenerator['form'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<form>\n' + statements_content + '</form>\n';
return code;
};
HtmlGenerator['table'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<table>\n' + statements_content + '</table>\n';
return code;
};
HtmlGenerator['tablerow'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<tr>\n' + statements_content + '</tr>\n';
return code;
};
HtmlGenerator['tablecell'] = function(block) {
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<td>' + statements_content.trim() + '</td>\n';
return code;
};
HtmlGenerator['input_text'] = function(block) {
var text_default = block.getFieldValue('default');
var code = '<input value="' + text_default + '">\n';
return code;
};
HtmlGenerator['button'] = function(block) {
var statements_name = HtmlGenerator.statementToCode(block, 'NAME');
var code = '<button>' + statements_name.trim() + '</button>\n';
return code;
};
HtmlGenerator['input'] = function(block) {
var dropdown_type = block.getFieldValue('type');
var text_value = block.getFieldValue('value');
var value_text = HtmlGenerator.valueToCode(block, 'text', HtmlGenerator.ORDER_ATOMIC);
var code = '<input type="' + dropdown_type + '" value="' + text_value + '"' + value_text + ' />\n';
return code;
};
HtmlGenerator['script'] = function(block) {
var statements_content = Blockly.JavaScript.statementToCode(block, 'content');
var code = '<script>\n' + statements_content + '</script>\n';
return code;
};
HtmlGenerator['onclick'] = function(block) {
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
var code = ' onclick="' + statements_name.trim() + '"';
return [code, HtmlGenerator.ORDER_NONE];
};
HtmlGenerator['body_attributes'] = function(block) {
var value_name = HtmlGenerator.valueToCode(block, 'NAME', HtmlGenerator.ORDER_ATOMIC);
var statements_content = HtmlGenerator.statementToCode(block, 'content');
var code = '<body' + value_name + '>\n' + statements_content + '</body>\n';
return code;
};