Class: SimpleCV::Layout

Inherits:
Prawn::Document
  • Object
show all
Defined in:
lib/simple_cv/layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Layout

Returns a new instance of Layout.



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
# File 'lib/simple_cv/layout.rb', line 9

def initialize(config = {})
  @config = config

  @black = "000000"
  @dark_gray = "6c6c6c"
  @light_gray = "A2A2A2"

  super({
    page_size: "A4",
    info: {
      Title: config["title"],
      Author: config["author"],
      Creator: config["author"],
      Producer: config["author"],
      CreationDate: Time.now
    }
  })

  font_families.update "Default" => default_font_files
  font "Default"
  stroke_color "000000"
  main

  if page_count > 1
    options = { start_count_at: 1, at: [0, -10], size: 7, style: :light, color: light_gray, align: :right }
    number_pages("Page <page> of <total>", options)
  end
end

Instance Attribute Details

#blackObject (readonly)

Returns the value of attribute black.



7
8
9
# File 'lib/simple_cv/layout.rb', line 7

def black
  @black
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/simple_cv/layout.rb', line 7

def config
  @config
end

#dark_grayObject (readonly)

Returns the value of attribute dark_gray.



7
8
9
# File 'lib/simple_cv/layout.rb', line 7

def dark_gray
  @dark_gray
end

#light_grayObject (readonly)

Returns the value of attribute light_gray.



7
8
9
# File 'lib/simple_cv/layout.rb', line 7

def light_gray
  @light_gray
end

Instance Method Details

#certificationObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/simple_cv/layout.rb', line 158

def certification
  h2("certification")
  last_cursor = start_cursor = cursor

  config["certification"]&.each do |elem|
    bounding_box([15, cursor], width: 523) do
      text(elem["subject"], size: 9)
      text(elem["institution"], size: 9, style: :light)
      text(elem["date"], size: 7.5, color: dark_gray, style: :light)
      move_down(20)
    end

    stroke_color(black)
    line_width(3)
    line([2, start_cursor], [2, cursor + 20])
    stroke
  end
end

#educationObject



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
# File 'lib/simple_cv/layout.rb', line 132

def education
  h2("education")
  start_cursor = cursor

  config["education"]&.each_with_index do |elem, index|
    bounding_box([12 + (index * 180), start_cursor], width: 180) do
      text(elem["subject"], size: 9)
      text(elem["institution"], size: 9, style: :light)
      text(elem["date"], size: 7.5, color: dark_gray, style: :light)
      move_down(10)
    end

    stroke_color(black)
    line_width(3)
    line([index * 180, start_cursor], [index * 180, cursor + 10])
    stroke
  end

  move_down(20)
  stroke_color(light_gray)
  line_width(0.5)
  line([0, cursor], [523, cursor])
  stroke
  move_down(20)
end

#experienceObject



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
# File 'lib/simple_cv/layout.rb', line 89

def experience
  h2("work experience")
  last_cursor = start_cursor = cursor

  config["experience"]&.each do |elem|
    bounding_box([0, last_cursor], width: 523) do
      bounding_box([15, 0], width: 165) do
        fill_color(light_gray)
        stroke_color("ffffff")
        text_box("", at: [-19, cursor+2], size: 13, color: light_gray, mode: :fill_stroke)
        fill_color(black)
        text(elem["company"], size: 9, style: :light)
        text(elem["date"], size: 7.5, color: dark_gray, style: :light)
      end

      bounding_box([180, bounds.top], width: 353, background_color: light_gray) do
        text(elem["job"], size: 9, leading: 7)

        elem["description_list"]&.each do |item|
          text_box("", at: [0, cursor], size: 8, color: dark_gray)
          indent(10) { text(item, size: 8, color: dark_gray, style: :light) }
        end

        move_down(10)
        last_cursor -= bounds.top
      end
    end
  end

  end_cursor = cursor
  stroke_color(light_gray)
  line_width(0.5)
  line([0, start_cursor + 5], [0, end_cursor + 10])
  stroke

  move_down(10)
  stroke_color(light_gray)
  line_width(0.5)
  line([0, cursor], [523, cursor])
  stroke
  move_down(20)
end

#headerObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/simple_cv/layout.rb', line 49

def header
  text(config.dig("profile", "name")&.upcase, size: 20, leading: 3, character_spacing: 1.9)
  move_down(2)
  text(config.dig("profile", "job")&.upcase, style: :light, size: 12, leading: 3, character_spacing: 1.9, color: dark_gray)
  move_down(10)
  stroke_color(black)
  line_width(1)
  line([0, cursor], [523, cursor])
  stroke

  line_pointer = 770
  text_box(config.dig("contact", "address"), size: 8, at: [240, line_pointer], align: :right, style: :light)

  fill_color(dark_gray)

  config["contact"]&.each do |k,v|
    line_pointer -= 10
    text_box("<color rgb='#{black}'>#{k.capitalize}:</color> #{v}", size: 8, at: [240, line_pointer], align: :right, inline_format: true, style: :light)
  end

  fill_color(black)
  move_down(20)
end

#introObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/simple_cv/layout.rb', line 73

def intro
  text_box(DateTime.now.strftime("%d.%m.%Y"), at: [0, cursor], align: :right, size: 7)
  text(config.dig("intro", "receiver", "name")&.upcase, size: 7, color: black)
  text(config.dig("intro", "receiver", "position")&.upcase, size: 7, color: dark_gray)

  move_down(30)
  text(config.dig("intro", "text"), size: 9, color: dark_gray, style: :light)

  # move_down(20)
  # stroke_color(light_gray)
  # line_width(0.5)
  # line([0, cursor], [523, cursor])
  # stroke
  # move_down(30)
end

#mainObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/simple_cv/layout.rb', line 38

def main
  header
  if config["intro"]
    intro
    start_new_page
  end
  experience
  education
  certification
end