kitabu 2.0.3 → 2.0.4

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
  SHA1:
3
- metadata.gz: bd86f5ee69244e8b29bfaece12650d010841a669
4
- data.tar.gz: 9e091f5f94a6c452f6e76722ad690902999c52a4
3
+ metadata.gz: 6e80a74dc472390fc4a60fa9d1efcb58883ab3a8
4
+ data.tar.gz: 5d0ff304f818d482a9d7553b6d338f789c38b799
5
5
  SHA512:
6
- metadata.gz: ab2dd6d9710198b3a7da0027826b108e074e4ef35c43c3012cc89e160c9d2d13d39723c26dffae53b9a00f665f95b0bf92a98417a737ca317a67ba46832abcfb
7
- data.tar.gz: 345c9f9fb488991a3c7507c4eb15d5b2454b75846a85cc29b30881b1fe81aba00203eded8401be5a13ef5385787ac81abb700a3d4bd4b95ae60f6973aed3ad26
6
+ metadata.gz: 7517d568da3ccbd2804f42c7fa9dc7905778acca3a26a82e58ffab6965dab7bd232b1bf2134f10fff62559a1e3fedbbb6471b51c1f0d48412775990c59c303f5
7
+ data.tar.gz: 1dc60c65a50467a337dd6db0b4da2a01da2260b0257810b315e336e4fdfc58f4b428e39561bcf43d55c0be76572b80b3da8ba8ad188634981170052bb51b0c5f
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  /spec/support/mybook/output
5
5
  /coverage
6
6
  .sass-cache
7
+ *.lock
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## v2.0.4
4
+
5
+ - Support fonts directory
6
+ - Allow having any element as the chapter title (e.g. h1). Previously you could only use h2.
7
+ - Bug fix: unknown Rouge lexer was raising an error.
8
+
9
+ ## v2.0.3
10
+
11
+ - Bug fix: footnote label wasn't updated with current count
12
+
13
+ ## v2.0.2
14
+
15
+ - Bug fix: generate valid HTML markup
16
+
17
+ ## v2.0.1
18
+
19
+ - Improve footnote generation
20
+
3
21
  ## v2.0.0
4
22
 
5
23
  - Remove support for different markdown processors; now using Redcarpet.
data/README.md CHANGED
@@ -125,7 +125,7 @@ To print the TOC, you need to print a variable called `toc`, using the eRb tag.
125
125
 
126
126
  <%= toc %>
127
127
 
128
- #### Using ERB
128
+ ### Using ERB
129
129
 
130
130
  You can also have `.erb` files. You can mix Markdown and HTML, like the following:
131
131
 
@@ -189,7 +189,28 @@ The following Redcarpet options are enabled:
189
189
  * `superscript`
190
190
  * `tables`
191
191
 
192
- ### References
192
+ ### Using custom fonts
193
+
194
+ You can use custom fonts for your PDF. Just add them to the `fonts` directory (you can create this directory on your book's root directory if it doesn't exist).
195
+
196
+ Then, on `templates/styles/pdf.scss` you can add the `@font-face` declaration.
197
+
198
+ ```css
199
+ @font-face {
200
+ font-family: 'Open Sans Condensed Bold';
201
+ src: url('../fonts/OpenSans-CondBold.ttf');
202
+ }
203
+ ```
204
+
205
+ Finally, to use this font, do something like this:
206
+
207
+ ```css
208
+ .chapter > h2 {
209
+ font-family: 'Open Sans Condensed Bold';
210
+ }
211
+ ```
212
+
213
+ ## References
193
214
 
194
215
  * Markdown: <http://daringfireball.net/projects/markdown/syntax>
195
216
  * Markdown PHP: <https://michelf.ca/projects/php-markdown/extra/>
@@ -37,7 +37,6 @@ module Kitabu
37
37
  require "kitabu/errors"
38
38
  require "kitabu/version"
39
39
  require "kitabu/generator"
40
- require "kitabu/toc"
41
40
  require "kitabu/cli"
42
41
  require "kitabu/markdown"
43
42
  require "kitabu/source_list"
@@ -52,7 +51,9 @@ module Kitabu
52
51
  require "kitabu/footnotes/base"
