my-last-cv 0.0.1 → 0.0.4

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: f49e3e414740b89f40a22d988bffe9ec9c9358f54ccc01d19de1747fe503d0cd
4
- data.tar.gz: 6a47be333db52a09c3ad418122c18a112e03c03ca5cc61a5f08f5d4ffe8c87ea
3
+ metadata.gz: cf2509574951b9a1befe15309696db3b3dbfd5ce8196fafbd8ec48d2d4ae9d80
4
+ data.tar.gz: f0c6d142419598ce2246156320db87a98062667acd39e8ed30fbc06529745366
5
5
  SHA512:
6
- metadata.gz: d3b054946d412143dc1bfda3521f4b5311915b749c9581dcb9c8dd2e3b7e3500b8768e6945d32c9c931b5f6928d156821babf8f9e5815382bff4379eb5da6fc3
7
- data.tar.gz: e3400653f75dda9d26f61693b78327ed61b30c3e81c406776ff27d4ce6f97ec8d91a84215649a703bacea3a2b41fba82ac61bc5fe379c74f126cd3b1896b7504
6
+ metadata.gz: 32586b06068dcc7b74e3700581634f6bf693108b87181641edf25c69084e1ad42258fd64fee58492a8fd509bf0fc1873a3d4efb5291504383fd508a2857d625a
7
+ data.tar.gz: 7ce669851940b2e5f9c1fdec663eb8d84f90b75da8ef3e927c111d58bd038c55727386e0742b6135dc184c69e09c9f06f9ad5366f9422b3329f1eab9b40c6808
data/README.md CHANGED
@@ -3,7 +3,7 @@ A simple gem to generate beautiful CV from a markdown file
3
3
 
4
4
  ## How to use it?
5
5
  ```bash
6
- gem install bundler
6
+ bundle add my-last-cv
7
7
  bundle install
8
- ruby exe/my_last_cv sample/cv.md output/cv.pdf
8
+ bundle exec my_last_cv sample/cv.md output/cv.pdf
9
9
  ```
data/exe/my_last_cv CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # Script CLI pour utiliser la gem depuis le terminal.
3
- # Usage : my_last_cv input.md output.pdf
2
+
4
3
  require 'bundler/setup'
5
- require_relative '../lib/my_last_cv'
4
+ require 'my_last_cv'
6
5
 
7
6
  if ARGV.length < 2
8
7
  puts "Usage: my_last_cv input.md output.pdf"
@@ -10,5 +9,18 @@ if ARGV.length < 2
10
9
  end
11
10
 
12
11
  input, output = ARGV
13
- MyLastCV.generate(input, output)
12
+
13
+ pro = MyLastCV::Style.new(
14
+ header_font: "Inter",
15
+ header_size: 22,
16
+ section_font: "Inter",
17
+ section_size: 12,
18
+ body_font: "Lora",
19
+ body_size: 10,
20
+ page_options: { margin: 36 },
21
+ accent_color: "1F7AE0" # blue
22
+ )
23
+
24
+ MyLastCV.generate(input, output, style: pro)
25
+
14
26
  puts "CV généré : #{output}"
@@ -13,12 +13,9 @@ module MyLastCV
13
13
  next if ligne.strip.empty?
14
14
  if (m = ligne.match(/^#\s+(.*)/))
15
15
  resultat[:name] = m[1].strip
16
- elsif (m = ligne.match(/^email:\s*(.+)/i))
16
+ elsif (m = ligne.match(/^(email|phone|location):\s*(.+)/i))
17
17
  resultat[:contact] ||= []
18
- resultat[:contact] << m[1].strip
19
- elsif (m = ligne.match(/^location:\s*(.+)/i))
20
- resultat[:contact] ||= []
21
- resultat[:contact] << m[1].strip
18
+ resultat[:contact] << m[2].strip
22
19
  elsif (m = ligne.match(/^##\s+(.*)/))
23
20
  section_actuelle = { title: m[1].strip, items: [] }
24
21
  resultat[:sections] << section_actuelle
@@ -1,4 +1,5 @@
1
1
  require 'prawn'
2
+ require "fileutils"
2
3
 
3
4
  module MyLastCV
4
5
  class Renderer
@@ -8,7 +9,9 @@ module MyLastCV
8
9
  end
9
10
 
10
11
  def to_pdf(output_path)
12
+ FileUtils.mkdir_p(File.dirname(output_path))
11
13
  Prawn::Document.generate(output_path, **@style.page_options) do |pdf|
14
+ register_fonts(pdf)
12
15
  render_header(pdf)
13
16
  render_sections(pdf)
14
17
  end
@@ -16,14 +19,47 @@ module MyLastCV
16
19
 
17
20
  private
18
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
+
34
+ def register_fonts(pdf)
35
+ fonts_dir = resolved_fonts_dir
36
+ return unless fonts_dir
37
+
38
+ # Exemple : Inter (Regular / Bold)
39
+ pdf.font_families.update(
40
+ "Inter" => {
41
+ normal: File.join(fonts_dir, "Inter-Regular.ttf"),
42
+ bold: File.join(fonts_dir, "Inter-Bold.ttf")
43
+ },
44
+ "Lora" => {
45
+ normal: File.join(fonts_dir, "Lora-Regular.ttf"),
46
+ bold: File.join(fonts_dir, "Lora-Bold.ttf")
47
+ }
48
+ )
49
+ end
50
+
19
51
  def render_header(pdf)
20
52
  pdf.font(@style.header_font)
21
53
  pdf.move_down 12
22
- pdf.text(@parsed_cv[:name] || '-', size: @style.header_size, align: :center)
54
+ with_color(pdf, @style.accent_color) do
55
+ pdf.text(@parsed_cv[:name] || '-', size: @style.header_size, align: :center)
56
+ end
23
57
  pdf.move_down 6
24
58
  pdf.font(@style.body_font)
25
59
  pdf.text(@parsed_cv[:contact] || '', size: @style.body_size, align: :center)
26
- pdf.stroke_horizontal_rule
60
+ with_color(pdf, @style.accent_color) do
61
+ pdf.stroke_horizontal_rule
62
+ end
27
63
  pdf.move_down 12
28
64
  end
29
65
 
@@ -39,5 +75,14 @@ module MyLastCV
39
75
  end
40
76
  end
41
77
  end
78
+
79
+ def with_color(pdf, hex)
80
+ return yield if hex.to_s.strip.empty?
81
+ previous = pdf.fill_color
82
+ pdf.fill_color(hex)
83
+ yield
84
+ ensure
85
+ pdf.fill_color(previous) if previous
86
+ end
42
87
  end
43
88
  end
@@ -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.1"
2
+ VERSION = "0.0.4"
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.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Hanicotte
@@ -57,5 +57,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements: []
58
58
  rubygems_version: 3.7.1
59
59
  specification_version: 4
60
- summary: Generate your CV from Mardown to PDF
60
+ summary: Generate your CV from Markdown to PDF
61
61
  test_files: []