my-last-cv 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f49e3e414740b89f40a22d988bffe9ec9c9358f54ccc01d19de1747fe503d0cd
4
+ data.tar.gz: 6a47be333db52a09c3ad418122c18a112e03c03ca5cc61a5f08f5d4ffe8c87ea
5
+ SHA512:
6
+ metadata.gz: d3b054946d412143dc1bfda3521f4b5311915b749c9581dcb9c8dd2e3b7e3500b8768e6945d32c9c931b5f6928d156821babf8f9e5815382bff4379eb5da6fc3
7
+ data.tar.gz: e3400653f75dda9d26f61693b78327ed61b30c3e81c406776ff27d4ce6f97ec8d91a84215649a703bacea3a2b41fba82ac61bc5fe379c74f126cd3b1896b7504
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # my-last-cv
2
+ A simple gem to generate beautiful CV from a markdown file
3
+
4
+ ## How to use it?
5
+ ```bash
6
+ gem install bundler
7
+ bundle install
8
+ ruby exe/my_last_cv sample/cv.md output/cv.pdf
9
+ ```
data/exe/my_last_cv ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # Script CLI pour utiliser la gem depuis le terminal.
3
+ # Usage : my_last_cv input.md output.pdf
4
+ require 'bundler/setup'
5
+ require_relative '../lib/my_last_cv'
6
+
7
+ if ARGV.length < 2
8
+ puts "Usage: my_last_cv input.md output.pdf"
9
+ exit 1
10
+ end
11
+
12
+ input, output = ARGV
13
+ MyLastCV.generate(input, output)
14
+ puts "CV généré : #{output}"
@@ -0,0 +1,36 @@
1
+ module MyLastCV
2
+ class Parser
3
+ def initialize(markdown)
4
+ @markdown = markdown
5
+ end
6
+
7
+ def parse
8
+ lignes = @markdown.lines.map(&:chomp)
9
+ resultat = { sections: [] }
10
+ section_actuelle = nil
11
+
12
+ lignes.each do |ligne|
13
+ next if ligne.strip.empty?
14
+ if (m = ligne.match(/^#\s+(.*)/))
15
+ resultat[:name] = m[1].strip
16
+ elsif (m = ligne.match(/^email:\s*(.+)/i))
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
22
+ elsif (m = ligne.match(/^##\s+(.*)/))
23
+ section_actuelle = { title: m[1].strip, items: [] }
24
+ resultat[:sections] << section_actuelle
25
+ elsif (m = ligne.match(/^[-*]\s+(.*)/))
26
+ section_actuelle ||= { title: "Divers", items: [] }
27
+ resultat[:sections] << section_actuelle unless resultat[:sections].include?(section_actuelle)
28
+ section_actuelle[:items] << m[1].strip
29
+ end
30
+ end
31
+
32
+ resultat[:contact] = (resultat[:contact] || []).join(" · ")
33
+ resultat
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ require 'prawn'
2
+
3
+ module MyLastCV
4
+ class Renderer
5
+ def initialize(parsed_cv, style: Style.new)
6
+ @parsed_cv = parsed_cv
7
+ @style = style
8
+ end
9
+
10
+ def to_pdf(output_path)
11
+ Prawn::Document.generate(output_path, **@style.page_options) do |pdf|
12
+ render_header(pdf)
13
+ render_sections(pdf)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def render_header(pdf)
20
+ pdf.font(@style.header_font)
21
+ pdf.move_down 12
22
+ pdf.text(@parsed_cv[:name] || '-', size: @style.header_size, align: :center)
23
+ pdf.move_down 6
24
+ pdf.font(@style.body_font)
25
+ pdf.text(@parsed_cv[:contact] || '', size: @style.body_size, align: :center)
26
+ pdf.stroke_horizontal_rule
27
+ pdf.move_down 12
28
+ end
29
+
30
+ def render_sections(pdf)
31
+ @parsed_cv[:sections].each do |section|
32
+ pdf.move_down 8
33
+ pdf.font(@style.section_font)
34
+ pdf.text(section[:title], size: @style.section_size, style: :bold)
35
+ pdf.move_down 4
36
+ pdf.font(@style.body_font)
37
+ section[:items].each do |item|
38
+ pdf.text("• #{item}", size: @style.body_size, indent_paragraphs: 16)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ module MyLastCV
2
+ class Style
3
+ attr_reader :header_font, :header_size, :section_font, :section_size, :body_font, :body_size, :page_options, :accent_color
4
+
5
+ def initialize(opts = {})
6
+ @header_font = opts[:header_font] || 'Helvetica'
7
+ @header_size = opts[:header_size] || 18
8
+ @section_font = opts[:section_font] || 'Helvetica'
9
+ @section_size = opts[:section_size] || 12
10
+ @body_font = opts[:body_font] || 'Helvetica'
11
+ @body_size = opts[:body_size] || 10
12
+ @page_options = opts[:page_options] || { margin: 48 }
13
+ @accent_color = opts[:accent_color] || '000000'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module MyLastCV
2
+ VERSION = "0.0.1"
3
+ end
data/lib/my_last_cv.rb ADDED
@@ -0,0 +1,12 @@
1
+ require_relative 'my_last_cv/version'
2
+ require_relative 'my_last_cv/parser'
3
+ require_relative 'my_last_cv/style'
4
+ require_relative 'my_last_cv/renderer'
5
+
6
+ module MyLastCV
7
+ def self.generate(input_path, output_path, style: Style.new)
8
+ md = File.read(input_path)
9
+ parsed = Parser.new(md).parse
10
+ Renderer.new(parsed, style: style).to_pdf(output_path)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my-last-cv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxime Hanicotte
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: prawn
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.5'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.5'
26
+ email:
27
+ - max_hanicotte@msn.com
28
+ executables:
29
+ - my_last_cv
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - exe/my_last_cv
35
+ - lib/my_last_cv.rb
36
+ - lib/my_last_cv/parser.rb
37
+ - lib/my_last_cv/renderer.rb
38
+ - lib/my_last_cv/style.rb
39
+ - lib/my_last_cv/version.rb
40
+ homepage: https://www.maxime.hanicotte.net/my-last-cv/
41
+ licenses:
42
+ - GPL-3.0-or-later
43
+ metadata: {}
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '3.0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.7.1
59
+ specification_version: 4
60
+ summary: Generate your CV from Mardown to PDF
61
+ test_files: []