53
52
  require "kitabu/footnotes/html"
54
53
  require "kitabu/footnotes/pdf"
55
- require "kitabu/stream"
54
+ require "kitabu/toc/html"
55
+ require "kitabu/toc/html/stream"
56
+ require "kitabu/toc/epub"
56
57
  require "kitabu/dependency"
57
58
  require "kitabu/stats"
58
59
  require "kitabu/helpers"
@@ -64,6 +64,8 @@ module Kitabu
64
64
  end
65
65
 
66
66
  def copy_directory(source, target)
67
+ return unless root_dir.join(source).directory?
68
+
67
69
  source = root_dir.join("#{source}/.")
68
70
  target = root_dir.join(target)
69
71
 
@@ -5,6 +5,7 @@ module Kitabu
5
5
 
6
6
  def export
7
7
  files = Dir[root_dir.join("templates/styles/*.{scss,sass}").to_s]
8
+
8
9
  options = {
9
10
  style: :expanded,
10
11
  line_numbers: true,
@@ -129,7 +129,7 @@ module Kitabu
129
129
  def navigation
130
130
  sections.map do |section|
131
131
  {
132
- label: section.html.css("h2:first-of-type").text,
132
+ label: section.html.css(":first-child").text,
133
133
  content: section.filename
134
134
  }
135
135
  end
@@ -13,6 +13,7 @@ module Kitabu
13
13
  #
14
14
  def export
15
15
  copy_images!
16
+ copy_fonts!
16
17
  export_stylesheets!
17
18
 
18
19
  File.open(root_dir.join("output/#{name}.html"), "w") do |file|
@@ -99,6 +100,12 @@ module Kitabu
99
100
  copy_directory("images", "output/images")
100
101
  end
101
102
 
103
+ # Copy font files
104
+ #
105
+ def copy_fonts!
106
+ copy_directory("fonts", "output/fonts")
107
+ end
108
+
102
109
  # Export all root stylesheets.
103
110
  #
104
111
  def export_stylesheets!
@@ -2,7 +2,8 @@ module Rouge
2
2
  module Plugins
3
3
  module Redcarpet
4
4
  def rouge_formatter(lexer)
5
- Formatters::HTML.new({css_class: "highlight #{lexer.tag}"}.merge(lexer.options))
5
+ options = lexer.respond_to?(:options) ? lexer.options : {}
6
+ Formatters::HTML.new({css_class: "highlight #{lexer.tag}"}.merge(options))
6
7
  end
7
8
  end
8
9
  end
@@ -43,12 +43,15 @@ module Kitabu
43
43
 
44
44
  def create_directories
45
45
  empty_directory "output"
46
+ empty_directory "fonts"
46
47
  end
47
48
 
48
49
  def create_git_files
49
50
  create_file ".gitignore" do
50
51
  "/output"
51
52
  end
53
+
54
+ create_file "fonts/.keep"
52
55
  end
53
56
 
54
57
  def copy_guardfile
@@ -69,7 +69,13 @@ module Kitabu
69
69
  def to_html
70
70
  String.new.tap do |html|
71
71
  toc.each do |options|
72
- html << %[<div class="level#{options[:level]} #{options[:permalink]}"><a href="##{options[:permalink]}"><span>#{CGI.escape_html(options[:text])}</span></a></div>]
72
+ html << %[
73
+ <div class="level#{options[:level]} #{options[:permalink]}">
74
+ <a href="##{options[:permalink]}">
75
+ <span>#{CGI.escape_html(options[:text])}</span>
76
+ </a>
77
+ </div>
78
+ ]
73
79
  end
74
80
  end
75
81
  end
@@ -0,0 +1,31 @@
1
+ module Kitabu
2
+ module TOC
3
+ class HTML
4
+ class Stream
5
+ attr_accessor :listener, :content
6
+ attr_reader :html
7
+
8
+ def initialize(content, listener)
9
+ @content = content
10
+ @listener = listener
11
+ @html = Nokogiri::HTML.parse(content)
12
+ end
13
+
14
+ def parse
15
+ traverse(html)
16
+ end
17
+
18
+ def traverse(node)
19
+ node.children.each do |child|
20
+ emit(child)
21
+ traverse(child)
22
+ end
23
+ end
24
+
25
+ def emit(node)
26
+ listener.tag(node) if node.name =~ /h[1-6]/
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,7 +2,7 @@ module Kitabu
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 4
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -42,5 +42,16 @@ describe Kitabu::Exporter::HTML do
42
42
  it "renders erb blocks" do
43
43
  expect(html).to have_tag("div.note.info > p", "This is a note!")
44
44
  end
45
+
46
+ it "copies fonts" do
47
+ expect(root.join('output/fonts/OpenSans-CondBold.ttf')).to be_file
48
+ end
49
+
50
+ it "exports css files" do
51
+ expect(root.join('output/styles/epub.css')).to be_file
52
+ expect(root.join('output/styles/html.css')).to be_file
53
+ expect(root.join('output/styles/pdf.css')).to be_file
54
+ expect(root.join('output/styles/print.css')).to be_file
55
+ end
45
56
  end
46
57
  end
@@ -21,4 +21,14 @@ describe Kitabu::Markdown do
21
21
 
22
22
  expect(html).to include('<span class="k">echo</span>')
23
23
  end
24
+
25
+ it 'does not raise with unknown lexers' do
26
+ expect {
27
+ Kitabu::Markdown.render <<-TEXT.strip_heredoc
28
+ ```terminal
29
+ Text plain.
30
+ ```
31
+ TEXT
32
+ }.not_to raise_error
33
+ end
24
34
  end
@@ -2,6 +2,10 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe Kitabu::TOC::HTML do
5
+ def regexp(text)
6
+ /#{Regexp.escape(text)}/
7
+ end
8
+
5
9
  HTML = <<-HTML
6
10
  <h1>Item 1</h1>
7
11
  <h2>Item 1.2</h2>
@@ -26,30 +30,30 @@ describe Kitabu::TOC::HTML do
26
30
  end
27
31
 
28
32
  it "generates toc" do
29
- expect(html).to have_tag("div.level1.item-1", "Item 1")
30
- expect(html).to have_tag("div.level2.item-1-2", "Item 1.2")
31
- expect(html).to have_tag("div.level3.item-1-1-3", "Item 1.1.3")
32
- expect(html).to have_tag("div.level4.item-1-1-1-4", "Item 1.1.1.4")
33
- expect(html).to have_tag("div.level5.item-1-1-1-1-5", "Item 1.1.1.1.5")
34
- expect(html).to have_tag("div.level6.item-1-1-1-1-1-6", "Item 1.1.1.1.1.6")
33
+ expect(html).to have_tag("div.level1.item-1", regexp("Item 1"))
34
+ expect(html).to have_tag("div.level2.item-1-2", regexp("Item 1.2"))
35
+ expect(html).to have_tag("div.level3.item-1-1-3", regexp("Item 1.1.3"))
36
+ expect(html).to have_tag("div.level4.item-1-1-1-4", regexp("Item 1.1.1.4"))
37
+ expect(html).to have_tag("div.level5.item-1-1-1-1-5", regexp("Item 1.1.1.1.5"))
38
+ expect(html).to have_tag("div.level6.item-1-1-1-1-1-6", regexp("Item 1.1.1.1.1.6"))
35
39
 
36
- expect(html).to have_tag("div.level2.item-2-1", "Item 2.1")
37
- expect(html).to have_tag("div.level2.item-2-1-again", "Item 2.1 again")
40
+ expect(html).to have_tag("div.level2.item-2-1", regexp("Item 2.1"))
41
+ expect(html).to have_tag("div.level2.item-2-1-again", regexp("Item 2.1 again"))
38
42
 
39
- expect(html).to have_tag("div.level2.internacionalizacao", "Internacionalização")
43
+ expect(html).to have_tag("div.level2.internacionalizacao", regexp("Internacionalização"))
40
44
  end
41
45
 
42
46
  it "adds id attribute to content" do
43
- expect(content).to have_tag("h1#item-1", "Item 1")
44
- expect(content).to have_tag("h2#item-1-2", "Item 1.2")
45
- expect(content).to have_tag("h3#item-1-1-3", "Item 1.1.3")
46
- expect(content).to have_tag("h4#item-1-1-1-4", "Item 1.1.1.4")
47
- expect(content).to have_tag("h5#item-1-1-1-1-5", "Item 1.1.1.1.5")
48
- expect(content).to have_tag("h6#item-1-1-1-1-1-6", "Item 1.1.1.1.1.6")
47
+ expect(content).to have_tag("h1#item-1", regexp("Item 1"))
48
+ expect(content).to have_tag("h2#item-1-2", regexp("Item 1.2"))
49
+ expect(content).to have_tag("h3#item-1-1-3", regexp("Item 1.1.3"))
50
+ expect(content).to have_tag("h4#item-1-1-1-4", regexp("Item 1.1.1.4"))
51
+ expect(content).to have_tag("h5#item-1-1-1-1-5", regexp("Item 1.1.1.1.5"))
52
+ expect(content).to have_tag("h6#item-1-1-1-1-1-6", regexp("Item 1.1.1.1.1.6"))
49
53
 
50
- expect(content).to have_tag("h2#item-2-1", "Item 2.1")
51
- expect(content).to have_tag("h2#item-2-1-again", "Item 2.1 again")
54
+ expect(content).to have_tag("h2#item-2-1", regexp("Item 2.1"))
55
+ expect(content).to have_tag("h2#item-2-1-again", regexp("Item 2.1 again"))
52
56
 
53
- expect(content).to have_tag("h2#internacionalizacao", "Internacionalização")
57
+ expect(content).to have_tag("h2#internacionalizacao", regexp("Internacionalização"))
54
58
  end
55
59
  end
@@ -13,6 +13,10 @@ shared_examples_for "e-book" do
13
13
  expect(mybook.join("text")).to be_directory
14
14
  end
15
15
 
16
+ it "creates fonts directory" do
17
+ expect(mybook.join("fonts")).to be_directory
18
+ end
19
+
16
20
  it "creates template directory" do
17
21
  expect(mybook.join("templates")).to be_directory
18
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitabu
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -250,7 +250,6 @@ files:
250
250
  - ".travis.yml"
251
251
  - CHANGELOG.md
252
252
  - Gemfile
253
- - Gemfile.lock
254
253
  - README.md
255
254
  - Rakefile
256
255
  - attachments/browser-version.png
@@ -282,11 +281,10 @@ files:
282
281
  - lib/kitabu/markdown.rb
283
282
  - lib/kitabu/source_list.rb
284
283
  - lib/kitabu/stats.rb
285
- - lib/kitabu/stream.rb
286
284
  - lib/kitabu/syntax/highlight.rb
287
- - lib/kitabu/toc.rb
288
285
  - lib/kitabu/toc/epub.rb
289
286
  - lib/kitabu/toc/html.rb
287
+ - lib/kitabu/toc/html/stream.rb
290
288
  - lib/kitabu/version.rb
291
289
  - spec/kitabu/cli/export_spec.rb
292
290
  - spec/kitabu/cli/new_spec.rb
@@ -315,6 +313,7 @@ files:
315
313
  - spec/support/mybook/code/code.rb
316
314
  - spec/support/mybook/config/helper.rb
317
315
  - spec/support/mybook/config/kitabu.yml
316
+ - spec/support/mybook/fonts/OpenSans-CondBold.ttf
318
317
  - spec/support/mybook/images/.gitkeep
319
318
  - spec/support/mybook/images/logo.gif
320
319
  - spec/support/mybook/templates/epub/cover.erb
@@ -417,6 +416,7 @@ test_files:
417
416
  - spec/support/mybook/code/code.rb
418
417
  - spec/support/mybook/config/helper.rb
419
418
  - spec/support/mybook/config/kitabu.yml
419
+ - spec/support/mybook/fonts/OpenSans-CondBold.ttf
420
420
  - spec/support/mybook/images/.gitkeep
421
421
  - spec/support/mybook/images/logo.gif
422
422
  - spec/support/mybook/templates/epub/cover.erb
@@ -1,108 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- kitabu (2.0.3)
5
- activesupport
6
- eeepub-with-cover-support
7
- i18n
8
- nokogiri
9
- notifier
10
- redcarpet
11
- rouge
12
- rubyzip
13
- sass
14
- sass-globbing
15
- thor
16
- zip-zip
17
-
18
- GEM
19
- remote: https://rubygems.org/
20
- specs:
21
- activesupport (4.2.0)
22
- i18n (~> 0.7)
23
- json (~> 1.7, >= 1.7.7)
24
- minitest (~> 5.1)
25
- thread_safe (~> 0.3, >= 0.3.4)
26
- tzinfo (~> 1.1)
27
- awesome_print (1.6.1)
28
- builder (3.2.2)
29
- byebug (3.5.1)
30
- columnize (~> 0.8)
31
- debugger-linecache (~> 1.2)
32
- slop (~> 3.6)
33
- codeclimate-test-reporter (0.4.7)
34
- simplecov (>= 0.7.1, < 1.0.0)
35
- coderay (1.1.0)
36
- columnize (0.9.0)
37
- debugger-linecache (1.2.0)
38
- diff-lcs (1.2.5)
39
- docile (1.1.5)
40
- eeepub-with-cover-support (0.8.8)
41
- builder
42
- rubyzip
43
- i18n (0.7.0)
44
- json (1.8.2)
45
- method_source (0.8.2)
46
- mini_portile (0.6.2)
47
- minitest (5.5.1)
48
- multi_json (1.11.0)
49
- nokogiri (1.6.6.2)
50
- mini_portile (~> 0.6.0)
51
- notifier (0.5.0)
52
- pry (0.10.1)
53
- coderay (~> 1.1.0)
54
- method_source (~> 0.8.1)
55
- slop (~> 3.4)
56
- pry-byebug (3.0.1)
57
- byebug (~> 3.4)
58
- pry (~> 0.10)
59
- pry-meta (0.0.10)
60
- awesome_print
61
- pry
62
- pry-byebug
63
- pry-remote
64
- pry-remote (0.1.8)
65
- pry (~> 0.9)
66
- slop (~> 3.0)
67
- rake (10.4.2)
68
- redcarpet (3.2.2)
69
- rouge (1.8.0)
70
- rspec (3.2.0)
71
- rspec-core (~> 3.2.0)
72
- rspec-expectations (~> 3.2.0)
73
- rspec-mocks (~> 3.2.0)
74
- rspec-core (3.2.2)
75
- rspec-support (~> 3.2.0)
76
- rspec-expectations (3.2.0)
77
- diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.2.0)
79
- rspec-mocks (3.2.1)
80
- diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.2.0)
82
- rspec-support (3.2.2)
83
- rubyzip (1.1.7)
84
- sass (3.4.13)
85
- sass-globbing (1.1.1)
86
- sass (>= 3.1)
87
- simplecov (0.9.2)
88
- docile (~> 1.1.0)
89
- multi_json (~> 1.0)
90
- simplecov-html (~> 0.9.0)
91
- simplecov-html (0.9.0)
92
- slop (3.6.0)
93
- thor (0.19.1)
94
- thread_safe (0.3.5)
95
- tzinfo (1.2.2)
96
- thread_safe (~> 0.1)
97
- zip-zip (0.3)
98
- rubyzip (>= 1.0.0)
99
-
100
- PLATFORMS
101
- ruby
102
-
103
- DEPENDENCIES
104
- codeclimate-test-reporter
105
- kitabu!
106
- pry-meta
107
- rake
108
- rspec
@@ -1,27 +0,0 @@
1
- module Kitabu
2
- class Stream
3
- attr_accessor :listener, :content
4
- attr_reader :html
5
-
6
- def initialize(content, listener)
7
- @content = content
8
- @listener = listener
9
- @html = Nokogiri::HTML.parse(content)
10
- end
11
-
12
- def parse
13
- traverse(html)
14
- end
15
-
16
- def traverse(node)
17
- node.children.each do |child|
18
- emit(child)
19
- traverse(child)
20
- end
21
- end
22
-
23
- def emit(node)
24
- listener.tag(node) if node.name =~ /h[1-6]/
25
- end
26
- end
27
- end
@@ -1,6 +0,0 @@
1
- module Kitabu
2
- module TOC
3
- autoload :HTML, "kitabu/toc/html"
4
- autoload :Epub, "kitabu/toc/epub"
5
- end
6
- end