-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv.rb
445 lines (399 loc) · 16.8 KB
/
cv.rb
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'htmlentities'
module CV
PROF_EXP={:en => "Work Experience", :fr => "Expérience Professionelle"}
DEGREES ={:en=> "Education", :fr=>"Diplômes et Études"}
PERSONAL ={:en=> "Personal Experience", :fr=>"Expérience Personnelle"}
SKILLS ={:en=> "Skills", :fr=>"Compétences"}
OTHERS ={:en=> "Others", :fr=>"Divers"}
LANGUAGES ={:en=> "Languages", :fr=>"Langages"}
PATENTS ={:en=> "Patents", :fr=>"Brevets"}
def stringToTeX(str)
return nil if str == nil
return str.gsub(/!BR!/, "\\\\\\").gsub(/&/, '\\\&').gsub(/€/, '\\texteuro').gsub(/!B!.*!B!/) { |n|
"\\textbf{" + n.gsub(/!B!/, "") +"}"
}.gsub(/!I!(.*)!I!/) { |n|
"$" + n.gsub(/!I!/, "") +"$"
}
end
module_function :stringToTeX
def stringToBasicHTML(str)
return nil if str == nil
coder = HTMLEntities.new
return coder.encode(str, :named)
end
module_function :stringToBasicHTML
def stringToText(str)
return nil if str == nil
return str.gsub(/!BR!/, "").gsub(/!B!.*!B!/) { |n|
n.gsub(/!B!/, "")
}.gsub(/!I!(.*)!I!/) { |n|
n.gsub(/!I!/, "")
}
end
module_function :stringToText
def HTMLputs(file, str)
str = str.gsub(/!BR!/, "<br />").gsub(/é/, "é").gsub(/è/, "è").gsub(/à/, "à").gsub(/!B!.*!B!/) { |n|
"<b>" + n.gsub(/!B!/, "") +"</b>"
}.gsub(/!I!(.*)!I!/) { |n|
"<i>" + n.gsub(/!I!/, "") +"</i>"
}
file.puts str
end
module_function :HTMLputs
class Top
attr_accessor :firstName, :lastName, :title, :address, :city,
:mobile, :email, :homepage, :extras, :professional, :degrees,
:personal, :skills, :skill_cols, :languages,:other, :patents, :language, :pagetitle,
:header, :footer, :middleStuff
def initialize()
@extras=[]
@professional=[]
@degrees=[]
@personal=[]
@skills={}
@skills_cols = 2
@other=[]
@language = :fr
@languages=[]
@patents=[]
end
def toTeX(filename)
file = File.open(filename, "w")
file.puts "\\documentclass[10pt,a4paper]{moderncv}
\\moderncvstyle{classic}
\\moderncvcolor{blue}
\\moderncvicons{awesome}
\\usepackage[scale=0.8]{geometry}
"
file.puts "\\name{#{@firstName.to_s()}}{#{@lastName.to_s()}}"
file.puts "\\title{#{CV::stringToTeX(@title).gsub('\\\\', ' ')}}" if @title != nil
file.puts "\\address{#{@address}}{#{@city}}" if @address != nil || @city != nil
file.puts "\\phone[mobile]{#{@mobile}}" if @mobile != nil
file.puts "\\email{#{@email}}" if @email != nil
file.puts "\\homepage{#{@homepage}}" if @homepage != nil
@extras.each() {|extra|
file.puts "\\extrainfo{#{extra}}"
}
file.puts "
\\begin{document}
\\maketitle"
file.puts "\\section{#{CV::PROF_EXP[@language]}}" if @professional.length != 0
@professional.each() {|prof|
prof.toTeX(file)
}
file.puts "\n\\section{#{CV::DEGREES[@language]}}" if @degrees.length != 0
@degrees.each() {|prof|
prof.toTeX(file)
}
file.puts "\n\n\\section{#{CV::PERSONAL[@language]}}" if @personal.length != 0
@personal.each() {|prof|
prof.toTeX(file)
}
file.puts "\n\n\\section{#{CV::SKILLS[@language]}}" if @skills.length != 0 ||
@languages.length != 0
@skills.each() {|skill_type, skill_list|
cat = skill_type
cols = @skills_cols
if skill_type.kind_of?(Hash) then
cat = skill_type[:name]
cols = skill_type[:cols] if skill_type[:cols].to_s() != ""
end
file.puts "\n\n\\subsection{#{CV::stringToTeX(cat)}}"
inLine = 0
case cols
when 1
skill_list.each(){|skill|
CV::HTMLputs(file, "\n\n\\cvline")
skill.toTeX(file)
}
when 2
skill_list.each(){|skill|
CV::HTMLputs(file, "\n\n\\cvcomputer") if inLine == 0
skill.toTeX(file)
inLine += 1
inLine = 0 if inLine == 2
}
file.puts "{}{}" if inLine != 0
else
raise("Invalid # of skill columns")
end
}
file.puts "\n\n\\subsection{#{CV::LANGUAGES[@language]}}" if @languages.length != 0
@languages.each(){|lang|
lang.toTeX(file)
}
file.puts "\n\n\\section{#{CV::PATENTS[@language]}}" if @patents.length != 0
@patents.each(){|lang|
lang.toTeX(file)
}
file.puts "\n\n\\section{#{CV::OTHERS[@language]}}" if @other.length != 0
@other.each(){|ot|
ot.toTeX(file)
}
file.puts "\\end{document}"
file.close()
end
def toHTML(filename)
file = File.open(filename, "w")
CV::HTMLputs(file, "
<html>
<head><title>#{@firstName} #{@lastName}</title>
<meta name='description' content=\"#{@firstName} #{@lastName}'s Web Page\" >
<meta name='keywords' content='#{@firstName}, @{lastName}, CV, #{@keywords}' >
<meta name='robots' content='all'>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<link rel='stylesheet' type='text/css' href='cv.css'>
</head>
<body>
#{@header}
<table width='100\%'><tr>
<td><img src='cv-pic.jpg' alt='MyPicture' height='300' ></td><td >
<span class='cv-name'>#{@firstName} #{lastName}</span><br /><br />
<span class='cv-title'>#{@title}</span>
</td>
<td>")
CV::HTMLputs(file, "<span class='cv-coord'>#{@address}</span><br />") if @address != nil
CV::HTMLputs(file, "<span class='cv-coord'>#{@city}</span><br />") if @city != nil
CV::HTMLputs(file, "<span class='cv-coord'>#{@mobile}</span><br />") if @mobile != nil
if @email != nil
CV::HTMLputs(file, "<span class='cv-coord'>#{@email.gsub(/\./, " DOT ").gsub(/@/, " AT ")}</span><br />")
end
if @homepage != nil
CV::HTMLputs(file, "<span class='cv-coord'><a href='http://#{@homepage}'>#{@homepage}</a></span><br />")
end
@extras.each() {|extra|
CV::HTMLputs(file, "<span class='cv-coord'>#{extra}</span><br />")
}
CV::HTMLputs(file,"</td>\n</tr>\n</table><br />#{middleStuff}")
CV::HTMLputs(file, "<br /> <br /><table width='100%'>")
#Professional
CV::HTMLputs(file, "<tr><td class='section-filler'></td>" +
"<td colspan=3 class='section-title'>" +
"#{CV::stringToBasicHTML(CV::PROF_EXP[@language])}</td></tr>"
) if @professional.length != 0
@professional.each() {|prof|
CV::HTMLputs(file, "<tr class='entry-padding'></tr>")
prof.toHTML(file)
}
# Degress
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr><td class='section-filler'></td>" +
"<td class='section-title'>" +
"#{CV::stringToBasicHTML(CV::DEGREES[@language])}</td></tr>"
) if @degrees.length != 0
@degrees.each() {|prof|
CV::HTMLputs(file, "<tr class='entry-padding'></tr>")
prof.toHTML(file)
}
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
# Personal
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr><td class='section-filler'></td>" +
"<td class='section-title'>" +
"#{CV::stringToBasicHTML(CV::PERSONAL[@language])}</td></tr>"
) if @personal.length != 0
@personal.each() {|prof|
CV::HTMLputs(file, "<tr class='entry-padding'></tr>")
prof.toHTML(file)
}
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
# Skills
CV::HTMLputs(file, "<tr><td class='section-filler'></td><td colspan=3 class='section-title'>" +
"#{CV::stringToBasicHTML(CV::SKILLS[@language])}</td></tr>"
) if @skills.length != 0 || @languages.length != 0
@skills.each() {|skill_type, skill_list|
CV::HTMLputs(file, "<tr><td></td><td class='skill-title'>" +
"#{skill_type}</td></tr>")
inLine = 0
skill_list.each(){|skill|
CV::HTMLputs(file, "<tr>") if inLine == 0
skill.toHTML(file)
inLine +=1
if inLine == 2
CV::HTMLputs(file, "</tr>")
inLine = 0
end
}
if(inLine != 0)
CV::HTMLputs(file, "</tr>")
end
CV::HTMLputs(file, "<tr class='skill-padding'></tr>")
}
CV::HTMLputs(file, "<tr><td></td><td class='skill-title'>" +
"#{CV::LANGUAGES[@language]}</td></tr>") if @languages.length != 0
@languages.each() {|lang|
lang.toHTML(file)
}
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr><td class='section-filler'></td>" +
"<td class='section-title'>" +
"#{CV::stringToBasicHTML(CV::PATENTS[@language])}</td></tr>"
) if @patents.length != 0
@patents.each() {|patent|
patent.toHTML(file)
}
# Other
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr><td class='section-filler'></td>" +
"<td class='section-title'>" +
"#{CV::stringToBasicHTML(CV::OTHERS[@language])}</td></tr>"
) if @other.length != 0
@other.each() {|prof|
prof.toHTML(file)
}
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file, "<tr class='padding-tr'></tr>")
CV::HTMLputs(file,"</table>#{@footer}</body>")
file.close()
end
def keywords()
@skills.map() {|skill_type, skill_list|
skill_list.map() {|skill|
skill.content.split(",").map(){|unique_skill|
CV::stringToText(unique_skill).strip().gsub(/\s+/, "-").gsub('/', "-").downcase
}
}
}.flatten().uniq() + [ "cv", "cursus" ]
end
def categories()
categories = [
@firstName.downcase() + "-" + @lastName.downcase(),
@lastName.downcase(),
@title.downcase().gsub(/\s+/, "-"),
]
categories += (professional.map(){|entry| entry.company.gsub(/\s+/, "-").downcase() } +
degrees.map(){|entry| entry.company.gsub(/\s+/, "-").downcase() }).uniq()
return categories
end
def fuzzy_block(categories, keywords, max_depth, prefix="", depth=0, used_keywords=[], &block)
keywords.each(){|keyword|
next if used_keywords.index(keyword) != nil
yield(prefix, keyword)
}
if depth < max_depth then
(categories + keywords).each(){|sub_cat|
next if used_keywords.index(sub_cat) != nil
fuzzy_block(categories, keywords, max_depth,
prefix + "/" + sub_cat,
depth + 1, used_keywords + [sub_cat], &block)
}
end
end
def fuzzy(fuzzy_dir, target, url, max_depth)
keywords=keywords()
categories = categories()
`rm -Rf #{fuzzy_dir}; mkdir #{fuzzy_dir}`
here = Dir.pwd()
Dir.chdir(fuzzy_dir)
categories.each(){|cat|
`ln -s . #{cat}`
}
keywords.each(){|keyword|
`ln -s . #{keyword}`
`ln -s #{target} #{keyword}.html`
}
xml_handle = File.open("sitemap.xml", "w+")
html_handle = File.open("sitemap.html", "w+")
d = Time.new()
xml_handle.puts('<?xml version="1.0" encoding="UTF-8"?>')
xml_handle.puts('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
html_handle.puts("<html><head><title>Sitemap</title></head><body>")
fuzzy_block(categories, keywords, max_depth) {|prefix, keyword|
xml_handle.puts("<url>")
xml_handle.puts("\t<loc>" + url + prefix + "/" + keyword + ".html</loc>")
xml_handle.puts("\t<lastmod>" + d.strftime("%Y-%m-%d") + "</lastmod>")
xml_handle.puts("</url>")
html_handle.puts("<a href=\"" + url + prefix + "/" + keyword + ".html\">" +
(prefix.gsub(/[-\/]/, " ") + " " + keyword).strip() + "</a><br />")
}
xml_handle.puts('</urlset>')
xml_handle.close()
html_handle.puts("</body></html>")
html_handle.close()
Dir.chdir(here)
end
end
class Language
attr_accessor :lang, :level, :more
def initialize()
end
def toTeX(file)
file.puts "\\cvlanguage{#{@lang}}{#{@level}}{#{CV::stringToTeX(@more)}}"
end
def toHTML(file)
CV::HTMLputs(file, "<tr><td class='lang'>#{@lang}</td>\n" +
"<td>#{CV::stringToBasicHTML(@level)}</td>\n" +
"<td></td><td>#{CV::stringToBasicHTML(more)}</td></tr>")
end
end
class Other
attr_accessor :cat, :more
def initialize()
end
def toTeX(file)
file.puts "\\cvline{#{@cat}}{#{CV::stringToTeX(@more)}}"
end
def toHTML(file)
CV::HTMLputs(file, "<tr><td class='entry-other'>#{@cat}</td>\n" +
"<td colspan=3>#{CV::stringToBasicHTML(@more)}</td></tr>")
end
end
class Entry
attr_accessor :date, :title, :company, :city, :country, :details
def initialize()
@details=[]
end
def toTeX(file)
file.printf "\\cventry{#{CV::stringToTeX(@date)}}"+
"{#{CV::stringToTeX(@title)}}{#{@company}}{#{@city}}{#{@country}}{"
if @details.length > 0 then
file.puts "\\begin{itemize}"
@details.each() {|detail|
file.puts "\\item[#{detail != "" ? "-" : ""}]{#{CV::stringToTeX(detail)}}"
}
file.puts "\\end{itemize}"
end
file.puts "}"
end
def toHTML(file)
CV::HTMLputs(file, "<tr><td>#{CV::stringToBasicHTML(@date)}</td>"+
"<td colspan=3><b>#{@title}</b>")
CV::HTMLputs(file, ", <i>#{@company}</i>") if @company != nil
CV::HTMLputs(file, ", #{@city}") if @city != nil
CV::HTMLputs(file, ", #{@country}") if @country != nil
# CV::HTMLputs(file, ".<br />")
@details.each() {|detail|
next if detail == ""
CV::HTMLputs(file, "<li>#{detail}<br />")
}
CV::HTMLputs(file, "</td></tr>")
end
end
class Skill
attr_accessor :type, :content
def initialize()
end
def toTeX(file)
file.puts "{#{CV::stringToTeX(@type)}}{#{CV::stringToTeX(@content)}}"
end
def toHTML(file)
CV::HTMLputs(file, "<td class='skill-name'>#{@type}</td><td>#{@content}</td>")
end
end
class Patent
attr_accessor :reference, :title
def initialize()
end
def toTeX(file)
file.puts "\\cvline{#{@reference}}{#{CV::stringToTeX(@title)}}"
end
def toHTML(file)
CV::HTMLputs(file, "<tr><td class='entry-other'>#{@reference}</td>\n" +
"<td colspan=3>#{CV::stringToBasicHTML(@title)}</td></tr>")
end
end
end