philomath 0.0.2 → 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 +4 -4
- data/lib/philomath/version.rb +1 -1
- data/lib/philomath.rb +22 -3
- metadata +4 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28c65133fd367daf551ae99869c542ec7034413ea2441e6f813c4b83ad3a8ec7
|
4
|
+
data.tar.gz: 23ae381eeef90485353399e4e210a46d2b161ec7868a3cb08b1260f277e4ac65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206707454d206e8f2d4c89aae971e7fa94ff7cd855e3c10977f9cd4a9405e004b0a36e92858f638a4df9b1cc18dde15ce091e7850d90ed7cf965077f5f68d53a
|
7
|
+
data.tar.gz: 3de3389f4d09481a7275922b27f5d814bf59879844f99ae1ea65bcced29899fa6ccca6e89f0e32695fca574c1d82cd8e08b103ba0b8084130bcdf3fa4617c64d
|
data/lib/philomath/version.rb
CHANGED
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:, output_path: nil)
|
14
|
+
def render(chapters:, output_path: nil, cover_image: nil)
|
14
15
|
table_of_contents = {}
|
15
16
|
contents = {}
|
16
17
|
pdf_chapters = []
|
@@ -20,10 +21,19 @@ module Philomath
|
|
20
21
|
PrawnComponents.initialize_fonts(pdf: pdf)
|
21
22
|
pdf.font('Inter')
|
22
23
|
|
24
|
+
unless cover_image.nil?
|
25
|
+
pdf.canvas do
|
26
|
+
pdf.image(cover_image, scale: 0.4, at: pdf.bounds.top_left)
|
27
|
+
end
|
28
|
+
|
29
|
+
pdf.start_new_page
|
30
|
+
end
|
31
|
+
|
23
32
|
chapters.each do |chapter|
|
24
33
|
content = chapter.key?(:content) ? chapter[:content] : File.read(chapter.fetch(:file_path))
|
25
34
|
pdf_chapters << {
|
26
35
|
name: chapter[:name],
|
36
|
+
path_to_chapter: File.dirname(chapter[:file_path]),
|
27
37
|
parsed_elements: Markdownlyze.parse(content)
|
28
38
|
}
|
29
39
|
end
|
@@ -61,9 +71,18 @@ module Philomath
|
|
61
71
|
pdf.ol(node[:value], callback: callback)
|
62
72
|
when :ul
|
63
73
|
pdf.ul(node[:value], callback: callback)
|
74
|
+
when :remote_image
|
75
|
+
pdf.move_down(6)
|
76
|
+
pdf.image(URI.open(node[:value]), position: :center, width: pdf.bounds.width - 25)
|
77
|
+
pdf.move_down(6)
|
64
78
|
when :image
|
65
79
|
pdf.move_down(6)
|
66
|
-
|
80
|
+
|
81
|
+
chapter_path = chapter_conf[:path_to_chapter]
|
82
|
+
path_to_image = node[:value]
|
83
|
+
image_absolute_path = File.join(chapter_path, path_to_image.sub(/^\.\//, ''))
|
84
|
+
pdf.image(image_absolute_path, position: :center, width: pdf.bounds.width - 25)
|
85
|
+
|
67
86
|
pdf.move_down(6)
|
68
87
|
when :quote
|
69
88
|
pdf.quote(node[:value], callback: callback)
|
@@ -74,7 +93,7 @@ module Philomath
|
|
74
93
|
pdf.start_new_page unless chapter_conf_i == pdf_chapters.size - 1
|
75
94
|
end
|
76
95
|
|
77
|
-
toc_page = 1
|
96
|
+
toc_page = cover_image.nil? ? 1 : 2
|
78
97
|
|
79
98
|
pdf.go_to_page(toc_page)
|
80
99
|
|
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.
|
4
|
+
version: 0.0.4
|
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,14 +29,14 @@ dependencies:
|
|
30
29
|
requirements:
|
31
30
|
- - '='
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
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.
|
39
|
+
version: 0.0.3
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
41
|
name: prawn_components
|
43
42
|
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.
|
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: []
|