-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_code-builders.js
54 lines (47 loc) · 1.29 KB
/
_code-builders.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
define(["_tag-builders", "_dom-writers", "_array-helpers"], function(tags, writers, arrays){
return {
buildCodeTagsSet: buildCodeTagsSet,
writeAdjacentCode: writeAdjacentCode,
};
function writeAdjacentCode(ioSets){
var preTags = buildCodeTagsSet(ioSets);
var tagStack = tags.stackBuilder(preTags);
writers.appendToFirstArticle(tagStack);
}
function buildCodeTagsSet(ioSets){
return ioSets.
map(setToLineTags).
reduce(arrays.concat).
filter(Boolean);
}
function setToLineTags(set){
return [
buildCommentPre(set.c),
buildCodePre(set.i),
buildSampPre(set.o),
];
}
function buildCommentPre(lines){
if(lines == undefined){ return; }
var commentTag = buildPre(lines);
commentTag.className = "code-comment";
return commentTag;
}
function buildCodePre(lines){
var codeTag = tags.builder("code")();
return buildPre(lines, codeTag);
}
function buildSampPre(lines){
var sampTag = tags.builder("samp")();
return buildPre(lines, sampTag);
}
function buildPre(lines, wrapperTag){
var preTag = tags.builder("pre", lines.join("\n"))();
if(wrapperTag){
wrapperTag.insertAdjacentElement('beforeEnd', preTag);
return wrapperTag;
} else {
return preTag;
}
}
});