kitabu 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +4 -0
  3. data/.github/FUNDING.yml +4 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
  5. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
  8. data/.github/dependabot.yml +15 -0
  9. data/.github/workflows/ruby-tests.yml +61 -0
  10. data/.gitignore +1 -0
  11. data/.rubocop.yml +17 -0
  12. data/CHANGELOG.md +34 -1
  13. data/CODE_OF_CONDUCT.md +74 -0
  14. data/CONTRIBUTING.md +79 -0
  15. data/Gemfile +2 -0
  16. data/LICENSE.md +20 -0
  17. data/README.md +121 -85
  18. data/Rakefile +7 -0
  19. data/bin/kitabu +4 -0
  20. data/kitabu.gemspec +20 -14
  21. data/lib/kitabu/cli.rb +54 -39
  22. data/lib/kitabu/dependency.rb +11 -5
  23. data/lib/kitabu/errors.rb +2 -0
  24. data/lib/kitabu/exporter/base.rb +13 -11
  25. data/lib/kitabu/exporter/css.rb +6 -14
  26. data/lib/kitabu/exporter/epub.rb +24 -18
  27. data/lib/kitabu/exporter/html.rb +33 -20
  28. data/lib/kitabu/exporter/mobi.rb +7 -1
  29. data/lib/kitabu/exporter/pdf.rb +9 -3
  30. data/lib/kitabu/exporter.rb +15 -16
  31. data/lib/kitabu/extensions/rouge.rb +7 -1
  32. data/lib/kitabu/extensions/string.rb +5 -3
  33. data/lib/kitabu/footnotes/base.rb +2 -0
  34. data/lib/kitabu/footnotes/html.rb +19 -12
  35. data/lib/kitabu/footnotes/pdf.rb +17 -11
  36. data/lib/kitabu/generator.rb +16 -8
  37. data/lib/kitabu/helpers.rb +12 -9
  38. data/lib/kitabu/markdown.rb +12 -10
  39. data/lib/kitabu/source_list.rb +15 -12
  40. data/lib/kitabu/stats.rb +3 -1
  41. data/lib/kitabu/syntax/highlight.rb +4 -11
  42. data/lib/kitabu/toc/epub.rb +5 -2
  43. data/lib/kitabu/toc/html/stream.rb +33 -0
  44. data/lib/kitabu/toc/html.rb +19 -9
  45. data/lib/kitabu/version.rb +4 -2
  46. data/lib/kitabu.rb +11 -12
  47. data/spec/kitabu/cli/export_spec.rb +6 -4
  48. data/spec/kitabu/cli/new_spec.rb +6 -4
  49. data/spec/kitabu/cli/permalinks_spec.rb +4 -2
  50. data/spec/kitabu/cli/stats_spec.rb +19 -15
  51. data/spec/kitabu/cli/version_spec.rb +3 -1
  52. data/spec/kitabu/exporter/css_spec.rb +3 -1
  53. data/spec/kitabu/exporter/epub_spec.rb +2 -0
  54. data/spec/kitabu/exporter/html_spec.rb +17 -4
  55. data/spec/kitabu/exporter/mobi_spec.rb +5 -5
  56. data/spec/kitabu/exporter/pdf_spec.rb +8 -4
  57. data/spec/kitabu/extensions/string_spec.rb +14 -9
  58. data/spec/kitabu/footnotes/html_spec.rb +38 -28
  59. data/spec/kitabu/generator_spec.rb +3 -1
  60. data/spec/kitabu/markdown_spec.rb +15 -3
  61. data/spec/kitabu/source_list_spec.rb +8 -2
  62. data/spec/kitabu/stats_spec.rb +10 -6
  63. data/spec/kitabu/toc/html_spec.rb +55 -35
  64. data/spec/spec_helper.rb +23 -8
  65. data/spec/support/exit_with_code.rb +7 -5
  66. data/spec/support/have_tag.rb +44 -32
  67. data/spec/support/helper.rb +5 -3
  68. data/spec/support/mybook/code/code.rb +2 -0
  69. data/spec/support/mybook/config/helper.rb +2 -0
  70. data/spec/support/mybook/fonts/OpenSans-CondBold.ttf +0 -0
  71. data/spec/support/shared.rb +12 -6
  72. data/templates/Gemfile +5 -3
  73. data/templates/Guardfile +3 -1
  74. data/templates/helper.rb +8 -6
  75. data/templates/templates/styles/epub.css +1 -0
  76. data/templates/templates/styles/files/normalize.css +351 -0
  77. data/templates/templates/styles/{html.scss → html.css} +28 -26
  78. data/templates/templates/styles/{pdf.scss → pdf.css} +49 -47
  79. data/templates/templates/styles/print.css +2 -0
  80. data/templates/text/01_Getting_Started.md +27 -9
  81. data/templates/text/02_Creating_Chapters.md +9 -3
  82. data/templates/text/{03_Syntax_Highlighting.erb → 03_Syntax_Highlighting.md.erb} +12 -7
  83. data/templates/text/04_Dynamic_Content.md.erb +48 -0
  84. data/templates/text/05_Exporting_Files.md +17 -8
  85. metadata +42 -50
  86. data/.gitmodules +0 -3
  87. data/.travis.yml +0 -18
  88. data/Gemfile.lock +0 -108
  89. data/lib/kitabu/exporter/txt.rb +0 -18
  90. data/lib/kitabu/stream.rb +0 -27
  91. data/lib/kitabu/toc.rb +0 -6
  92. data/spec/kitabu/exporter/txt_spec.rb +0 -14
  93. data/templates/ebook.png +0 -0
  94. data/templates/templates/styles/epub.scss +0 -1
  95. data/templates/templates/styles/files/_normalize.scss +0 -427
  96. data/templates/templates/styles/print.scss +0 -2
  97. data/templates/text/04_Dynamic_Content.erb +0 -64
