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.
Files changed (92) 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/.rubocop.yml +17 -0
  11. data/CHANGELOG.md +13 -2
  12. data/CODE_OF_CONDUCT.md +74 -0
  13. data/CONTRIBUTING.md +79 -0
  14. data/Gemfile +2 -0
  15. data/LICENSE.md +20 -0
  16. data/README.md +103 -88
  17. data/Rakefile +7 -0
  18. data/bin/kitabu +4 -0
  19. data/kitabu.gemspec +21 -15
  20. data/lib/kitabu/cli.rb +54 -39
  21. data/lib/kitabu/dependency.rb +11 -5
  22. data/lib/kitabu/errors.rb +2 -0
  23. data/lib/kitabu/exporter/base.rb +11 -11
  24. data/lib/kitabu/exporter/css.rb +6 -15
  25. data/lib/kitabu/exporter/epub.rb +23 -17
  26. data/lib/kitabu/exporter/html.rb +27 -21
  27. data/lib/kitabu/exporter/mobi.rb +7 -1
  28. data/lib/kitabu/exporter/pdf.rb +9 -3
  29. data/lib/kitabu/exporter.rb +15 -16
  30. data/lib/kitabu/extensions/rouge.rb +6 -1
  31. data/lib/kitabu/extensions/string.rb +5 -3
  32. data/lib/kitabu/footnotes/base.rb +2 -0
  33. data/lib/kitabu/footnotes/html.rb +18 -13
  34. data/lib/kitabu/footnotes/pdf.rb +17 -11
  35. data/lib/kitabu/generator.rb +13 -8
  36. data/lib/kitabu/helpers.rb +12 -9
  37. data/lib/kitabu/markdown.rb +12 -10
  38. data/lib/kitabu/source_list.rb +15 -12
  39. data/lib/kitabu/stats.rb +3 -1
  40. data/lib/kitabu/syntax/highlight.rb +4 -11
  41. data/lib/kitabu/toc/epub.rb +5 -2
  42. data/lib/kitabu/toc/html/stream.rb +3 -1
  43. data/lib/kitabu/toc/html.rb +12 -8
  44. data/lib/kitabu/version.rb +4 -2
  45. data/lib/kitabu.rb +8 -10
  46. data/spec/kitabu/cli/export_spec.rb +6 -4
  47. data/spec/kitabu/cli/new_spec.rb +6 -4
  48. data/spec/kitabu/cli/permalinks_spec.rb +4 -2
  49. data/spec/kitabu/cli/stats_spec.rb +19 -15
  50. data/spec/kitabu/cli/version_spec.rb +3 -1
  51. data/spec/kitabu/exporter/css_spec.rb +3 -1
  52. data/spec/kitabu/exporter/epub_spec.rb +2 -0
  53. data/spec/kitabu/exporter/html_spec.rb +11 -9
  54. data/spec/kitabu/exporter/mobi_spec.rb +5 -5
  55. data/spec/kitabu/exporter/pdf_spec.rb +8 -4
  56. data/spec/kitabu/extensions/string_spec.rb +14 -9
  57. data/spec/kitabu/footnotes/html_spec.rb +35 -33
  58. data/spec/kitabu/generator_spec.rb +3 -1
  59. data/spec/kitabu/markdown_spec.rb +8 -6
  60. data/spec/kitabu/source_list_spec.rb +8 -2
  61. data/spec/kitabu/stats_spec.rb +10 -6
  62. data/spec/kitabu/toc/html_spec.rb +37 -21
  63. data/spec/spec_helper.rb +23 -8
  64. data/spec/support/exit_with_code.rb +7 -5
  65. data/spec/support/have_tag.rb +44 -32
  66. data/spec/support/helper.rb +5 -3
  67. data/spec/support/mybook/code/code.rb +2 -0
  68. data/spec/support/mybook/config/helper.rb +2 -0
  69. data/spec/support/shared.rb +8 -6
  70. data/templates/Gemfile +5 -3
  71. data/templates/Guardfile +3 -1
  72. data/templates/helper.rb +8 -6
  73. data/templates/templates/styles/epub.css +1 -0
  74. data/templates/templates/styles/files/normalize.css +351 -0
  75. data/templates/templates/styles/{html.scss → html.css} +28 -26
  76. data/templates/templates/styles/{pdf.scss → pdf.css} +49 -47
  77. data/templates/templates/styles/print.css +2 -0
  78. data/templates/text/01_Getting_Started.md +27 -9
  79. data/templates/text/02_Creating_Chapters.md +9 -3
  80. data/templates/text/{03_Syntax_Highlighting.erb → 03_Syntax_Highlighting.md.erb} +12 -7
  81. data/templates/text/04_Dynamic_Content.md.erb +48 -0
  82. data/templates/text/05_Exporting_Files.md +17 -8
  83. metadata +40 -48
  84. data/.gitmodules +0 -3
  85. data/.travis.yml +0 -18
  86. data/lib/kitabu/exporter/txt.rb +0 -18
  87. data/spec/kitabu/exporter/txt_spec.rb +0 -14
  88. data/templates/ebook.png +0 -0
  89. data/templates/templates/styles/epub.scss +0 -1
  90. data/templates/templates/styles/files/_normalize.scss +0 -427
  91. data/templates/templates/styles/print.scss +0 -2
  92. data/templates/text/04_Dynamic_Content.erb +0 -64
