-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseAngelus.groovy
49 lines (48 loc) · 1.62 KB
/
parseAngelus.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
import groovy.json.*
/** Combine two data files (usually English and Latin) into one dual language
* version, which will be used to generate the HTML page.*/
def cli = new CliBuilder(usage: "Read two Angelus files and weave them together")
cli.p(longOpt: "primary", args: 1, required: true, "Primary file")
cli.s(longOpt: "secondary", args: 1, required: true, "Secondary file")
def opt = cli.parse(args)
assert opt
def p = new File(opt.p)
def s = new File(opt.s)
def data = [
lang: [
p: p.name.replaceAll(/.*\./, ''),
s: s.name.replaceAll(/.*\./, '')
],
lines: [:]
]
println data
[p,s].each {assert it.exists()}
data.lines["p"] = p.readLines().grep {it =~ /[^ ]/}
data.lines.s = s.readLines().grep {it =~ /[^ ]/}
assert data.lines.p.size() == data.lines.s.size()
// Now march through the lines and create unified file.
def l = data.lines
println "data.lang=${data.lang}"
def sections = (0 .. data.lines.p.size()).collect {
i ->
def pt = l.p[i];
def st = l.s[i];
println "data.lang=${data.lang}"
def lang=data.lang
(pt =~ /&(.*)\.\.\. *$/).each {
m ->
def fileBase = m[1]
ptf = new File("$fileBase.${lang.p}")
stf = new File("$fileBase.${lang.s}")
pt = "$fileBase: ${ptf.text}"
st = "$fileBase: ${stf.text}"
}
def sct = ['','','']
(pt =~ /^([a-zA-Z]+): *(.*)/).each {
sct = [it[1] as String,
pt.replaceAll(/^[^:]+: */,''),
st.replaceAll(/^[^:]+: */,'')]
}
sct
}
new File('webapp/js/angelus.json').text = new JsonOutput().prettyPrint(new JsonOutput().toJson(sections))