kamisaku 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c810e820b25f0105dcd4bda49ea0de6aa29a9d802079105fc6ee8b6f055d39e5
4
- data.tar.gz: 63a00b823e8881454a73a660f4e74b0c467c0cf2e1cdc49af37bff7ec70221a5
3
+ metadata.gz: c3ec65c8d7b635ea047a547d4fdf3a90ef1e4ddaa2b271b2178e8b2bdf9bca0f
4
+ data.tar.gz: c6fada80efb1876043306bc9c38842e627f5ee32a7ca18f1a3c97a1f1490a954
5
5
  SHA512:
6
- metadata.gz: d0a4b2ff2d49eeafaaae02f00a7d7765ffd0958eca484047deea258b06e3a914ac5a9dc66bc590b564b2296874c4ee3706a5e3acd8ddca98cb1c5a4a94c7c2bc
7
- data.tar.gz: 16afe349ee8f3696d08eca40f98241a5d05f6e647790fb9596c6b1eaf42d4597ace2cd42c3383658fbe39ebbbc6dc6a937a669b5e9c2dbc1f14bd4089e6acb88
6
+ metadata.gz: ea270d4a7e392a32ffb83fbe87a9f31ba483b1827f99f52547278875f92f87989b629dd901e4047d31f288cafeac8f722a6534ac1d88858cd6e9b3f6e06c055a
7
+ data.tar.gz: '0877a0d602fe76e39cd955bd71557355d273b4d6f45b6bafd519757b1478d635da1c3c78e67488e1aa3cd23898d7eb3297f55870c328c811f506675847ca2c63'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamisaku (0.2.1)
4
+ kamisaku (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,63 @@
1
+ module Kamisaku
2
+ class PDF
3
+ attr_reader :yaml_content, :pdf_location, :html_location, :cv_data, :template
4
+
5
+ def initialize(yaml_content:, pdf_location:, html_location: nil, template: nil)
6
+ @yaml_content = yaml_content
7
+ @cv_data = CvData.new(YAML.load(yaml_content))
8
+ @pdf_location = pdf_location
9
+ @html_location = html_location
10
+ @template = template || "sleek"
11
+ end
12
+
13
+ def create
14
+ generated_html_file do |file_path|
15
+ FileUtils.cp(file_path, html_location) if html_location
16
+ html_file_to_pdf_file(file_path, pdf_location)
17
+ soft_remove_metadata_from_pdf_file(pdf_location)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def html_file_to_pdf_file(html_file_path, pdf_file_path)
24
+ # Convert the HTML file to a PDF using Google Chrome in headless mode
25
+ pdf_conversion_command = <<~CMD
26
+ google-chrome --headless --disable-gpu --run-all-compositor-stages-before-draw \
27
+ --print-to-pdf=#{pdf_file_path} --no-pdf-header-footer \
28
+ #{html_file_path}
29
+ CMD
30
+
31
+ system(pdf_conversion_command)
32
+ raise "PDF generation failed" unless File.exist?(pdf_file_path)
33
+ end
34
+
35
+ def soft_remove_metadata_from_pdf_file(file_path)
36
+ command = <<~CMD
37
+ exiftool -all= #{file_path} -overwrite_original
38
+ CMD
39
+ system(command)
40
+ end
41
+
42
+ def generated_html_file
43
+ temp_html_file = Tempfile.new(%w[kamisaku .html])
44
+ temp_html_file.write(cv_html)
45
+ temp_html_file.close
46
+ begin
47
+ yield temp_html_file.path
48
+ ensure
49
+ temp_html_file.unlink
50
+ end
51
+ end
52
+
53
+ def cv_html
54
+ rhtml = ERB.new(template_html)
55
+ rhtml.result(@cv_data.get_bindings)
56
+ end
57
+
58
+ def template_html
59
+ path = File.join(File.dirname(__FILE__), "/../templates/#{template}/template.html.erb")
60
+ File.read(path)
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamisaku
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/kamisaku.rb CHANGED
@@ -11,6 +11,7 @@ require_relative "kamisaku/cv_data"
11
11
  require_relative "kamisaku/meta_file_parser"
12
12
  require_relative "kamisaku/cv_generator"
13
13
  require_relative "kamisaku/arg_parser"
14
+ require_relative "kamisaku/pdf"
14
15
 
15
16
  module Kamisaku
16
17
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamisaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sinaru Gunawardena
@@ -42,6 +42,7 @@ files:
42
42
  - lib/kamisaku/cv_data_sections/skill.rb
43
43
  - lib/kamisaku/cv_generator.rb
44
44
  - lib/kamisaku/meta_file_parser.rb
45
+ - lib/kamisaku/pdf.rb
45
46
  - lib/kamisaku/version.rb
46
47
  - lib/templates/paper/template.html.erb
47
48
  - lib/templates/sleek/template.html.erb