lib/yaml-cv.rb in yaml-cv-0.1.8 vs lib/yaml-cv.rb in yaml-cv-0.1.9
- old
+ new
@@ -35,25 +35,25 @@
end
class CV < Mustache
self.template_file = File.join(File.dirname(__FILE__), "assets/cv.mustache")
-
+
attr_accessor :is_pdf
def initialize(file_path)
@file_path = file_path
@cv = YAML.load_file(file_path)
if @cv["contact"]
@cv["contact"] = @cv["contact"].map { |c|
- c["icon"] = icon(c["icon"])
+ c["icon_svg"] = icon(c["icon"])
c
}
end
end
-
+
def details
@cv["details"]
end
def profile
@@ -63,11 +63,27 @@
def has_profile
@cv.key?("profile")
end
def skills
- @cv["skills"]
+ # split into an n-column table
+ nskills = @cv["skills"]["fields"].length()
+ ncols = @cv["skills"]["columns"]
+ nrows = (nskills / ncols).ceil
+
+ skills_table = Array.new(nrows){Array.new(ncols)}
+
+ i = 0
+ while i < nskills
+
+ col = i % ncols
+ row = i / nrows
+ skills_table[row][col] = @cv["skills"]["fields"][i]
+
+ i = i + 1
+ end
+ skills_table
end
def has_skills
@cv.key?("skills")
end
@@ -88,63 +104,64 @@
@cv["sections"].map { |s|
s["items"] = format_subsections s["items"]
s
}
end
-
+
def full_name
details["last_name"] + " " + details["first_name"]
end
-
+
def css
load_asset("style.css")
end
-
+
def pdf_css
load_asset("pdf.css")
end
def enable_pdf(enable = true)
@is_pdf = true
end
def contact
- @cv["contact"]
- end
+ # split into a 2-column table
+ contact_table = Array.new(3){Array.new(2)}
- def contact_padding
- if !contact
- return 0
- end
+ i = 0
+ while i < @cv["contact"].length()
- columns = (contact.length / 3.0).ceil
- padding = (1 - columns) * 3
+ row = i % 3
+ col = 1 - (i / 3)
+ contact_table[row][col] = @cv["contact"][i]
- Array.new(padding) { |i| 0 }
+ i = i + 1
+ end
+ contact_table
end
def icon(name)
load_asset("icons/#{name.strip}.svg")
end
def format_subsections(subsections)
if !subsections
return
end
-
+
subsections.map { |e|
if e["from"]
e["from"] = format_period e["from"]
end
if e["to"]
e["to"] = format_period e["to"]
end
-
+
if e["logo"]
e["logo_img"] = read_image e["logo"]
end
-
+
e
}
end
def read_image(img_path)
@@ -184,10 +201,10 @@
system("wkhtmltopdf #{temp_file.path} #{file_path}")
temp_file.close
end
-
+
end
def is_windows
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
\ No newline at end of file