-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvgen.scala
181 lines (137 loc) · 3.99 KB
/
cvgen.scala
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
import java.io._
import scala.xml._
object cvgen {
def main(args: Array[String]) {
val cv_xml = args(0)
val cv_tex = cv_xml.replaceAll("xml", "tex")
val cv = XML.loadFile(cv_xml)
def escape(text: String): String =
text.replace("&", "\\&").replace("#", "\\#").replace("_", "\\_").replace("\n", " \\newline ")
def entrytext2row(entry: NodeSeq): String = (entry\"@type").text match {
case "url" => """\""" + """url{""" + entry.text + """}"""
case "ref" => entry.text.replace("\n", " \\newline")
case _ => escape(entry.text)
}
def entry2row(entry: NodeSeq): String = {
(entry\"@key").text match {
case "Name" => """
\multicolumn{3}{ l } {\LARGE{\textbf{""" + entry.text + """}}} \\
\multicolumn{3}{ l } {\textbf{Curriculum Vitae}} \\
\multicolumn{3}{ l } {} \\
"""
case _ => """
\nohyphens{\textbf{""" + entry\"@key" + """}} && \nohyphens{""" + entrytext2row(entry) + """} \\
"""
}
}
def p_entry2row(entry: NodeSeq): String = {
(entry\"@key").text match {
case "description" => """\multicolumn{3}{ p{0.9\textwidth } } {""" + escape(entry.text) + """} \\
\multicolumn{3}{ l } {} \\
"""
case _ => """
\mbox{\textbf{""" + entry\"@key" + """}} && """ + entrytext2row(entry) + """ \\
"""
}
}
def section2tabular(section: NodeSeq): String = {
var text = """
\begin{tabular}{p{0.25\textwidth} p{0.01\textwidth} p{0.7\textwidth}}
"""
section \ "entry" foreach { entry =>
text += entry2row(entry)
}
text += """
\end{tabular}
"""
text
}
def project2tabular(section: NodeSeq): String = {
var text = """
\begin{tabular}{p{0.25\textwidth} p{0.01\textwidth} p{0.7\textwidth}}
"""
section \ "entry" foreach { entry =>
text += p_entry2row(entry)
}
text += """
\end{tabular}
"""
text
}
var text = """
\documentclass[12pt]{article}
\"""+"""usepackage[printwatermark]{xwatermark}
\"""+"""usepackage{xcolor}
\"""+"""usepackage{color}
\"""+"""usepackage{graphicx}
\"""+"""usepackage{wrapfig}
\"""+"""usepackage{hyperref}
\"""+"""usepackage[utf8]{inputenc}
\"""+"""usepackage{hyphenat}
\"""+"""usepackage[margin=2cm]{geometry}
\usepackage{fontspec}
\newwatermark[allpages,color=black!50,angle=90,scale=0.25,xpos=-100,ypos=0]{Generated by \url{https://github.com/coiouhkc/cvgen} }
\begin{document}
\thispagestyle{empty}
\pagestyle{empty}
"""
// cv
(cv \\ "section") .filter ( section => (section\"@type").text == "general" ) .foreach { section =>
val sectionName = section\"@name"
text += """
\begin{minipage}[t]{\textwidth}""" + section2tabular(section) + """
\end{minipage}
\begin{picture}(0,0)
\put(400,0){\hbox{\includegraphics[height=4cm]{resources/portrait.jpg}}}
\end{picture}
"""
}
(cv \\ "section") .filter ( section => (section\"@type").text != "general" ) .foreach { section =>
val sectionName = section\"@name"
text += """
\begin{minipage}[t]{\textwidth}
\vskip\medskipamount
{\Large {\textbf{""" + sectionName + """}}}
\vskip\medskipamount
\leaders\vrule width \textwidth\vskip0.4pt
"""
text += """
""" + section2tabular(section) + """
\end{minipage}
"""
}
// new page
text += """
\newpage"""
// projects header
(cv \\ "projects" ) foreach { project =>
val projectHeader = project\"@name"
text += """
{\LARGE """ + projectHeader + """}
\vskip\medskipamount
\leaders\vrule width \textwidth\vskip0.4pt
\vskip\medskipamount
\leaders\vrule width \textwidth\vskip0.4pt
"""
}
// project
(cv \\ "project" ) foreach { project =>
val projectName = project\"@name"
text += """
\begin{minipage}[t]{\textwidth}
\vskip\medskipamount
{\Large \textbf{""" + projectName + """}}
\vskip\medskipamount
\leaders\vrule width \textwidth\vskip0.4pt
"""
text += """
""" + project2tabular(project) + """
\end{minipage}
"""
}
text += """
\end{document}
"""
Some(new PrintWriter(cv_tex)).foreach{p => p.write(text); p.close}
}
}