@@ -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('text')
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(",")}}"].sort
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)) && !IGNORE_DIR.include?(File.basename(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).gsub(/\./, "").downcase
70
- File.file?(source.join(entry)) && EXTENSIONS.include?(ext) && entry !~ IGNORE_FILES
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  class Stats
3
5
  attr_reader :root_dir
@@ -15,7 +17,7 @@ module Kitabu
15
17
  end
16
18
 
17
19
  def words
18
- @words ||= text.split(" ").size
20
+ @words ||= text.split.size
19
21
  end
20
22
 
21
23
  def chapters
@@ -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
- if Dependency.pygments_rb?
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(:css => :class))
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
@@ -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
- ERB.new(template).result OpenStruct.new(:navigation => navigation).instance_eval{ binding }
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
- <<-HTML.strip_heredoc.force_encoding("utf-8")
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">
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitabu
4
+ module TOC
5
+ class HTML
6
+ class Stream
7
+ attr_accessor :listener, :content
8
+ attr_reader :html
9
+
10
+ def initialize(content, listener)
11
+ @content = content
12
+ @listener = listener
13
+ @html = Nokogiri::HTML.parse(content)
14
+ end
15
+
16
+ def parse
17
+ traverse(html)
18
+ end
19
+
20
+ def traverse(node)
21
+ node.children.each do |child|
22
+ emit(child)
23
+ traverse(child)
24
+ end
25
+ end
26
+
27
+ def emit(node)
28
+ listener.tag(node) if /h[1-6]/.match?(node.name)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -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 # :nodoc:
10
- attr_reader :attrs # :nodoc:
11
- attr_accessor :content # :nodoc:
11
+ attr_reader :buffer, :attrs
12
+ attr_accessor :content
12
13
 
13
- # Traverse every title and add a +id+ attribute.
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
- permalink = "#{permalink}-#{counter[permalink]}" if counter[permalink] > 1
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,11 +70,18 @@ module Kitabu
67
70
  # Return the table of contents in HTML format.
68
71
  #
69
72
  def to_html
70
- String.new.tap do |html|
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>]
73
+ buffer =
74
+ toc.each_with_object([]) do |options, html|
75
+ html << %[
76
+ <div class="level#{options[:level]} #{options[:permalink]}">
77
+ <a href="##{options[:permalink]}">
78
+ <span>#{CGI.escape_html(options[:text])}</span>
79
+ </a>
80
+ </div>
81
+ ]
73
82
  end
74
- end
83
+
84
+ buffer.join
75
85
  end
76
86
  end
77
87
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  module Version
3
- MAJOR = 2
5
+ MAJOR = 3
4
6
  MINOR = 0
5
- PATCH = 2
7
+ PATCH = 0
6
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
9
  end
8
10
  end
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,30 +15,24 @@ 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"
37
33
  require "kitabu/errors"
38
34
  require "kitabu/version"
39
35
  require "kitabu/generator"
40
- require "kitabu/toc"
41
36
  require "kitabu/cli"
42
37
  require "kitabu/markdown"
43
38
  require "kitabu/source_list"
