philomath 0.0.1 → 0.0.3

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: bb70795a33712bfa57b1199014c8c8e47db6b01939a20b2076f8893f687cf126
4
- data.tar.gz: 97dace31e67170cd2c76e5618be7263df4a57e9ff6c02bd8632cd99587164685
3
+ metadata.gz: cd7b0c304a0ed0306aba4660fb0ee17cff27b671b8fe2606c8a41c0acf36e46c
4
+ data.tar.gz: 401b25956693d11eaa2a4337b86ec5dea2849b7b08f6b04970b59b15bddbbda6
5
5
  SHA512:
6
- metadata.gz: a416eceddfbf958bc994dd221e9844bc4886f65bea2da18553a74d786c364b061860ad72fce0c345f78d85a6f15d2dd7327e678df50c3517806517837c19b048
7
- data.tar.gz: afa5784f2b3c04aee3dd1f4cc4a0b1f2aec86a22ac6f73d18bdca7a4247fa6680a0145d40cd0d0b51210ec9c4f516e012f4fd45040968f6dc9af5d96d120ed24
6
+ metadata.gz: fcdf66b21e981a86592f0482bd47a1185b2166b3f40e1db3d3c767b2e2f32e45a14eaf524a801d95946e7a708fa52a1adc9a48bc97360e44097b44d3f1f257f9
7
+ data.tar.gz: defe87eb60a168985730e4e79f292349da7dd7dda365f80826760f2aae32ec6aa867a4c21e59f79b5048e67250a3c5113f6785f14f5f1e7ffadd4b8f13668b8f
@@ -3,7 +3,7 @@ module Philomath
3
3
  module_function
4
4
 
5
5
  def to_s
6
- "0.0.1"
6
+ "0.0.3"
7
7
  end
8
8
  end
9
9
  end
data/lib/philomath.rb CHANGED
@@ -2,6 +2,7 @@ require 'markdownlyze'
2
2
  require 'prawn'
3
3
  require 'prawn_components'
4
4
  require 'nokogiri'
5
+ require 'open-uri'
5
6
 
6
7
  require_relative 'philomath/rendering/render_code_inline'
7
8
  require_relative 'philomath/rendering/render_styled_link'
@@ -10,7 +11,7 @@ require_relative 'philomath/rendering/render_callback'
10
11
 
11
12
  module Philomath
12
13
  class << self
13
- def render(chapters:)
14
+ def render(chapters:, output_path: nil)
14
15
  table_of_contents = {}
15
16
  contents = {}
16
17
  pdf_chapters = []
@@ -21,9 +22,11 @@ module Philomath
21
22
  pdf.font('Inter')
22
23
 
23
24
  chapters.each do |chapter|
25
+ content = chapter.key?(:content) ? chapter[:content] : File.read(chapter.fetch(:file_path))
24
26
  pdf_chapters << {
25
27
  name: chapter[:name],
26
- parsed_elements: Markdownlyze.parse(chapter[:content])
28
+ path_to_chapter: File.dirname(chapter[:file_path]),
29
+ parsed_elements: Markdownlyze.parse(content)
27
30
  }
28
31
  end
29
32
 
@@ -42,30 +45,39 @@ module Philomath
42
45
  chapter_elements.each do |node|
43
46
  case node[:element]
44
47
  when :h1
45
- pdf.public_send("h1", node[:value], callback: callback)
48
+ pdf.h1(node[:value], callback: callback)
46
49
  when :h2
47
50
  table_of_contents[chapter_conf[:name]][:headings][node[:value]] = pdf.page_number
48
- pdf.public_send("h2", node[:value], callback: callback)
51
+ pdf.h2(node[:value], callback: callback)
49
52
  when :h3
50
- pdf.public_send("h3", node[:value], callback: callback)
53
+ pdf.h3(node[:value], callback: callback)
51
54
  when :h4
52
- pdf.public_send("h4", node[:value], callback: callback)
55
+ pdf.h4(node[:value], callback: callback)
53
56
  when :paragraph
