bookify 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bookify.rb +1 -0
- data/lib/bookify/node/h1.rb +8 -2
- data/lib/bookify/node/h2.rb +12 -2
- data/lib/bookify/renderer.rb +10 -1
- data/lib/bookify/sections.rb +31 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1c8b6ba5756c03591227c7a7569704c4ba6942a4cf3a394ece903d5ca30f69
|
4
|
+
data.tar.gz: b9e842cf16c742c759eeb7985dfd6ca5ebfecdfc375ede57c81439d55f6b2b5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e4d342c7e3cc17d2c671390f6592686f9f2be819956fc7194b840286fd74d37c829911f672dc63602ee1f884806ca26b48063a74ffd452b1ce190e1f0d0cf5
|
7
|
+
data.tar.gz: 1b0a40c88f60ecaf25d44ee1e0acd382de65b3930055d9cbec9c20d804b733386e8e8f9ce425f527fe8d4b6c9d58b14a4089c068a66e94c288a1ff164fa6ce6b
|
data/lib/bookify.rb
CHANGED
data/lib/bookify/node/h1.rb
CHANGED
@@ -5,10 +5,16 @@ module Bookify::Node
|
|
5
5
|
def render
|
6
6
|
break_if_close_to_bottom(250)
|
7
7
|
move_down 20 unless pdf.y == page_top
|
8
|
-
|
8
|
+
|
9
9
|
html = decode_html(node.inner_html.strip)
|
10
|
-
|
10
|
+
dest = dest_xyz(0, pdf.y, nil, pdf.page)
|
11
|
+
|
12
|
+
Bookify::Sections.add(:h1, html, dest)
|
13
|
+
add_dest(html, dest)
|
14
|
+
|
15
|
+
font :h1
|
11
16
|
text html, align: :center
|
17
|
+
|
12
18
|
move_down 10
|
13
19
|
end
|
14
20
|
|
data/lib/bookify/node/h2.rb
CHANGED
@@ -3,10 +3,20 @@ require_relative "base"
|
|
3
3
|
module Bookify::Node
|
4
4
|
class H2 < Base
|
5
5
|
def render
|
6
|
-
font :h2
|
7
6
|
move_down 5
|
8
7
|
break_if_close_to_bottom
|
9
|
-
|
8
|
+
|
9
|
+
html = decode_html(node.inner_html.strip)
|
10
|
+
dest = dest_xyz(0, pdf.y, nil, pdf.page)
|
11
|
+
parent_h1 = Bookify::Sections.current_h1_title
|
12
|
+
|
13
|
+
Bookify::Sections.add(:h2, html, dest)
|
14
|
+
add_dest(html, dest)
|
15
|
+
add_dest("#{parent_h1}/#{html}", dest) if parent_h1
|
16
|
+
|
17
|
+
font :h2
|
18
|
+
text html
|
19
|
+
|
10
20
|
move_down 1
|
11
21
|
stroke { horizontal_rule }
|
12
22
|
move_down 10
|
data/lib/bookify/renderer.rb
CHANGED
@@ -32,6 +32,7 @@ class Bookify::Renderer
|
|
32
32
|
|
33
33
|
def render
|
34
34
|
doc_opts = {margin: margin, page_layout: layout, page_size: page_size}.compact
|
35
|
+
Bookify::Sections.reset
|
35
36
|
|
36
37
|
Prawn::Document.generate(output_file, doc_opts) do |pdf|
|
37
38
|
font_path = "#{File.dirname(__FILE__)}/../../fonts"
|
@@ -40,7 +41,7 @@ class Bookify::Renderer
|
|
40
41
|
normal: {file: "#{font_path}/BookAntiqua.ttf"},
|
41
42
|
bold: {file: "#{font_path}/BookAntiqua-Bold.ttf"},
|
42
43
|
italic: {file: "#{font_path}/BookAntiqua-Italic.ttf"},
|
43
|
-
bold_italic: {file: "#{font_path}/BookAntiqua-BoldItalic.ttf"}
|
44
|
+
bold_italic: {file: "#{font_path}/BookAntiqua-BoldItalic.ttf"}
|
44
45
|
}
|
45
46
|
|
46
47
|
pdf.fill_color "000000"
|
@@ -51,6 +52,14 @@ class Bookify::Renderer
|
|
51
52
|
pdf.column_box [0, pdf.cursor], columns: columns, width: pdf.bounds.width, spacer: (column_spacer || pdf.font_size) do
|
52
53
|
doc.children.each { |c| Bookify::Node.render(c, pdf) }
|
53
54
|
end
|
55
|
+
|
56
|
+
Bookify::Sections.all.each do |section|
|
57
|
+
pdf.outline.section(section[:title], destination: section[:dest]) do
|
58
|
+
section[:subsections].each do |subsection|
|
59
|
+
pdf.outline.page title: subsection[:title], destination: subsection[:dest]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Bookify
|
2
|
+
module Sections
|
3
|
+
InvalidLevel = Class.new(StandardError)
|
4
|
+
|
5
|
+
@@sections = []
|
6
|
+
|
7
|
+
def self.add(level, title, dest)
|
8
|
+
case level
|
9
|
+
when :h1
|
10
|
+
@@sections << {title: title, dest: dest, subsections: []}
|
11
|
+
when :h2
|
12
|
+
return if @@sections.empty?
|
13
|
+
@@sections.last[:subsections] << {title: title, dest: dest}
|
14
|
+
else
|
15
|
+
raise InvalidLevel, level
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all
|
20
|
+
@@sections
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.current_h1_title
|
24
|
+
@@sections.any? ? @@sections.last[:title] : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.reset
|
28
|
+
@@sections = []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joey Schoblaska
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/bookify/node/paragraph.rb
|
122
122
|
- lib/bookify/node/table.rb
|
123
123
|
- lib/bookify/renderer.rb
|
124
|
+
- lib/bookify/sections.rb
|
124
125
|
homepage: https://github.com/joeyschoblaska/bookify
|
125
126
|
licenses:
|
126
127
|
- MIT
|
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
141
|
- !ruby/object:Gem::Version
|
141
142
|
version: '0'
|
142
143
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.1.2
|
144
145
|
signing_key:
|
145
146
|
specification_version: 4
|
146
147
|
summary: Transform Markdown docs into two-column PDFs.
|