@@ -47,12 +42,13 @@ module Kitabu
47
42
  require "kitabu/exporter/epub"
48
43
  require "kitabu/exporter/mobi"
49
44
  require "kitabu/exporter/pdf"
50
- require "kitabu/exporter/txt"
51
45
  require "kitabu/exporter/css"
52
46
  require "kitabu/footnotes/base"
53
47
  require "kitabu/footnotes/html"
54
48
  require "kitabu/footnotes/pdf"
55
- require "kitabu/stream"
49
+ require "kitabu/toc/html"
50
+ require "kitabu/toc/html/stream"
51
+ require "kitabu/toc/epub"
56
52
  require "kitabu/dependency"
57
53
  require "kitabu/stats"
58
54
  require "kitabu/helpers"
@@ -61,10 +57,13 @@ module Kitabu
61
57
  root_dir ||= Pathname.new(Dir.pwd)
62
58
  path = root_dir.join("config/kitabu.yml")
63
59
 
64
- raise "Invalid Kitabu directory; couldn't found config/kitabu.yml file." unless File.file?(path)
60
+ unless File.file?(path)
61
+ raise "Invalid Kitabu directory; couldn't find config/kitabu.yml file."
62
+ end
63
+
65
64
  content = File.read(path)
66
65
  erb = ERB.new(content).result
67
- YAML.load(erb).with_indifferent_access
66
+ YAML.safe_load(erb).with_indifferent_access
68
67
  end
69
68
 
70
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
@@ -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
- }.to_not raise_error
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
- }.to_not raise_error
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) { double("stats", {
24
- :chapters => 4,
25
- :words => 50,
26
- :images => 10,
27
- :footnotes => 15,
28
- :links => 20,
29
- :code_blocks => 25
30
- })}
31
-
32
- before {
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,4 +1,6 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe Kitabu::Exporter::CSS do
4
6
  let(:root) { SPECDIR.join("support/mybook") }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Kitabu::Exporter::Epub do
@@ -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: RUBY_PLATFORM.include?('darwin') do
14
+ it "generates valid markup", osx: Kitabu::Dependency.macos? do
13
15
  `./vendor/bin/tidy5_osx '#{file}' 2>&1 > /dev/null`
14
- expect($?.exitstatus).to eq(0)
16
+ expect($CHILD_STATUS.exitstatus).to eq(0)
15
17
  end
16
18
 
17
- it "generates valid markup", linux: RUBY_PLATFORM.include?('linux') do
19
+ it "generates valid markup", linux: Kitabu::Dependency.linux? do
18
20
  `./vendor/bin/tidy5_linux '#{file}' 2>&1 > /dev/null`
19
- expect($?.exitstatus).to eq(0)
21
+ expect($CHILD_STATUS.exitstatus).to eq(0)
20
22
  end
21
23
 
22
24
  it "keeps html file around" do
@@ -42,5 +44,16 @@ describe Kitabu::Exporter::HTML do
42
44
  it "renders erb blocks" do
43
45
  expect(html).to have_tag("div.note.info > p", "This is a note!")
44
46
  end
47
+
48
+ it "copies fonts" do
49
+ expect(root.join("output/fonts/OpenSans-CondBold.ttf")).to be_file
50
+ end
51
+
52
+ it "exports css files" do
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
57
+ end
45
58
  end
46
59
  end
@@ -1,14 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
- describe Kitabu::Exporter::Mobi, kindlegen: Kitabu::Dependency.kindlegen? do
4
- let(:root) { SPECDIR.join("support/mybook") }
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('html.pdf')
13
- expect(root.join("output/mybook.print.html").read).to have_tag('html.print')
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
- expect(root.join("output/mybook.print.html").read).to have_tag('link[rel=stylesheet][href="styles/print.css"]')
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
- expect(root.join("output/mybook.pdf.html").read).to have_tag('link[rel=stylesheet][href="styles/pdf.css"]')
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
- # -*- encoding: utf-8 -*-
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
- 'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title-1-well-not-really',
9
- '////// meph1sto r0x ! \\\\\\' => 'meph1sto-r0x',
10
- 'āčēģīķļņū' => 'acegiklnu',
11
- '中文測試 chinese text' => 'chinese-text',
12
- 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test',
13
- 'http://simplesideias.com.br/tags/' => 'http-simplesideias-com-br-tags',
14
- "Don't Repeat Yourself (DRY)" => 'don-t-repeat-yourself-dry',
15
- "Text\nwith\nline\n\n\tbreaks" => 'text-with-line-breaks'
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