kitabu 2.1.0 → 3.0.0
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 +5 -5
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +4 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +61 -0
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +13 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +2 -0
- data/LICENSE.md +20 -0
- data/README.md +103 -88
- data/Rakefile +7 -0
- data/bin/kitabu +4 -0
- data/kitabu.gemspec +21 -15
- data/lib/kitabu/cli.rb +54 -39
- data/lib/kitabu/dependency.rb +11 -5
- data/lib/kitabu/errors.rb +2 -0
- data/lib/kitabu/exporter/base.rb +11 -11
- data/lib/kitabu/exporter/css.rb +6 -15
- data/lib/kitabu/exporter/epub.rb +23 -17
- data/lib/kitabu/exporter/html.rb +27 -21
- data/lib/kitabu/exporter/mobi.rb +7 -1
- data/lib/kitabu/exporter/pdf.rb +9 -3
- data/lib/kitabu/exporter.rb +15 -16
- data/lib/kitabu/extensions/rouge.rb +6 -1
- data/lib/kitabu/extensions/string.rb +5 -3
- data/lib/kitabu/footnotes/base.rb +2 -0
- data/lib/kitabu/footnotes/html.rb +18 -13
- data/lib/kitabu/footnotes/pdf.rb +17 -11
- data/lib/kitabu/generator.rb +13 -8
- data/lib/kitabu/helpers.rb +12 -9
- data/lib/kitabu/markdown.rb +12 -10
- data/lib/kitabu/source_list.rb +15 -12
- data/lib/kitabu/stats.rb +3 -1
- data/lib/kitabu/syntax/highlight.rb +4 -11
- data/lib/kitabu/toc/epub.rb +5 -2
- data/lib/kitabu/toc/html/stream.rb +3 -1
- data/lib/kitabu/toc/html.rb +12 -8
- data/lib/kitabu/version.rb +4 -2
- data/lib/kitabu.rb +8 -10
- data/spec/kitabu/cli/export_spec.rb +6 -4
- data/spec/kitabu/cli/new_spec.rb +6 -4
- data/spec/kitabu/cli/permalinks_spec.rb +4 -2
- data/spec/kitabu/cli/stats_spec.rb +19 -15
- data/spec/kitabu/cli/version_spec.rb +3 -1
- data/spec/kitabu/exporter/css_spec.rb +3 -1
- data/spec/kitabu/exporter/epub_spec.rb +2 -0
- data/spec/kitabu/exporter/html_spec.rb +11 -9
- data/spec/kitabu/exporter/mobi_spec.rb +5 -5
- data/spec/kitabu/exporter/pdf_spec.rb +8 -4
- data/spec/kitabu/extensions/string_spec.rb +14 -9
- data/spec/kitabu/footnotes/html_spec.rb +35 -33
- data/spec/kitabu/generator_spec.rb +3 -1
- data/spec/kitabu/markdown_spec.rb +8 -6
- data/spec/kitabu/source_list_spec.rb +8 -2
- data/spec/kitabu/stats_spec.rb +10 -6
- data/spec/kitabu/toc/html_spec.rb +37 -21
- data/spec/spec_helper.rb +23 -8
- data/spec/support/exit_with_code.rb +7 -5
- data/spec/support/have_tag.rb +44 -32
- data/spec/support/helper.rb +5 -3
- data/spec/support/mybook/code/code.rb +2 -0
- data/spec/support/mybook/config/helper.rb +2 -0
- data/spec/support/shared.rb +8 -6
- data/templates/Gemfile +5 -3
- data/templates/Guardfile +3 -1
- data/templates/helper.rb +8 -6
- data/templates/templates/styles/epub.css +1 -0
- data/templates/templates/styles/files/normalize.css +351 -0
- data/templates/templates/styles/{html.scss → html.css} +28 -26
- data/templates/templates/styles/{pdf.scss → pdf.css} +49 -47
- data/templates/templates/styles/print.css +2 -0
- data/templates/text/01_Getting_Started.md +27 -9
- data/templates/text/02_Creating_Chapters.md +9 -3
- data/templates/text/{03_Syntax_Highlighting.erb → 03_Syntax_Highlighting.md.erb} +12 -7
- data/templates/text/04_Dynamic_Content.md.erb +48 -0
- data/templates/text/05_Exporting_Files.md +17 -8
- metadata +40 -48
- data/.gitmodules +0 -3
- data/.travis.yml +0 -18
- data/lib/kitabu/exporter/txt.rb +0 -18
- data/spec/kitabu/exporter/txt_spec.rb +0 -14
- data/templates/ebook.png +0 -0
- data/templates/templates/styles/epub.scss +0 -1
- data/templates/templates/styles/files/_normalize.scss +0 -427
- data/templates/templates/styles/print.scss +0 -2
- data/templates/text/04_Dynamic_Content.erb +0 -64
data/lib/kitabu/source_list.rb
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
class SourceList
|
|
3
5
|
# List of directories that should be skipped.
|
|
4
6
|
#
|
|
5
|
-
IGNORE_DIR = %w[. .. .svn .git]
|
|
7
|
+
IGNORE_DIR = %w[. .. .svn .git].freeze
|
|
6
8
|
|
|
7
9
|
# Files that should be skipped.
|
|
8
10
|
#
|
|
9
|
-
IGNORE_FILES = /^(CHANGELOG|TOC)
|
|
11
|
+
IGNORE_FILES = /^(CHANGELOG|TOC)\..*?$/.freeze
|
|
10
12
|
|
|
11
13
|
# List of recognized extensions.
|
|
12
14
|
#
|
|
13
|
-
EXTENSIONS = %w[md erb]
|
|
15
|
+
EXTENSIONS = %w[md erb].freeze
|
|
14
16
|
|
|
15
|
-
attr_reader :root_dir
|
|
16
|
-
attr_reader :source
|
|
17
|
+
attr_reader :root_dir, :source
|
|
17
18
|
|
|
18
19
|
def initialize(root_dir)
|
|
19
20
|
@root_dir = root_dir
|
|
20
|
-
@source = root_dir.join(
|
|
21
|
+
@source = root_dir.join("text")
|
|
21
22
|
end
|
|
22
23
|
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
24
|
def each_chapter(&block)
|
|
26
25
|
files_grouped_by_chapter.each(&block)
|
|
27
26
|
end
|
|
@@ -38,7 +37,7 @@ module Kitabu
|
|
|
38
37
|
if File.file?(entry)
|
|
39
38
|
[entry]
|
|
40
39
|
else
|
|
41
|
-
Dir["#{entry}/**/*.{#{EXTENSIONS.join(
|
|
40
|
+
Dir["#{entry}/**/*.{#{EXTENSIONS.join(',')}}"].sort
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
43
|
|
|
@@ -60,14 +59,18 @@ module Kitabu
|
|
|
60
59
|
# Check if path is a valid directory.
|
|
61
60
|
#
|
|
62
61
|
def valid_directory?(entry)
|
|
63
|
-
File.directory?(source.join(entry)) &&
|
|
62
|
+
File.directory?(source.join(entry)) &&
|
|
63
|
+
!IGNORE_DIR.include?(File.basename(entry))
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Check if path is a valid file.
|
|
67
67
|
#
|
|
68
68
|
def valid_file?(entry)
|
|
69
|
-
ext = File.extname(entry).
|
|
70
|
-
|
|
69
|
+
ext = File.extname(entry).delete(".").downcase
|
|
70
|
+
|
|
71
|
+
File.file?(source.join(entry)) &&
|
|
72
|
+
EXTENSIONS.include?(ext) &&
|
|
73
|
+
entry !~ IGNORE_FILES
|
|
71
74
|
end
|
|
72
75
|
end
|
|
73
76
|
end
|
data/lib/kitabu/stats.rb
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
class Syntax
|
|
3
5
|
class Highlight
|
|
4
6
|
def self.apply(code, language)
|
|
5
|
-
|
|
6
|
-
pygments(code, language)
|
|
7
|
-
else
|
|
8
|
-
coderay(code, language)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
def self.pygments(code, language)
|
|
14
|
-
Pygments.highlight(code, :lexer => language, :options => {:encoding => "utf-8"})
|
|
7
|
+
coderay(code, language)
|
|
15
8
|
end
|
|
16
9
|
|
|
17
10
|
def self.coderay(code, language)
|
|
18
|
-
html = Nokogiri::HTML(CodeRay.scan(code, language).div(:
|
|
11
|
+
html = Nokogiri::HTML(CodeRay.scan(code, language).div(css: :class))
|
|
19
12
|
coderay = html.css("div.CodeRay").first
|
|
20
13
|
coderay.set_attribute "class", "CodeRay #{language}"
|
|
21
14
|
pre = html.css("pre").first
|
data/lib/kitabu/toc/epub.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
module TOC
|
|
3
5
|
class Epub
|
|
@@ -8,11 +10,12 @@ module Kitabu
|
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def to_html
|
|
11
|
-
|
|
13
|
+
data = OpenStruct.new(navigation: navigation).instance_eval { binding }
|
|
14
|
+
ERB.new(template).result(data)
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def template
|
|
15
|
-
|
|
18
|
+
(+<<-HTML).strip_heredoc.force_encoding("utf-8")
|
|
16
19
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
17
20
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
18
21
|
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
module TOC
|
|
3
5
|
class HTML
|
|
@@ -23,7 +25,7 @@ module Kitabu
|
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def emit(node)
|
|
26
|
-
listener.tag(node) if
|
|
28
|
+
listener.tag(node) if /h[1-6]/.match?(node.name)
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
end
|
data/lib/kitabu/toc/html.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
module TOC
|
|
3
5
|
class HTML
|
|
@@ -6,11 +8,10 @@ module Kitabu
|
|
|
6
8
|
attr_reader :toc
|
|
7
9
|
|
|
8
10
|
private_class_method :new
|
|
9
|
-
attr_reader :buffer
|
|
10
|
-
|
|
11
|
-
attr_accessor :content # :nodoc:
|
|
11
|
+
attr_reader :buffer, :attrs
|
|
12
|
+
attr_accessor :content
|
|
12
13
|
|
|
13
|
-
# Traverse every title and add
|
|
14
|
+
# Traverse every title and add an +id+ attribute.
|
|
14
15
|
# Return the modified content.
|
|
15
16
|
#
|
|
16
17
|
def self.normalize(content)
|
|
@@ -23,7 +24,9 @@ module Kitabu
|
|
|
23
24
|
counter[permalink] ||= 0
|
|
24
25
|
counter[permalink] += 1
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
if counter[permalink] > 1
|
|
28
|
+
permalink = "#{permalink}-#{counter[permalink]}"
|
|
29
|
+
end
|
|
27
30
|
|
|
28
31
|
tag.set_attribute("id", permalink)
|
|
29
32
|
end
|
|
@@ -67,8 +70,8 @@ module Kitabu
|
|
|
67
70
|
# Return the table of contents in HTML format.
|
|
68
71
|
#
|
|
69
72
|
def to_html
|
|
70
|
-
|
|
71
|
-
toc.
|
|
73
|
+
buffer =
|
|
74
|
+
toc.each_with_object([]) do |options, html|
|
|
72
75
|
html << %[
|
|
73
76
|
<div class="level#{options[:level]} #{options[:permalink]}">
|
|
74
77
|
<a href="##{options[:permalink]}">
|
|
@@ -77,7 +80,8 @@ module Kitabu
|
|
|
77
80
|
</div>
|
|
78
81
|
]
|
|
79
82
|
end
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
buffer.join
|
|
81
85
|
end
|
|
82
86
|
end
|
|
83
87
|
end
|
data/lib/kitabu/version.rb
CHANGED
data/lib/kitabu.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "active_support/all"
|
|
2
4
|
require "digest/md5"
|
|
3
5
|
require "eeepub"
|
|
4
6
|
require "erb"
|
|
5
7
|
require "logger"
|
|
6
8
|
require "nokogiri"
|
|
7
|
-
require "notifier"
|
|
8
9
|
require "open3"
|
|
9
10
|
require "optparse"
|
|
10
11
|
require "ostruct"
|
|
@@ -14,23 +15,18 @@ require "thor"
|
|
|
14
15
|
require "thor/group"
|
|
15
16
|
require "yaml"
|
|
16
17
|
require "cgi"
|
|
17
|
-
require "erb"
|
|
18
|
-
require "open3"
|
|
19
18
|
|
|
20
19
|
require "redcarpet"
|
|
21
20
|
require "rouge"
|
|
22
21
|
require "rouge/plugins/redcarpet"
|
|
23
22
|
|
|
24
|
-
require "sass"
|
|
25
|
-
require "sass-globbing"
|
|
26
|
-
|
|
27
23
|
I18n.enforce_available_locales = false
|
|
28
24
|
|
|
29
25
|
Encoding.default_internal = "utf-8"
|
|
30
26
|
Encoding.default_external = "utf-8"
|
|
31
27
|
|
|
32
28
|
module Kitabu
|
|
33
|
-
ROOT = Pathname.new(File.dirname(__FILE__)
|
|
29
|
+
ROOT = Pathname.new("#{File.dirname(__FILE__)}/..")
|
|
34
30
|
|
|
35
31
|
require "kitabu/extensions/string"
|
|
36
32
|
require "kitabu/extensions/rouge"
|
|
@@ -46,7 +42,6 @@ module Kitabu
|
|
|
46
42
|
require "kitabu/exporter/epub"
|
|
47
43
|
require "kitabu/exporter/mobi"
|
|
48
44
|
require "kitabu/exporter/pdf"
|
|
49
|
-
require "kitabu/exporter/txt"
|
|
50
45
|
require "kitabu/exporter/css"
|
|
51
46
|
require "kitabu/footnotes/base"
|
|
52
47
|
require "kitabu/footnotes/html"
|
|
@@ -62,10 +57,13 @@ module Kitabu
|
|
|
62
57
|
root_dir ||= Pathname.new(Dir.pwd)
|
|
63
58
|
path = root_dir.join("config/kitabu.yml")
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
unless File.file?(path)
|
|
61
|
+
raise "Invalid Kitabu directory; couldn't find config/kitabu.yml file."
|
|
62
|
+
end
|
|
63
|
+
|
|
66
64
|
content = File.read(path)
|
|
67
65
|
erb = ERB.new(content).result
|
|
68
|
-
YAML.
|
|
66
|
+
YAML.safe_load(erb).with_indifferent_access
|
|
69
67
|
end
|
|
70
68
|
|
|
71
69
|
def self.logger
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Cli do
|
|
4
6
|
context "while running export" do
|
|
5
7
|
it "exits with status 1 when an invalid --only option is provided" do
|
|
6
|
-
expect(
|
|
7
|
-
capture(:stderr){ Kitabu::Cli.start(["export", "--only=invalid"]) }
|
|
8
|
+
expect(lambda {
|
|
9
|
+
capture(:stderr) { Kitabu::Cli.start(["export", "--only=invalid"]) }
|
|
8
10
|
}).to exit_with_code(1)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
it "exits with status 1 when no config file is found" do
|
|
12
|
-
expect(
|
|
13
|
-
capture(:stderr){ Kitabu::Cli.start(["export"]) }
|
|
14
|
+
expect(lambda {
|
|
15
|
+
capture(:stderr) { Kitabu::Cli.start(["export"]) }
|
|
14
16
|
}).to exit_with_code(1)
|
|
15
17
|
end
|
|
16
18
|
end
|
data/spec/kitabu/cli/new_spec.rb
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Cli do
|
|
4
6
|
context "while running new" do
|
|
5
7
|
context "when all params are valid" do
|
|
6
8
|
before do
|
|
7
|
-
capture(:stdout)
|
|
9
|
+
capture(:stdout) do
|
|
8
10
|
Kitabu::Cli.start(["new", tmpdir.join("mybook").to_s])
|
|
9
|
-
|
|
11
|
+
end
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it_behaves_like "e-book"
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "exits with status 1 when no path is provided" do
|
|
16
|
-
expect(
|
|
17
|
-
capture(:stderr){ Kitabu::Cli.start(["new"]) }
|
|
18
|
+
expect(lambda {
|
|
19
|
+
capture(:stderr) { Kitabu::Cli.start(["new"]) }
|
|
18
20
|
}).to exit_with_code(1)
|
|
19
21
|
|
|
20
22
|
expect(File).not_to be_directory(tmpdir.join("mybook"))
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Cli do
|
|
@@ -5,9 +7,9 @@ describe Kitabu::Cli do
|
|
|
5
7
|
it "recognizes command" do
|
|
6
8
|
Dir.chdir SPECDIR.join("support/mybook")
|
|
7
9
|
|
|
8
|
-
expect
|
|
10
|
+
expect do
|
|
9
11
|
capture(:stdout) { Kitabu::Cli.start(["permalinks"]) }
|
|
10
|
-
|
|
12
|
+
end.to_not raise_error
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Cli, "while running stats" do
|
|
@@ -5,9 +7,9 @@ describe Kitabu::Cli, "while running stats" do
|
|
|
5
7
|
before { Dir.chdir(root_dir) }
|
|
6
8
|
|
|
7
9
|
it "recognizes command" do
|
|
8
|
-
expect
|
|
10
|
+
expect do
|
|
9
11
|
capture(:stdout) { Kitabu::Cli.start(["stats"]) }
|
|
10
|
-
|
|
12
|
+
end.to_not raise_error
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
it "initializes stats with root dir" do
|
|
@@ -20,22 +22,24 @@ describe Kitabu::Cli, "while running stats" do
|
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
context "outputting stats" do
|
|
23
|
-
let(:stats)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
let(:stats) do
|
|
26
|
+
double("stats", {
|
|
27
|
+
chapters: 4,
|
|
28
|
+
words: 50,
|
|
29
|
+
images: 10,
|
|
30
|
+
footnotes: 15,
|
|
31
|
+
links: 20,
|
|
32
|
+
code_blocks: 25
|
|
33
|
+
})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
before do
|
|
33
37
|
allow(Kitabu::Stats).to receive_message_chain(:new).and_return(stats)
|
|
34
|
-
|
|
38
|
+
end
|
|
35
39
|
|
|
36
|
-
subject(:output)
|
|
40
|
+
subject(:output) do
|
|
37
41
|
capture(:stdout) { Kitabu::Cli.start(["stats"]) }
|
|
38
|
-
|
|
42
|
+
end
|
|
39
43
|
|
|
40
44
|
it { expect(output).to include("Chapters: 4") }
|
|
41
45
|
it { expect(output).to include("Words: 50") }
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Cli do
|
|
4
6
|
context "while running version" do
|
|
5
7
|
it "outputs version" do
|
|
6
8
|
%w[version -v --version].each do |arg|
|
|
7
|
-
output = capture(:stdout){ Kitabu::Cli.start([arg]) }.chomp
|
|
9
|
+
output = capture(:stdout) { Kitabu::Cli.start([arg]) }.chomp
|
|
8
10
|
expect(output).to eq("Kitabu version #{Kitabu::Version::STRING}")
|
|
9
11
|
end
|
|
10
12
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Exporter::HTML do
|
|
@@ -9,14 +11,14 @@ describe Kitabu::Exporter::HTML do
|
|
|
9
11
|
let(:html) { File.read(file) }
|
|
10
12
|
before { format.export }
|
|
11
13
|
|
|
12
|
-
it "generates valid markup", osx:
|
|
14
|
+
it "generates valid markup", osx: Kitabu::Dependency.macos? do
|
|
13
15
|
`./vendor/bin/tidy5_osx '#{file}' 2>&1 > /dev/null`
|
|
14
|
-
expect(
|
|
16
|
+
expect($CHILD_STATUS.exitstatus).to eq(0)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
it "generates valid markup", linux:
|
|
19
|
+
it "generates valid markup", linux: Kitabu::Dependency.linux? do
|
|
18
20
|
`./vendor/bin/tidy5_linux '#{file}' 2>&1 > /dev/null`
|
|
19
|
-
expect(
|
|
21
|
+
expect($CHILD_STATUS.exitstatus).to eq(0)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
it "keeps html file around" do
|
|
@@ -44,14 +46,14 @@ describe Kitabu::Exporter::HTML do
|
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
it "copies fonts" do
|
|
47
|
-
expect(root.join(
|
|
49
|
+
expect(root.join("output/fonts/OpenSans-CondBold.ttf")).to be_file
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
it "exports css files" do
|
|
51
|
-
expect(root.join(
|
|
52
|
-
expect(root.join(
|
|
53
|
-
expect(root.join(
|
|
54
|
-
expect(root.join(
|
|
53
|
+
expect(root.join("output/styles/epub.css")).to be_file
|
|
54
|
+
expect(root.join("output/styles/html.css")).to be_file
|
|
55
|
+
expect(root.join("output/styles/pdf.css")).to be_file
|
|
56
|
+
expect(root.join("output/styles/print.css")).to be_file
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
|
-
describe Kitabu::Exporter::Mobi,
|
|
4
|
-
|
|
5
|
+
describe Kitabu::Exporter::Mobi, calibre: Kitabu::Dependency.calibre? do
|
|
6
|
+
it "generates mobi" do
|
|
7
|
+
root = SPECDIR.join("support/mybook")
|
|
5
8
|
|
|
6
|
-
before do
|
|
7
9
|
Kitabu::Exporter::HTML.export(root)
|
|
8
10
|
Kitabu::Exporter::Mobi.export(root)
|
|
9
|
-
end
|
|
10
11
|
|
|
11
|
-
it "generates mobi" do
|
|
12
12
|
expect(root.join("output/mybook.mobi")).to be_file
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe Kitabu::Exporter::PDF, prince: Kitabu::Dependency.prince? do
|
|
@@ -9,16 +11,18 @@ describe Kitabu::Exporter::PDF, prince: Kitabu::Dependency.prince? do
|
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
it "creates html with css identifier" do
|
|
12
|
-
expect(root.join("output/mybook.pdf.html").read).to have_tag(
|
|
13
|
-
expect(root.join("output/mybook.print.html").read).to have_tag(
|
|
14
|
+
expect(root.join("output/mybook.pdf.html").read).to have_tag("html.pdf")
|
|
15
|
+
expect(root.join("output/mybook.print.html").read).to have_tag("html.print")
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
it "sets stylesheet for print pdf" do
|
|
17
|
-
|
|
19
|
+
selector = 'link[rel=stylesheet][href="styles/print.css"]'
|
|
20
|
+
expect(root.join("output/mybook.print.html").read).to have_tag(selector)
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
it "sets stylesheet for pdf" do
|
|
21
|
-
|
|
24
|
+
selector = 'link[rel=stylesheet][href="styles/pdf.css"]'
|
|
25
|
+
expect(root.join("output/mybook.pdf.html").read).to have_tag(selector)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
it "generates pdf file for print" do
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Layout/LineLength
|
|
4
|
+
|
|
2
5
|
require "spec_helper"
|
|
3
6
|
|
|
4
7
|
describe String do
|
|
5
8
|
describe "#to_permalink" do
|
|
6
9
|
it "normalizes strings" do
|
|
7
10
|
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'some-)()()-ExtRa!/// .data==?> to \/\/test' =>
|
|
13
|
-
|
|
14
|
-
"Don't Repeat Yourself (DRY)" =>
|
|
15
|
-
"Text\nwith\nline\n\n\tbreaks" =>
|
|
11
|
+
"This IS a Tripped out title!!.!1 (well/ not really)" => "this-is-a-tripped-out-title-1-well-not-really",
|
|
12
|
+
"////// meph1sto r0x ! \\\\\\" => "meph1sto-r0x",
|
|
13
|
+
"āčēģīķļņū" => "acegiklnu",
|
|
14
|
+
"中文測試 chinese text" => "chinese-text",
|
|
15
|
+
'some-)()()-ExtRa!/// .data==?> to \/\/test' => "some-extra-data-to-test",
|
|
16
|
+
"http://simplesideias.com.br/tags/" => "http-simplesideias-com-br-tags",
|
|
17
|
+
"Don't Repeat Yourself (DRY)" => "don-t-repeat-yourself-dry",
|
|
18
|
+
"Text\nwith\nline\n\n\tbreaks" => "text-with-line-breaks"
|
|
16
19
|
}.each do |dirty, normalized|
|
|
17
20
|
expect(dirty.to_permalink).to eq(normalized)
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
end
|
|
21
24
|
end
|
|
25
|
+
|
|
26
|
+
# rubocop:enable Layout/LineLength
|