class SimpleCV::Layout
Public Class Methods
new(config: @config = config)
click to toggle source
Calls superclass method
# File lib/simple_cv/layout.rb, line 7 def initialize config: @config = config super({ page_size: "A4", info: { Title: @config.title, Author: @config.author, Creator: "AwesomeCV", Producer: "AwesomeCV", CreationDate: Time.now } }) font_families.update "Default" => default_font_files font "Default" stroke_color "000000" main end
Public Instance Methods
contact()
click to toggle source
# File lib/simple_cv/layout.rb, line 60 def contact h2 "contact" contact_table move_down 25 end
education()
click to toggle source
# File lib/simple_cv/layout.rb, line 84 def education h2 "education" @config.education&.each do |elem| h3 elem.subject h4 elem.institution h4 elem.date move_down 14 end end
experience()
click to toggle source
# File lib/simple_cv/layout.rb, line 72 def experience h2 "experience" @config.experience&.each do |elem| h3 elem.job h4 "#{elem.company} - #{elem.location}" h4 elem.date move_down 5 paragaph elem.description move_down 14 end end
job()
click to toggle source
# File lib/simple_cv/layout.rb, line 47 def job h1 @config.profile&.name text @config.profile&.job, style: :normal, size: 11 stroke move_down 25 end
main()
click to toggle source
Main
This builds main layout. Document is diveded in two columns. First column provides personal details and skills, second column show historic experience and education.
# File lib/simple_cv/layout.rb, line 33 def main bounding_box([0, 770], width: 170) do job profile contact skills end bounding_box([200, 770], width: 320) do experience education end end
profile()
click to toggle source
# File lib/simple_cv/layout.rb, line 54 def profile h2 "profile" text @config.profile&.description, style: :normal, size: 10 move_down 25 end
skills()
click to toggle source
# File lib/simple_cv/layout.rb, line 66 def skills h2 "skills" skill_table move_down 25 end
Private Instance Methods
contact_table()
click to toggle source
# File lib/simple_cv/layout.rb, line 139 def contact_table line_width(1) stroke_color "c6c6c6" @config.contact&.each_with_index do |elem, index| icon, value = elem path = path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "icons", "#{icon}.svg") if File.exist?(path) File.open(path, "r") do |icon| svg icon.read, svg_fit(icon.read, 10, 10) end line 20, cursor+10, 20, cursor stroke move_up 10 end text value, style: :normal, size: 9, align: :right, width: 170, leading: 9 if index+1 < @config.contact.count horizontal_line 0, 170, at: cursor+5 stroke end end end
default_font_files()
click to toggle source
Set fonts
Font of document can be customized over config file. TODO: check if file exists, when path given over config file and do proper error handling
# File lib/simple_cv/layout.rb, line 102 def default_font_files { light: @config.font&.light || File.join("lib", "font", "Lato-Light.ttf"), normal: @config.font&.normal || File.join("lib", "font", "Lato-Medium.ttf"), bold: @config.font&.bold || File.join("lib", "font", "Lato-Bold.ttf") } end
h1(title)
click to toggle source
# File lib/simple_cv/layout.rb, line 110 def h1 title text title&.upcase, style: :bold, size: 22, leading: 5 line_width(0.5) stroke_color "000000" horizontal_rule move_down 10 end
h2(title)
click to toggle source
# File lib/simple_cv/layout.rb, line 118 def h2 title text title&.upcase, style: :normal, size: 12, leading: 5 line_width(2) stroke_color "000000" horizontal_rule move_down 15 stroke end
h3(title)
click to toggle source
# File lib/simple_cv/layout.rb, line 127 def h3 title text title, style: :bold, size: 11 end
h4(title)
click to toggle source
# File lib/simple_cv/layout.rb, line 131 def h4 title text title, style: :normal, size: 9 end
paragaph(text)
click to toggle source
# File lib/simple_cv/layout.rb, line 135 def paragaph text text text, style: :normal, size: 9, color: "515151" end
skill_table()
click to toggle source
# File lib/simple_cv/layout.rb, line 167 def skill_table move_down 5 line_width(3) @config.skills&.each do |skill, value| text skill || " ", size: 9, leading: 5 if value stroke_color "c6c6c6" horizontal_line 110, 170, at: cursor+11 stroke stroke_color "000000" horizontal_line 110, 110+(60*value/100), at: cursor+11 stroke end end end
svg_fit(file, width, height)
click to toggle source
Shrink svg images
Helper method to resize given svg images to a specific width and height range.
# File lib/simple_cv/layout.rb, line 190 def svg_fit file, width, height viewBox = file[/(viewBox=)[\-\".0-9 ]*/] return { height: height } unless viewBox metric = viewBox.tr("viewBox=", "").tr("\"", "").split(" ") scale = metric.third.to_i / metric.fourth.to_i if (scale * height) > width { width: width } else { height: height } end end