my-last-cv 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50dc7597459a46e9b9e4dc05be3ce0ad29d79f1aa8827a9286ec06b7f3c14059
4
- data.tar.gz: df0e733de4e2e514915013766daf2f2f7cf66fb6066ef7ce045b29e0a732ab98
3
+ metadata.gz: 94c3e91fc809c66ce9bff0a797dbc4701562502617080a3dfc1980ff72d6d7a8
4
+ data.tar.gz: 0d92a8897223468db3de303b7a23e312873cc2da76d3b0976e2f642e7863e442
5
5
  SHA512:
6
- metadata.gz: b0464ac5ece152ff7a35f63d4ab4faa4701b72af57e6283bc0164301501cd331b129bcd12d43e26daccfe4f89ef10dceb71848acd7cab786e329d70443548af2
7
- data.tar.gz: b1b9b1b1faa7088385b903f0f2f02012c78813265d25a2e8c573cfc74a88a9a7d556e7a09a4bb3c30c233e47fb22067a51dfc73b3869cc7733de800a23515849
6
+ metadata.gz: cdfc99a9a7ae9d9145c643df109dedb8f9c02860e1d2d92c859a4d28a55a82bb8aff49e5d1fd478683b1e8d98f952d43d88a243749c12691f39a31489c000c4d
7
+ data.tar.gz: b8970a939e5ff4f47640dc3021cb743e4794e58a96d41db4c74ce4ed75949cc4481fd274d7b9a708a2c3badb8d257fe5982308f7b3fa931b1329cfb9d260fb20
data/README.md CHANGED
@@ -7,3 +7,8 @@ bundle add my-last-cv
7
7
  bundle install
8
8
  bundle exec my_last_cv sample/cv.md output/cv.pdf
