-
Notifications
You must be signed in to change notification settings - Fork 9
/
index_generator.groovy
85 lines (70 loc) · 3.04 KB
/
index_generator.groovy
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
/**
* link_generator.groovy
* generate index page for abcd mobile workshop
*/
def f = new File(".")
def srcDir = f.absolutePath
srcDir = srcDir.substring(0,srcDir.length()-1)
f.eachFile { dir ->
if (dir.isDirectory() && dir.name.charAt(0) != '.') {
dir.eachFile { file ->
if (file.name.contains("00_README.txt")) {
def dest = new File(dir, "index.html")
def pw = new PrintWriter(dest)
def fileName = dir.absolutePath.replace(srcDir,'')
fileName = fileName.replace ('./', '')
fileName = fileName.replace ('_', ' ')
pw.println "<!DOCTYPE html>\n<html>\n<head>\n<title>$fileName</title>\n"
pw.println new File("00_resources/cdn_css.txt").text
pw.println"</head>"
pw.println "<body>\n<div class=\"container\">\n"
pw.println "<div class=\"jumbotron\" style=\"background-color: #293352 !important; color: #F4EDCA !important; border: medium solid #4E84C4 !important;\">"
pw.println "<h1>Bootstrap Workshop</h1>\n<h2>${fileName}</h2>\n</div>"
def list = false
def pre = false
file.eachLine { line ->
if (line) {
if (line.startsWith('<pre>')) {
pw.println line
pre = true
} else if (line.startsWith('</pre>')) {
pw.println line
pre = false
} else {
line = line.replaceAll('<img', '<img')
line = line.replaceAll('/>', '/>')
if (pre) {
pw.println line
} else if (line.startsWith('-')) {
pw.println("<h2>${line.substring(1)}</h2>")
} else if (line.startsWith('http')) {
pw.println "<a href=\"$line\" target=\"_blank\">$line</a><br/>"
} else {
if (line.startsWith('*')) {
if (!list) {
pw.println("<ul>")
}
list = true
} else {
if (list) {
pw.println("</ul>")
}
list = false
}
if (list) {
pw.println "<li>${line.substring(1)}</li>"
} else {
pw.println("<p>$line</p>")
}
}
}
}
}
pw.println "\n</div>"
pw.println new File("00_resources/cdn_js.txt").text
pw.println "\n</body>\n</html>"
pw.close()
}
}
}
}