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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5efda6174113c079df650774858604834a31f9c8730cc01526488186057fdb1e
4
- data.tar.gz: c469a5f6aa68441251a53e8daa8fc6c76335a03c71f30dcaf471852a1edf152f
3
+ metadata.gz: 7c1c8b6ba5756c03591227c7a7569704c4ba6942a4cf3a394ece903d5ca30f69
4
+ data.tar.gz: b9e842cf16c742c759eeb7985dfd6ca5ebfecdfc375ede57c81439d55f6b2b5a
5
5
  SHA512:
6
- metadata.gz: 4521dca613962076e908c59acc7b7f1af57f23a667503969b5b32fd4d81495edde82018fb47bb891e5e5ae47967a40922a647d449c80e616a5770d7ea5fa9b15
7
- data.tar.gz: e7d33822d208f7ed34a690ef92da5a670db6a177dff1ec5ae0145e6ada1203f3d45c28d671c30777385aae939cc1f125aadbe86eccf1c6943d78a13b79153af6
6
+ metadata.gz: 00e4d342c7e3cc17d2c671390f6592686f9f2be819956fc7194b840286fd74d37c829911f672dc63602ee1f884806ca26b48063a74ffd452b1ce190e1f0d0cf5
7
+ data.tar.gz: 1b0a40c88f60ecaf25d44ee1e0acd382de65b3930055d9cbec9c20d804b733386e8e8f9ce425f527fe8d4b6c9d58b14a4089c068a66e94c288a1ff164fa6ce6b
@@ -12,4 +12,5 @@ end
12
12
  Dir["#{File.dirname(__FILE__)}/bookify/node/*.rb"].each { |f| require f }
13
13
 
14
14
  require_relative "bookify/node"
15
+ require_relative "bookify/sections"
15
16
  require_relative "bookify/renderer"
@@ -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
- font :h1
8
+
9
9
  html = decode_html(node.inner_html.strip)
10
- outline.page title: html, destination: dest_xyz(0, pdf.y, nil, pdf.page)
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
 
@@ -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
- text decode_html(node.inner_html.strip)
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
@@ -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.2.0
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-02-16 00:00:00.000000000 Z
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.0.6
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.