9
9
  ```
10
+
11
+ ## Custom fonts
12
+ By default, the gem looks for fonts in `./fonts` of the calling project.
13
+ You can override this with `Style.new(fonts_dir: "/path/to/fonts")`
14
+ or `MY_LAST_CV_FONTS_DIR=/path/to/fonts`.
@@ -8,21 +8,50 @@ module MyLastCV
8
8
  lignes = @markdown.lines.map(&:chomp)
9
9
  resultat = { sections: [] }
10
10
  section_actuelle = nil
11
+ element_actuel = nil
11
12
 
12
13
  lignes.each do |ligne|
13
- next if ligne.strip.empty?
14
- if (m = ligne.match(/^#\s+(.*)/))
14
+ line = ligne
15
+ next if line.strip.empty?
16
+
17
+ if (m = line.match(/^#\s+(.*)/))
15
18
  resultat[:name] = m[1].strip
16
- elsif (m = ligne.match(/^(email|phone|location):\s*(.+)/i))
17
- resultat[:contact] ||= []
18
- resultat[:contact] << m[2].strip
19
- elsif (m = ligne.match(/^##\s+(.*)/))
20
- section_actuelle = { title: m[1].strip, items: [] }
19
+ section_actuelle = nil
20
+ element_actuel = nil
21
+
22
+ elsif (m = line.match(/^(email|phone|location):\s*(.+)/i))
23
+ (resultat[:contact] ||= []) << m[2].strip
24
+
25
+ elsif (m = line.match(/^##\s+(.*)/))
26
+ section_actuelle = { title: m[1].strip, items: [], elements: [] }
21
27
  resultat[:sections] << section_actuelle
22
- elsif (m = ligne.match(/^[-*]\s+(.*)/))
23
- section_actuelle ||= { title: "Divers", items: [] }
28
+ element_actuel = nil
29
+
30
+ elsif (m = line.match(/^###\s+(.*)/))
31
+ section_actuelle ||= { title: "Divers", items: [], elements: [] }
24
32
  resultat[:sections] << section_actuelle unless resultat[:sections].include?(section_actuelle)
25
- section_actuelle[:items] << m[1].strip
33
+
34
+ element_actuel = { title: m[1].strip, items: [] }
35
+ section_actuelle[:elements] ||= []
36
+ section_actuelle[:elements] << element_actuel
37
+
38
+ elsif (m = line.match(/^[-*]\s+(.*)/))
39
+ if element_actuel
40
+ element_actuel[:items] << m[1].strip
41
+ else
42
+ section_actuelle ||= { title: "Divers", items: [], elements: [] }
43
+ resultat[:sections] << section_actuelle unless resultat[:sections].include?(section_actuelle)
44
+ section_actuelle[:items] << m[1].strip
45
+ end
46
+ else
47
+ if element_actuel && !element_actuel[:items].empty?
48
+ element_actuel[:items][-1] += " " + line.strip
49
+ elsif section_actuelle && !section_actuelle[:items].empty?
50
+ section_actuelle[:items][-1] += " " + line.strip
51
+ else
52
+ section_actuelle ||= { title: "Divers", items: [], elements: [] }
53
+ section_actuelle[:items] << line.strip
54
+ end
26
55
  end
27
56
  end
28
57
 
@@ -19,9 +19,21 @@ module MyLastCV
19
19
 
20
20
  private
21
21
 
22
+ def resolved_fonts_dir
23
+ candidates = []
24
+ candidates << @style.fonts_dir if @style.fonts_dir
25
+ candidates << ENV["MY_LAST_CV_FONTS_DIR"] if ENV["MY_LAST_CV_FONTS_DIR"]
26
+ candidates << File.join(Dir.pwd, "fonts")
27
+
28
+ # fallback if no fonts_dir specified
29
+ candidates << File.expand_path("../../fonts", __dir__)
30
+
31
+ candidates.find { |p| p && Dir.exist?(p) }
32
+ end
33
+
22
34
  def register_fonts(pdf)
23
- fonts_dir = File.expand_path("../../fonts", __dir__)
24
- return unless Dir.exist?(fonts_dir)
35
+ fonts_dir = resolved_fonts_dir
36
+ return unless fonts_dir
25
37
 
26
38
  # Exemple : Inter (Regular / Bold)
27
39
  pdf.font_families.update(
@@ -56,14 +68,30 @@ module MyLastCV
56
68
  pdf.move_down 8
57
69
  pdf.font(@style.section_font)
58
70
  pdf.text(section[:title], size: @style.section_size, style: :bold)
59
- pdf.move_down 4
60
- pdf.font(@style.body_font)
61
- section[:items].each do |item|
62
- pdf.text("• #{item}", size: @style.body_size, indent_paragraphs: 16)
71
+
72
+ unless section[:items].nil? || section[:items].empty?
73
+ pdf.move_down 4
74
+ pdf.font(@style.body_font)
75
+ section[:items].each do |item|
76
+ pdf.text("• #{item}", size: @style.body_size, indent_paragraphs: 16)
77
+ end
78
+ end
79
+
80
+ (section[:elements] || []).each do |el|
81
+ pdf.move_down 6
82
+ pdf.font(@style.section_font)
83
+ pdf.text(el[:title], size: (@style.section_size - 3), style: :bold)
84
+
85
+ pdf.move_down 2
86
+ pdf.font(@style.body_font)
87
+ (el[:items] || []).each do |item|
88
+ pdf.text("• #{item}", size: @style.body_size, indent_paragraphs: 20)
89
+ end
63
90
  end
64
91
  end
65
92
  end
66
93
 
94
+
67
95
  def with_color(pdf, hex)
68
96
  return yield if hex.to_s.strip.empty?
69
97
  previous = pdf.fill_color
@@ -1,6 +1,6 @@
1
1
  module MyLastCV
2
2
  class Style
3
- attr_reader :header_font, :header_size, :section_font, :section_size, :body_font, :body_size, :page_options, :accent_color
3
+ attr_reader :header_font, :header_size, :section_font, :section_size, :body_font, :body_size, :page_options, :accent_color, :fonts_dir
4
4
 
5
5
  def initialize(opts = {})
6
6
  @header_font = opts[:header_font] || 'Helvetica'
@@ -11,6 +11,7 @@ module MyLastCV
11
11
  @body_size = opts[:body_size] || 10
12
12
  @page_options = opts[:page_options] || { margin: 48 }
13
13
  @accent_color = opts[:accent_color] || '000000'
14
+ @fonts_dir = opts[:fonts_dir] # optional
14
15
  end
15
16
  end
16
17
  end
@@ -1,3 +1,3 @@
1
1
  module MyLastCV
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my-last-cv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Hanicotte