data/README.md CHANGED
@@ -1,25 +1,33 @@
1
1
  # kitabu
2
2
 
3
- [![Build Status](https://travis-ci.org/fnando/kitabu.svg)](https://travis-ci.org/fnando/kitabu)
4
- [![Code Climate](https://codeclimate.com/github/fnando/kitabu/badges/gpa.svg)](https://codeclimate.com/github/fnando/kitabu)
5
- [![Test Coverage](https://codeclimate.com/github/fnando/kitabu/badges/coverage.svg)](https://codeclimate.com/github/fnando/kitabu)
6
-
7
- Kitabu is a framework for creating e-books from Markdown using Ruby. Using Prince PDF generator, you'll be able to get high quality PDFs. Also supports EPUB, Mobi, Text and HTML generation.
8
-
9
- While Prince is too expensive (495USD for a single user license), the free version available at <http://www.princexml.com/download> generates a PDF with a small logo on the first page, which is removed when sent to a printer; you can use it locally for viewing the results immediately. When you're done writing your e-book, you can use [DocRaptor](http://docraptor.com), which have plans starting at $15/mo.
3
+ [![Tests](https://github.com/fnando/kitabu/workflows/ruby-tests/badge.svg)](https://github.com/fnando/kitabu)
4
+ [![Gem](https://img.shields.io/gem/v/kitabu.svg)](https://rubygems.org/gems/kitabu)
5
+ [![Gem](https://img.shields.io/gem/dt/kitabu.svg)](https://rubygems.org/gems/kitabu)
6
+ [![MIT License](https://img.shields.io/:License-MIT-blue.svg)](https://tldrlegal.com/license/mit-license)
7
+
8
+ Kitabu is a framework for creating e-books from Markdown using Ruby. Using
9
+ Prince PDF generator, you'll be able to get high quality PDFs. Also supports
10
+ EPUB, Mobi, and HTML generation.
11
+
12
+ While Prince is too expensive (495USD for a single user license), the free
13
+ version available at <http://www.princexml.com/download> generates a PDF with a
14
+ small logo on the first page, which is removed when sent to a printer; you can
15
+ use it locally for viewing the results immediately. When you're done writing
16
+ your e-book, you can use [DocRaptor](http://docraptor.com), which have plans
17
+ starting at \$15/mo.
10
18
 
11
19
  ## Features
12
20
 
13
- * Write using Markdown
14
- * Book layout support
15
- * Syntax highlight
16
- * Generate HTML, PDF, e-Pub, Mobi and Text files
17
- * Table of Contents automatically generated from chapter titles
21
+ - Write using Markdown
22
+ - Book layout support
23
+ - Syntax highlight
24
+ - Generate HTML, PDF, e-Pub, and Mobi
25
+ - Table of Contents automatically generated from chapter titles
18
26
 
19
27
  ## Installation
20
28
 
21
- To install Kitabu, you'll need a working Ruby 2.0+ installation.
22
- If you're cool with it, just run the following command to install it.
29
+ To install Kitabu, you'll need a working Ruby 2.7+ installation. If you're cool
30
+ with it, just run the following command to install it.
23
31
 
24
32
  gem install kitabu
25
33
 
@@ -31,13 +39,11 @@ dependencies.
31
39
  Prince XML: Converts HTML files into PDF files.
32
40
  Installed.
33
41
 
34
- KindleGen: Converts ePub e-books into .mobi files.
42
+ Calibre's ebook-convert: Converts ePub e-books into .mobi files.
35
43
  Installed.
36
44
 
37
- html2text: Converts HTML documents into plain text.
38
- Not installed.
39
-
40
- There are no hard requirements here; just make sure you cleared the correct dependency based on the formats you want to export to.
45
+ There are no hard requirements here; just make sure you cleared the correct
46
+ dependency based on the formats you want to export to.
41
47
 
42
48
  ## Usage
43
49
 
@@ -70,32 +76,38 @@ This command creates a directory `mybook` with the following structure:
70
76
  │   ├── html
71
77
  │   │   └── layout.erb
72
78
  │   └── styles
73
- │   ├── epub.scss
79
+ │   ├── epub.css
74
80
  │   ├── files
75
- │   │   └── _normalize.scss
76
- │   ├── html.scss
77
- │   ├── pdf.scss
78
- │   └── print.scss
81
+ │   │   └── _normalize.css
82
+ │   ├── html.css
83
+ │   ├── pdf.css
84
+ │   └── print.css
79
85
  └── text
80
86
  ├── 01_Getting_Started.md
81
87
  ├── 02_Creating_Chapters.md
82
- ├── 03_Syntax_Highlighting.erb
83
- ├── 04_Dynamic_Content.erb
88
+ ├── 03_Syntax_Highlighting.md.erb
89
+ ├── 04_Dynamic_Content.md.erb
84
90
  └── 05_Exporting_Files.md
85
91
 
86
- The `config/kitabu.yml` file holds some information about your book; so you'll always change it.
92
+ The `config/kitabu.yml` file holds some information about your book; so you'll
93
+ always change it.
87
94
 
88
95
  The generated structure is actually a good example. So make sure you try it!
89
96
 
90
- ![Kitabu - Sample Book](https://github.com/fnando/kitabu/raw/master/attachments/cover.png)
97
+ ![Kitabu - Sample Book](https://github.com/fnando/kitabu/raw/main/attachments/cover.png)
91
98
 
92
- There's a generated sample available on the [attachments directory](https://github.com/fnando/kitabu/tree/master/attachments) •
93
- [PDF](https://github.com/fnando/kitabu/raw/master/attachments/kitabu.pdf) /
94
- [EPUB](https://github.com/fnando/kitabu/raw/master/attachments/kitabu.epub) /
95
- [MOBI](https://github.com/fnando/kitabu/raw/master/attachments/kitabu.mobi) /
96
- [HTML](https://github.com/fnando/kitabu/raw/master/attachments/browser-version.png).
99
+ There's a generated sample available on the
100
+ [attachments directory](https://github.com/fnando/kitabu/tree/main/attachments)
101
+ [PDF](https://github.com/fnando/kitabu/raw/main/attachments/kitabu.pdf) /
102
+ [EPUB](https://github.com/fnando/kitabu/raw/main/attachments/kitabu.epub) /
103
+ [MOBI](https://github.com/fnando/kitabu/raw/main/attachments/kitabu.mobi) /
104
+ [HTML](https://github.com/fnando/kitabu/raw/main/attachments/browser-version.png).
97
105
 
98
- Now it's time to write your e-book. All your book content will be placed on the text directory. Kitabu requires you to separate your book into chapters. A chapter is nothing but a directory that holds lots of text files. The e-book will be generated using every folder/file alphabetically. So be sure to use a sequential numbering as the name. Here's a sample:
106
+ Now it's time to write your e-book. All your book content will be placed on the
107
+ text directory. Kitabu requires you to separate your book into chapters. A
108
+ chapter is nothing but a directory that holds lots of text files. The e-book
109
+ will be generated using every folder/file alphabetically. So be sure to use a
110
+ sequential numbering as the name. Here's a sample:
99
111
 
100
112
  * text
101
113
  * 01_Introduction
@@ -117,9 +129,12 @@ If you prefer, you can add a chapter per file:
117
129
  * 02_What_is_Ruby_on_Rails.md
118
130
  * 03_Installing_Ruby_on_Rails.md
119
131
 
120
- You'll want to see your progress eventually; it's time for you to generate the book PDF. Just run the command `kitabu export` and your book will be created on the `output` directory.
132
+ You'll want to see your progress eventually; it's time for you to generate the
133
+ book PDF. Just run the command `kitabu export` and your book will be created on
134
+ the `output` directory.
121
135
 
122
- Kitabu can generate a Table of Contents (TOC) based on your h2-h6 tags. The h1 tag is discarded because it's meant to be the book title.
136
+ Kitabu can generate a Table of Contents (TOC) based on your h2-h6 tags. The h1
137
+ tag is discarded because it's meant to be the book title.
123
138
 
124
139
  To print the TOC, you need to print a variable called `toc`, using the eRb tag.
125
140
 
@@ -127,21 +142,21 @@ To print the TOC, you need to print a variable called `toc`, using the eRb tag.
127
142
 
128
143
  ### Using ERB
129
144
 
130
- You can also have `.erb` files. You can mix Markdown and HTML, like the following:
145
+ You can also have `.md.erb` files. You can mix Markdown and HTML, like the
146
+ following:
131
147
 
132
148
  ## This the chapter title
133
149
 
134
150
  <% note do %>
135
- Make sure you try .erb files!
151
+ Make sure you try .md.erb files!
136
152
  <% end %>
137
153
 
138
- The above content must be placed in a `.erb` file. The generated content will be something like this:
154
+ The above content must be placed in a `.md.erb` file. The generated content will
155
+ be something like this:
139
156
 
140
157
  ```html
141
158
  <div class="note info">
142
- <p>
143
- Make sure you try .erb files!
144
- </p>
159
+ <p>Make sure you try .md.erb files!</p>
145
160
  </div>
146
161
  ```
147
162
 
@@ -153,7 +168,8 @@ The `note` helper is built-in and can accept a different note type.
153
168
  <% end %>
154
169
  ```
155
170
 
156
- You can see available helpers on <https://github.com/fnando/kitabu/blob/master/lib/kitabu/markdown.rb>.
171
+ You can see available helpers on
172
+ <https://github.com/fnando/kitabu/blob/main/lib/kitabu/markdown.rb>.
157
173
 
158
174
  ### Syntax Highlighting
159
175
 
@@ -172,33 +188,36 @@ You can even provide options:
172
188
  echo "Hello World";
173
189
  ```
174
190
 
175
- - We use [Redcarpet](https://rubygems.org/gems/redcarpet) for Markdown processing.
191
+ - We use [Redcarpet](https://rubygems.org/gems/redcarpet) for Markdown
192
+ processing.
176
193
  - We use [Rouge](https://rubygems.org/gems/rouge) for syntax highlighting.
177
194
 
178
195
  The following Redcarpet options are enabled:
179
196
 
180
- * `autolink`
181
- * `fenced_code_blocks`
182
- * `footnotes`
183
- * `hard_wrap`
184
- * `highlight`
185
- * `no_intra_emphasis`
186
- * `safe_links_only`
187
- * `space_after_headers`
188
- * `strikethrough`
189
- * `superscript`
190
- * `tables`
197
+ - `autolink`
198
+ - `fenced_code_blocks`
199
+ - `footnotes`
200
+ - `hard_wrap`
201
+ - `highlight`
202
+ - `no_intra_emphasis`
203
+ - `safe_links_only`
204
+ - `space_after_headers`
205
+ - `strikethrough`
206
+ - `superscript`
207
+ - `tables`
191
208
 
192
209
  ### Using custom fonts
193
210
 
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).
211
+ You can use custom fonts for your PDF. Just add them to the `fonts` directory
212
+ (you can create this directory on your book's root directory if it doesn't
213
+ exist).
195
214
 
196
- Then, on `templates/styles/pdf.scss` you can add the `@font-face` declaration.
215
+ Then, on `templates/styles/pdf.css` you can add the `@font-face` declaration.
197
216
 
198
217
  ```css
199
218
  @font-face {
200
- font-family: 'Open Sans Condensed Bold';
201
- src: url('../fonts/OpenSans-CondBold.ttf');
219
+ font-family: "Open Sans Condensed Bold";
220
+ src: url("../../fonts/OpenSans-CondBold.ttf");
202
221
  }
203
222
  ```
204
223
 
@@ -206,24 +225,23 @@ Finally, to use this font, do something like this:
206
225
 
207
226
  ```css
208
227
  .chapter > h2 {
209
- font-family: 'Open Sans Condensed Bold';
228
+ font-family: "Open Sans Condensed Bold";
210
229
  }
211
230
  ```
212
231
 
213
232
  ## References
214
233
 
215
- * Markdown: <http://daringfireball.net/projects/markdown/syntax>
216
- * Markdown PHP: <https://michelf.ca/projects/php-markdown/extra/>
234
+ - Markdown: <http://daringfireball.net/projects/markdown/syntax>
235
+ - Markdown PHP: <https://michelf.ca/projects/php-markdown/extra/>
217
236
 
218
237
  ## Legal Notes
219
238
 
220
- * KindleGen: [license](http://www.amazon.com/gp/feature.html?docId=1000599251).
221
- * PrinceXML: [license](http://www.princexml.com/license/)
239
+ - PrinceXML: [license](http://www.princexml.com/license/)
222
240
 
223
241
  Alternatives:
224
242
 
225
- - If you're planning to to sell your e-book, consider using [Calibre](http://calibre-ebook.com/) to convert from `.epub` to `.mobi`.
226
- - If you're not planning to buy PrinceXML, consider using [DocRaptor](http://docraptor.com). Here's how you can easily do it:
243
+ - If you're not planning to buy PrinceXML, consider using
244
+ [DocRaptor](http://docraptor.com). Here's how you can easily do it:
227
245
 
228
246
  ```bash
229
247
  curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_CREDENTIALS_HERE", "doc":{"name":"kitabu.pdf", "document_type":"pdf", "test":"false", "document_url":"https://dl.dropboxusercontent.com/u/123456789/output/kitabu.pdf.html"}}' http://docraptor.com/docs > kitabu.pdf
@@ -231,28 +249,25 @@ curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_CREDENTIALS
231
249
 
232
250
  ## Maintainer
233
251
 
234
- * [Nando Vieira](http://nandovieira.com.br)
235
- * [Jesse Storimer](http://jstorimer.com)
252
+ - [Nando Vieira](https://github.com/fnando)
253
+
254
+ ## Contributors
255
+
256
+ - https://github.com/fnando/kitabu/contributors
257
+
258
+ ## Contributing
259
+
260
+ For more details about how to contribute, please read
261
+ https://github.com/fnando/kitabu/blob/main/CONTRIBUTING.md.
236
262
 
237
263
  ## License
238
264
 
239
- (The MIT License)
240
-
241
- Permission is hereby granted, free of charge, to any person obtaining
242
- a copy of this software and associated documentation files (the
243
- 'Software'), to deal in the Software without restriction, including
244
- without limitation the rights to use, copy, modify, merge, publish,
245
- distribute, sublicense, and/or sell copies of the Software, and to
246
- permit persons to whom the Software is furnished to do so, subject to
247
- the following conditions:
248
-
249
- The above copyright notice and this permission notice shall be
250
- included in all copies or substantial portions of the Software.
251
-
252
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
253
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
254
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
255
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
256
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
257
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
258
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
265
+ The gem is available as open source under the terms of the
266
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
267
+ found at https://github.com/fnando/kitabu/blob/main/LICENSE.md.
268
+
269
+ ## Code of Conduct
270
+
271
+ Everyone interacting in the kitabu project's codebases, issue trackers, chat
272
+ rooms and mailing lists is expected to follow the
273
+ [code of conduct](https://github.com/fnando/kitabu/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler"
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
6
  require "rspec/core/rake_task"
5
7
  RSpec::Core::RakeTask.new
8
+
9
+ require "rubocop/rake_task"
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/kitabu CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # -*- mode: ruby -*-
3
5
 
6
+ $LOAD_PATH.unshift File.expand_path(File.join(__dir__, "../lib"))
7
+
4
8
  require "kitabu"
5
9
  Kitabu::Cli.start
data/kitabu.gemspec CHANGED
@@ -1,39 +1,45 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
3
4
  require "kitabu/version"
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = "kitabu"
7
8
  s.version = Kitabu::Version::STRING
8
9
  s.platform = Gem::Platform::RUBY
9
- s.required_ruby_version = ">= 2.0"
10
10
  s.authors = ["Nando Vieira"]
11
11
  s.email = ["fnando.vieira@gmail.com"]
12
12
  s.homepage = "http://rubygems.org/gems/kitabu"
13
- s.summary = "A framework for creating e-books from Markdown using Ruby. Using the Prince PDF generator, you'll be able to get high quality PDFs. Also supports EPUB, Mobi, Text and HTML generation."
13
+ s.summary = "A framework for creating e-books from Markdown " \
14
+ "using Ruby. Using the Prince PDF generator, " \
15
+ "you'll be able to get high quality PDFs. Also " \
16
+ "supports EPUB, Mobi, Text and HTML generation."
14
17
  s.description = s.summary
15
18
  s.license = "MIT"
19
+ s.required_ruby_version = ">= 2.7"
20
+ s.metadata = {"rubygems_mfa_required" => "true"}
16
21
 
17
22
  s.files = `git ls-files`.split("\n")
18
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
25
+ File.basename(f)
26
+ end
20
27
  s.require_paths = ["lib"]
21
28
 
22
29
  s.add_dependency "activesupport"
23
- s.add_dependency "nokogiri"
30
+ s.add_dependency "eeepub-with-cover-support"
24
31
  s.add_dependency "i18n"
25
- s.add_dependency "thor"
32
+ s.add_dependency "nokogiri"
26
33
  s.add_dependency "redcarpet"
27
- s.add_dependency "eeepub-with-cover-support"
28
- s.add_dependency "rouge", "~> 2.0"
29
- s.add_dependency "notifier"
34
+ s.add_dependency "rouge"
30
35
  s.add_dependency "rubyzip"
36
+ s.add_dependency "thor"
31
37
  s.add_dependency "zip-zip"
32
- s.add_dependency "sass"
33
- s.add_dependency "sass-globbing"
34
38
 
35
- s.add_development_dependency "rspec"
36
- s.add_development_dependency "rake"
37
39
  s.add_development_dependency "pry-meta"
38
- s.add_development_dependency "codeclimate-test-reporter"
40
+ s.add_development_dependency "rake"
41
+ s.add_development_dependency "rspec"
42
+ s.add_development_dependency "rubocop"
43
+ s.add_development_dependency "rubocop-fnando"
44
+ s.add_development_dependency "simplecov"
39
45
  end
data/lib/kitabu/cli.rb CHANGED
@@ -1,7 +1,8 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  module Kitabu
3
4
  class Cli < Thor
4
- FORMATS = %w[pdf html epub mobi txt]
5
+ FORMATS = %w[pdf html epub mobi].freeze
5
6
  check_unknown_options!
6
7
 
7
8
  def self.exit_on_failure?
@@ -9,8 +10,14 @@ module Kitabu
9
10
  end
10
11
 
11
12
  def initialize(args = [], options = {}, config = {})
12
- if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
13
- raise Error, "The e-Book path is required. For details run: kitabu help new"
13
+ has_no_args = (
14
+ config[:current_task] ||
15
+ config[:current_command]
16
+ ).name == "new" && args.empty?
17
+
18
+ if has_no_args
19
+ raise Error,
20
+ "The e-Book path is required. For details run: kitabu help new"
14
21
  end
15
22
 
16
23
  super
@@ -25,12 +32,16 @@ module Kitabu
25
32
  end
26
33
 
27
34
  desc "export [OPTIONS]", "Export e-book"
28
- method_option :only, :type => :string, :desc => "Can be one of: #{FORMATS.join(", ")}"
29
- method_option :open, :type => :boolean, :desc => "Automatically open PDF (Preview.app for Mac OS X and xdg-open for Linux)"
35
+ method_option :only, type: :string,
36
+ desc: "Can be one of: #{FORMATS.join(', ')}"
37
+ method_option :open, type: :boolean,
38
+ desc: "Automatically open PDF (Preview.app for " \
39
+ "Mac OS X and xdg-open for Linux)"
30
40
 
31
41
  def export
32
42
  if options[:only] && !FORMATS.include?(options[:only])
33
- raise Error, "The --only option need to be one of: #{FORMATS.join(", ")}"
43
+ raise Error,
44
+ "The --only option need to be one of: #{FORMATS.join(', ')}"
34
45
  end
35
46
 
36
47
  inside_ebook!
@@ -39,7 +50,7 @@ module Kitabu
39
50
  end
40
51
 
41
52
  desc "version", "Prints the Kitabu's version information"
42
- map %w(-v --version) => :version
53
+ map %w[-v --version] => :version
43
54
 
44
55
  def version
45
56
  say "Kitabu version #{Version::STRING}"
@@ -51,24 +62,26 @@ module Kitabu
51
62
  result = []
52
63
 
53
64
  result << {
54
- :description => "Prince XML: Converts HTML files into PDF files.",
55
- :installed => Kitabu::Dependency.prince?
65
+ description: "Prince XML: Converts HTML files into PDF files.",
66
+ installed: Kitabu::Dependency.prince?
56
67
  }
57
68
 
58
69
  result << {
59
- :description => "KindleGen: Converts ePub e-books into .mobi files.",
60
- :installed => Kitabu::Dependency.kindlegen?
70
+ description: "Calibre's ebook-convert: Converts ePub e-books into " \
71
+ ".mobi files.",
72
+ installed: Kitabu::Dependency.calibre?
61
73
  }
62
74
 
63
- result << {
64
- :description => "html2text: Converts HTML documents into plain text.",
65
- :installed => Kitabu::Dependency.html2text?
66
- }
75
+ result.each do |info|
76
+ state = if info[:installed]
77
+ color("Installed.", :green)
78
+ else
79
+ color("Not installed.", :red)
80
+ end
67
81
 
68
- result.each do |result|
69
- text = color(result[:name], :blue)
70
- text << "\n" << result[:description]
71
- text << "\n" << (result[:installed] ? color("Installed.", :green) : color("Not installed.", :red))
82
+ text = color(info[:name], :blue)
83
+ text << "\n" << info[:description]
84
+ text << "\n" << state
72
85
  text << "\n"
73
86
 
74
87
  say(text)
@@ -110,31 +123,33 @@ module Kitabu
110
123
  ].join("\n")
111
124
  end
112
125
 
113
- private
114
- def inside_ebook!
115
- unless File.exist?(config_path)
116
- raise Error, "You have to run this command from inside an e-book directory."
126
+ no_commands do
127
+ def inside_ebook!
128
+ return if File.exist?(config_path)
129
+
130
+ raise Error,
131
+ "You have to run this command from inside an e-book directory."
117
132
  end
118
- end
119
133
 
120
- def config
121
- YAML.load_file(config_path).with_indifferent_access
122
- end
134
+ def config
135
+ YAML.load_file(config_path).with_indifferent_access
136
+ end
123
137
 
124
- def config_path
125
- root_dir.join("config/kitabu.yml")
126
- end
138
+ def config_path
139
+ root_dir.join("config/kitabu.yml")
140
+ end
127
141
 
128
- def root_dir
129
- @root ||= Pathname.new(Dir.pwd)
130
- end
142
+ def root_dir
143
+ @root_dir ||= Pathname.new(Dir.pwd)
144
+ end
131
145
 
132
- def color(text, color)
133
- color? ? shell.set_color(text, color) : text
134
- end
146
+ def color(text, color)
147
+ color? ? shell.set_color(text, color) : text
148
+ end
135
149
 
136
- def color?
137
- shell.instance_of?(Thor::Shell::Color)
150
+ def color?
151
+ shell.instance_of?(Thor::Shell::Color)
152
+ end
138
153
  end
139
154
  end
140
155
  end
@@ -1,15 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  class Dependency
3
- def self.kindlegen?
4
- @kindlegen ||= `which kindlegen` && $?.success?
5
+ def self.calibre?
6
+ @calibre ||= `which ebook-convert` && $CHILD_STATUS.success?
5
7
  end
6
8
 
7
9
  def self.prince?
8
- @prince ||= `which prince` && $?.success?
10
+ @prince ||= `which prince` && $CHILD_STATUS.success?
11
+ end
12
+
13
+ def self.linux?
14
+ RUBY_PLATFORM.include?("linux")
9
15
  end
10
16
 
11
- def self.html2text?
12
- @html2text ||= `which html2text` && $?.success?
17
+ def self.macos?
18
+ RUBY_PLATFORM.include?("darwin")
13
19
  end
14
20
  end
15
21
  end
data/lib/kitabu/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  class DirectoryAlreadyCreatedError < StandardError; end
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  class Exporter
3
5
  class Base
@@ -18,8 +20,6 @@ module Kitabu
18
20
  @source = root_dir.join("text")
19
21
  end
20
22
 
21
- #
22
- #
23
23
  def source_list
24
24
  @source_list ||= SourceList.new(root_dir)
25
25
  end
@@ -40,18 +40,18 @@ module Kitabu
40
40
  #
41
41
  def render_template(file, locals = {})
42
42
  context = OpenStruct.new(locals).extend(Helpers)
43
- ERB.new(File.read(file), 0, "%<>", "@_output").result context.instance_eval { binding }
43
+ data = context.instance_eval { binding }
44
+ ERB.new(File.read(file), trim_mode: "%<>",
45
+ eoutvar: "@_output").result(data)
44
46
  end
45
47
 
46
48
  def spawn_command(command)
47
- begin
48
- stdout_and_stderr, status = Open3.capture2e(*command)
49
- rescue Errno::ENOENT => e
50
- puts e.message
51
- else
52
- puts stdout_and_stderr unless status.success?
53
- status.success?
54
- end
49
+ stdout_and_stderr, status = Open3.capture2e(*command)
50
+ rescue Errno::ENOENT => error
51
+ puts error.message
52
+ else
53
+ puts stdout_and_stderr unless status.success?
54
+ status.success?
55
55
  end
56
56
 
57
57
  def ui
@@ -1,24 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  class Exporter
3
5
  class CSS < Base
4
6
  attr_reader :root_dir
5
7
 
6
8
  def export
7
- files = Dir[root_dir.join("templates/styles/*.{scss,sass}").to_s]
8
-
9
- options = {
10
- style: :expanded,
11
- line_numbers: true,
12
- load_paths: [root_dir.join("templates/styles")]
13
- }
14
-
15
- files.each do |file|
16
- _, file_name, syntax = *File.basename(file).match(/(.*?)\.(.*?)$/)
17
- engine = Sass::Engine.new(File.read(file), options.merge(syntax: syntax.to_sym))
18
- target = root_dir.join("output/styles", "#{file_name}.css")
19
- FileUtils.mkdir_p(File.dirname(target))
20
- File.open(target, "w") {|io| io << engine.render }
21
- end
9
+ FileUtils.cp_r(
10
+ root_dir.join("templates/styles").to_s,
11
+ root_dir.join("output/styles").to_s
12
+ )
22
13
  end
23
14
  end
24
15
  end