simple_cv 0.1.0

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.
@@ -0,0 +1,5 @@
1
+ require "simple_cv/version"
2
+ require "simple_cv/basic"
3
+
4
+ module SimpleCV
5
+ end
@@ -0,0 +1,54 @@
1
+ require "simple_cv/layout"
2
+ require "hashugar"
3
+ require "json"
4
+ require "yaml"
5
+
6
+ module SimpleCV
7
+ class Basic
8
+ attr_reader :config
9
+
10
+ def initialize config_path:
11
+ @config = build_struct_tree parse_config_file config_path
12
+ end
13
+
14
+ # Render file
15
+ #
16
+ # With given path and filename, pdf can be rendered to a specific
17
+ # location. If no arguments are given, filename will be set to
18
+ # SimpleCV.pdf and pdf will be rendered to current working dir.
19
+
20
+ def render_file filename: "SimpleCV", path: nil
21
+ output_path = File.join(path || Dir.pwd, "#{filename.chomp('.pdf')}.pdf")
22
+ Layout.new(config: @config).render_file(output_path)
23
+ output_path
24
+ end
25
+
26
+ private
27
+
28
+ # Parse config
29
+ #
30
+ # Currently yml and json files are supported. Will parse file content to hash.
31
+
32
+ def parse_config_file config_path
33
+ File.open(config_path, "r") do |file|
34
+ case File.extname(file).delete(".")
35
+ when "json" then JSON.parse(file.read)
36
+ when "yml" then YAML.load_file(file)
37
+ else
38
+ file.close
39
+ raise LoadError, "Type of file is not supported."
40
+ end
41
+ end
42
+ end
43
+
44
+ # Struct tree
45
+ #
46
+ # Since i prefere to use dot notation to navigate through medium size hashes,
47
+ # parse hash into open structs
48
+
49
+ def build_struct_tree data
50
+ data.to_hashugar
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,205 @@
1
+ require "prawn"
2
+ require "prawn-svg"
3
+
4
+ module SimpleCV
5
+ class Layout < ::Prawn::Document
6
+
7
+ def initialize config:
8
+ @config = config
9
+
10
+ super({
11
+ page_size: "A4",
12
+ info: {
13
+ Title: @config.title,
14
+ Author: @config.author,
15
+ Creator: "AwesomeCV",
16
+ Producer: "AwesomeCV",
17
+ CreationDate: Time.now
18
+ }
19
+ })
20
+
21
+ font_families.update "Default" => default_font_files
22
+ font "Default"
23
+ stroke_color "000000"
24
+ main
25
+ end
26
+
27
+ # Main
28
+ #
29
+ # This builds main layout. Document is diveded in two columns.
30
+ # First column provides personal details and skills, second
31
+ # column show historic experience and education.
32
+
33
+ def main
34
+ bounding_box([0, 770], width: 170) do
35
+ job
36
+ profile
37
+ contact
38
+ skills
39
+ end
40
+
41
+ bounding_box([200, 770], width: 320) do
42
+ experience
43
+ education
44
+ end
45
+ end
46
+
47
+ def job
48
+ h1 @config.profile&.name
49
+ text @config.profile&.job, style: :normal, size: 11
50
+ stroke
51
+ move_down 25
52
+ end
53
+
54
+ def profile
55
+ h2 "profile"
56
+ text @config.profile&.description, style: :normal, size: 10
57
+ move_down 25
58
+ end
59
+
60
+ def contact
61
+ h2 "contact"
62
+ contact_table
63
+ move_down 25
64
+ end
65
+
66
+ def skills
67
+ h2 "skills"
68
+ skill_table
69
+ move_down 25
70
+ end
71
+
72
+ def experience
73
+ h2 "experience"
74
+ @config.experience&.each do |elem|
75
+ h3 elem.job
76
+ h4 "#{elem.company} - #{elem.location}"
77
+ h4 elem.date
78
+ move_down 5
79
+ paragaph elem.description
80
+ move_down 14
81
+ end
82
+ end
83
+
84
+ def education
85
+ h2 "education"
86
+ @config.education&.each do |elem|
87
+ h3 elem.subject
88
+ h4 elem.institution
89
+ h4 elem.date
90
+ move_down 14
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ # Set fonts
97
+ #
98
+ # Font of document can be customized over config file.
99
+ # TODO: check if file exists, when path given over config file and do proper
100
+ # error handling
101
+
102
+ def default_font_files
103
+ {
104
+ light: @config.font&.light || File.join("lib", "font", "Lato-Light.ttf"),
105
+ normal: @config.font&.normal || File.join("lib", "font", "Lato-Medium.ttf"),
106
+ bold: @config.font&.bold || File.join("lib", "font", "Lato-Bold.ttf")
107
+ }
108
+ end
109
+
110
+ def h1 title
111
+ text title&.upcase, style: :bold, size: 22, leading: 5
112
+ line_width(0.5)
113
+ stroke_color "000000"
114
+ horizontal_rule
115
+ move_down 10
116
+ end
117
+
118
+ def h2 title
119
+ text title&.upcase, style: :normal, size: 12, leading: 5
120
+ line_width(2)
121
+ stroke_color "000000"
122
+ horizontal_rule
123
+ move_down 15
124
+ stroke
125
+ end
126
+
127
+ def h3 title
128
+ text title, style: :bold, size: 11
129
+ end
130
+
131
+ def h4 title
132
+ text title, style: :normal, size: 9
133
+ end
134
+
135
+ def paragaph text
136
+ text text, style: :normal, size: 9, color: "515151"
137
+ end
138
+
139
+ def contact_table
140
+ line_width(1)
141
+ stroke_color "c6c6c6"
142
+
143
+ @config.contact&.each_with_index do |elem, index|
144
+ icon, value = elem
145
+
146
+ path = path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "icons", "#{icon}.svg")
147
+ if File.exist?(path)
148
+ File.open(path, "r") do |icon|
149
+ svg icon.read, svg_fit(icon.read, 10, 10)
150
+ end
151
+
152
+ line 20, cursor+10, 20, cursor
153
+ stroke
154
+
155
+ move_up 10
156
+ end
157
+
158
+ text value, style: :normal, size: 9, align: :right, width: 170, leading: 9
159
+
160
+ if index+1 < @config.contact.count
161
+ horizontal_line 0, 170, at: cursor+5
162
+ stroke
163
+ end
164
+ end
165
+ end
166
+
167
+ def skill_table
168
+ move_down 5
169
+ line_width(3)
170
+
171
+ @config.skills&.each do |skill, value|
172
+ text skill || " ", size: 9, leading: 5
173
+
174
+ if value
175
+ stroke_color "c6c6c6"
176
+ horizontal_line 110, 170, at: cursor+11
177
+ stroke
178
+
179
+ stroke_color "000000"
180
+ horizontal_line 110, 110+(60*value/100), at: cursor+11
181
+ stroke
182
+ end
183
+ end
184
+ end
185
+
186
+ # Shrink svg images
187
+ #
188
+ # Helper method to resize given svg images to a specific width and height range.
189
+
190
+ def svg_fit file, width, height
191
+ viewBox = file[/(viewBox=)[\-\".0-9 ]*/]
192
+ return { height: height } unless viewBox
193
+
194
+ metric = viewBox.tr("viewBox=", "").tr("\"", "").split(" ")
195
+ scale = metric.third.to_i / metric.fourth.to_i
196
+
197
+ if (scale * height) > width
198
+ { width: width }
199
+ else
200
+ { height: height }
201
+ end
202
+ end
203
+
204
+ end
205
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleCV
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_cv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_cv"
8
+ spec.version = SimpleCV::VERSION
9
+ spec.authors = ["Frederic Walch"]
10
+ spec.email = ["fredericwalch@me.com"]
11
+
12
+ spec.summary = %q{This Gem helps you to generate a awesome CV!}
13
+ spec.homepage = "https://github.com/freder1c"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "prawn", "2.2.2"
33
+ spec.add_dependency "prawn-svg", "0.27.1"
34
+ spec.add_dependency "hashugar", "1.0.1"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.14"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "pry-nav"
42
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_cv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frederic Walch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: prawn-svg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.27.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.27.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashugar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-nav
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - fredericwalch@me.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - SimleCV.pdf
139
+ - bin/console
140
+ - bin/setup
141
+ - circle.yml
142
+ - examples/example.json
143
+ - examples/example.yml
144
+ - lib/font/Lato-Bold.ttf
145
+ - lib/font/Lato-Light.ttf
146
+ - lib/font/Lato-Medium.ttf
147
+ - lib/font/SIL Open Font License.txt
148
+ - lib/icons/address.svg
149
+ - lib/icons/email.svg
150
+ - lib/icons/phone.svg
151
+ - lib/icons/website.svg
152
+ - lib/simple_cv.rb
153
+ - lib/simple_cv/basic.rb
154
+ - lib/simple_cv/layout.rb
155
+ - lib/simple_cv/version.rb
156
+ - simple_cv.gemspec
157
+ homepage: https://github.com/freder1c
158
+ licenses:
159
+ - MIT
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.6.11
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: This Gem helps you to generate a awesome CV!
181
+ test_files: []