54
- pdf.public_send("paragraph", callback.call(node[:value]))
57
+ pdf.paragraph(callback.call(node[:value]))
55
58
  when :code_block
56
- pdf.public_send("code_block", node[:value], node[:language])
59
+ pdf.code_block(node[:value], node[:language])
57
60
  when :blank_line
58
61
  pdf.move_down(3)
59
62
  when :ol
60
- pdf.public_send("ol", node[:value], callback: callback)
63
+ pdf.ol(node[:value], callback: callback)
61
64
  when :ul
62
- pdf.public_send("ul", node[:value], callback: callback)
65
+ pdf.ul(node[:value], callback: callback)
66
+ when :remote_image
67
+ pdf.move_down(6)
68
+ pdf.image(URI.open(node[:value]), position: :center, width: pdf.bounds.width - 25)
69
+ pdf.move_down(6)
63
70
  when :image
64
71
  pdf.move_down(6)
65
- pdf.image(chapter.images[node[:value]], position: :center, width: pdf.bounds.width - 25)
72
+
73
+ chapter_path = chapter_conf[:path_to_chapter]
74
+ path_to_image = node[:value]
75
+ image_absolute_path = File.join(chapter_path, path_to_image.sub(/^\.\//, ''))
76
+ pdf.image(image_absolute_path, position: :center, width: pdf.bounds.width - 25)
77
+
66
78
  pdf.move_down(6)
67
79
  when :quote
68
- pdf.public_send("quote", node[:value], callback: callback)
80
+ pdf.quote(node[:value], callback: callback)
69
81
  pdf.move_down(6)
70
82
  end
71
83
  end
@@ -77,10 +89,10 @@ module Philomath
77
89
 
78
90
  pdf.go_to_page(toc_page)
79
91
 
80
- pdf.public_send("h1", 'Table of contents')
92
+ pdf.h1('Table of contents')
81
93
  pdf.move_down(50)
82
94
 
83
- pdf.public_send("table_of_contents", table_of_contents)
95
+ pdf.table_of_contents(table_of_contents)
84
96
 
85
97
  # Generate clickable table of contents
86
98
  pdf.outline.define do |outline|
@@ -107,7 +119,11 @@ module Philomath
107
119
 
108
120
  pdf.number_pages('<page>', options)
109
121
 
110
- pdf.render
122
+ if output_path
123
+ pdf.render_file(output_path)
124
+ else
125
+ pdf.render
126
+ end
111
127
  end
112
128
 
113
129
  private
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philomath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
10
  date: 2024-11-17 00:00:00.000000000 Z
@@ -30,28 +29,28 @@ dependencies:
30
29
  requirements:
31
30
  - - '='
32
31
  - !ruby/object:Gem::Version
33
- version: 0.0.2
32
+ version: 0.0.3
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - '='
39
38
  - !ruby/object:Gem::Version
40
- version: 0.0.2
39
+ version: 0.0.3
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: prawn_components
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - '='
46
45
  - !ruby/object:Gem::Version
47
- version: 0.0.1
46
+ version: 0.0.2
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - '='
53
52
  - !ruby/object:Gem::Version
54
- version: 0.0.1
53
+ version: 0.0.2
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: prawn
57
56
  requirement: !ruby/object:Gem::Requirement
@@ -92,10 +91,8 @@ files:
92
91
  - lib/philomath/rendering/render_styled_link.rb
93
92
  - lib/philomath/rendering/render_without_entities.rb
94
93
  - lib/philomath/version.rb
95
- homepage:
96
94
  licenses: []
97
95
  metadata: {}
98
- post_install_message:
99
96
  rdoc_options: []
100
97
  require_paths:
101
98
  - lib
@@ -110,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
107
  - !ruby/object:Gem::Version
111
108
  version: '0'
112
109
  requirements: []
113
- rubygems_version: 3.4.10
114
- signing_key:
110
+ rubygems_version: 3.6.2
115
111
  specification_version: 4
116
112
  summary: Turn markdown files into PDF book
117
113
  test_files: []