-
Notifications
You must be signed in to change notification settings - Fork 0
/
col-detach.wok
69 lines (62 loc) · 1.93 KB
/
col-detach.wok
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
#!/usr/bin/wok -f
/** col-detach.wok
*
* Usage:
* java -jar wok-0.1.0.jar -f col-detach.wok -v@str src=1,2,3 -v dst=1 -v@rawstr media=path_to_media_dir input > output
*
* Option:
* -v@str src: The index number of the source column. When it is separated by commas and do not contain space,
* this can contain mutiple values.
* -v dst: The index number of the destination column.
* -v@rawstr media: Path to a directory to be used as the output destination of HTML files.
*/
FS = '\t'
FQ = Quote.Min
OFS = '\t'
OFQ = Quote.All
val srcs = src
.split(",")
.map(_.toInt)
.toList
val md = java.security.MessageDigest.getInstance("md5")
val html_head =
"""<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="col-detach.css">
<script type="text/javascript" src="col-detach.js"></script>
</head>
<body>
<div id="detached">
"""
val html_tail =
"""
</div>
</body>
</html>
"""
In { _
.map { row =>
// asasure that row have just the size
val padding = math.max(dst, srcs.max) + srcs.count(_ <= dst)
row.padTo(padding, "")
}
.map { row =>
val body = srcs.zipWithIndex
.map { case (x, i) => f"""<div id="detached-${i}%02d">${row(x)}</div>""" }
.mkString
val bytes = (html_head + body + html_tail).getBytes("utf-8")
md.reset()
md update bytes
val hash = md.digest().map("%02X" format _).mkString
val file = media / s"$hash.html"
if (file nonExistent)
file write bytes
val buffer = row.toBuffer
srcs.sorted.reverse foreach (buffer remove _)
buffer.insert(dst, s"""<iframe src="${file.name}"></iframe>""")
buffer.toList
}
.foreach (row => println(row: _*))
}