kitabu 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/.gitignore +1 -0
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +34 -1
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +2 -0
- data/LICENSE.md +20 -0
- data/README.md +121 -85
- data/Rakefile +7 -0
- data/bin/kitabu +4 -0
- data/kitabu.gemspec +20 -14
- 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 +13 -11
- data/lib/kitabu/exporter/css.rb +6 -14
- data/lib/kitabu/exporter/epub.rb +24 -18
- data/lib/kitabu/exporter/html.rb +33 -20
- 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 +7 -1
- data/lib/kitabu/extensions/string.rb +5 -3
- data/lib/kitabu/footnotes/base.rb +2 -0
- data/lib/kitabu/footnotes/html.rb +19 -12
- data/lib/kitabu/footnotes/pdf.rb +17 -11
- data/lib/kitabu/generator.rb +16 -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 +33 -0
- data/lib/kitabu/toc/html.rb +19 -9
- data/lib/kitabu/version.rb +4 -2
- data/lib/kitabu.rb +11 -12
- 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 +17 -4
- 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 +38 -28
- data/spec/kitabu/generator_spec.rb +3 -1
- data/spec/kitabu/markdown_spec.rb +15 -3
- data/spec/kitabu/source_list_spec.rb +8 -2
- data/spec/kitabu/stats_spec.rb +10 -6
- data/spec/kitabu/toc/html_spec.rb +55 -35
- 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/mybook/fonts/OpenSans-CondBold.ttf +0 -0
- data/spec/support/shared.rb +12 -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 +42 -50
- data/.gitmodules +0 -3
- data/.travis.yml +0 -18
- data/Gemfile.lock +0 -108
- data/lib/kitabu/exporter/txt.rb +0 -18
- data/lib/kitabu/stream.rb +0 -27
- data/lib/kitabu/toc.rb +0 -6
- 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/README.md
CHANGED
@@ -1,25 +1,33 @@
|
|
1
1
|
# kitabu
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.
|
22
|
-
|
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
|
-
|
42
|
+
Calibre's ebook-convert: Converts ePub e-books into .mobi files.
|
35
43
|
Installed.
|
36
44
|
|
37
|
-
|
38
|
-
|
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.
|
79
|
+
│ ├── epub.css
|
74
80
|
│ ├── files
|
75
|
-
│ │ └── _normalize.
|
76
|
-
│ ├── html.
|
77
|
-
│ ├── pdf.
|
78
|
-
│ └── print.
|
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
|
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/
|
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
|
93
|
-
[
|
94
|
-
[
|
95
|
-
[
|
96
|
-
[
|
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
|
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,31 +129,34 @@ 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
|
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
|
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
|
|
126
141
|
<%= toc %>
|
127
142
|
|
128
|
-
|
143
|
+
### Using ERB
|
129
144
|
|
130
|
-
You can also have `.erb` files. You can mix Markdown and HTML, like the
|
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
|
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
|
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,37 +188,60 @@ 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
|
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
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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`
|
208
|
+
|
209
|
+
### Using custom fonts
|
210
|
+
|
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).
|
214
|
+
|
215
|
+
Then, on `templates/styles/pdf.css` you can add the `@font-face` declaration.
|
216
|
+
|
217
|
+
```css
|
218
|
+
@font-face {
|
219
|
+
font-family: "Open Sans Condensed Bold";
|
220
|
+
src: url("../../fonts/OpenSans-CondBold.ttf");
|
221
|
+
}
|
222
|
+
```
|
223
|
+
|
224
|
+
Finally, to use this font, do something like this:
|
225
|
+
|
226
|
+
```css
|
227
|
+
.chapter > h2 {
|
228
|
+
font-family: "Open Sans Condensed Bold";
|
229
|
+
}
|
230
|
+
```
|
191
231
|
|
192
|
-
|
232
|
+
## References
|
193
233
|
|
194
|
-
|
195
|
-
|
234
|
+
- Markdown: <http://daringfireball.net/projects/markdown/syntax>
|
235
|
+
- Markdown PHP: <https://michelf.ca/projects/php-markdown/extra/>
|
196
236
|
|
197
237
|
## Legal Notes
|
198
238
|
|
199
|
-
|
200
|
-
* PrinceXML: [license](http://www.princexml.com/license/)
|
239
|
+
- PrinceXML: [license](http://www.princexml.com/license/)
|
201
240
|
|
202
241
|
Alternatives:
|
203
242
|
|
204
|
-
- If you're planning to
|
205
|
-
|
243
|
+
- If you're not planning to buy PrinceXML, consider using
|
244
|
+
[DocRaptor](http://docraptor.com). Here's how you can easily do it:
|
206
245
|
|
207
246
|
```bash
|
208
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
|
@@ -210,28 +249,25 @@ curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_CREDENTIALS
|
|
210
249
|
|
211
250
|
## Maintainer
|
212
251
|
|
213
|
-
|
214
|
-
|
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.
|
215
262
|
|
216
263
|
## License
|
217
264
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
The above copyright notice and this permission notice shall be
|
229
|
-
included in all copies or substantial portions of the Software.
|
230
|
-
|
231
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
232
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
233
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
234
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
235
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
236
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
237
|
-
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
data/bin/kitabu
CHANGED
data/kitabu.gemspec
CHANGED
@@ -1,39 +1,45 @@
|
|
1
|
-
#
|
2
|
-
|
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
|
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
|
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 "
|
30
|
+
s.add_dependency "eeepub-with-cover-support"
|
24
31
|
s.add_dependency "i18n"
|
25
|
-
s.add_dependency "
|
32
|
+
s.add_dependency "nokogiri"
|
26
33
|
s.add_dependency "redcarpet"
|
27
|
-
s.add_dependency "eeepub-with-cover-support"
|
28
34
|
s.add_dependency "rouge"
|
29
|
-
s.add_dependency "notifier"
|
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 "
|
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
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Kitabu
|
3
4
|
class Cli < Thor
|
4
|
-
FORMATS = %w[pdf html epub mobi
|
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
|
-
|
13
|
-
|
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, :
|
29
|
-
|
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,
|
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
|
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
|
-
:
|
55
|
-
:
|
65
|
+
description: "Prince XML: Converts HTML files into PDF files.",
|
66
|
+
installed: Kitabu::Dependency.prince?
|
56
67
|
}
|
57
68
|
|
58
69
|
result << {
|
59
|
-
:
|
60
|
-
|
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
|
-
|
65
|
-
|
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
|
-
|
69
|
-
text
|
70
|
-
text << "\n" <<
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
134
|
+
def config
|
135
|
+
YAML.load_file(config_path).with_indifferent_access
|
136
|
+
end
|
123
137
|
|
124
|
-
|
125
|
-
|
126
|
-
|
138
|
+
def config_path
|
139
|
+
root_dir.join("config/kitabu.yml")
|
140
|
+
end
|
127
141
|
|
128
|
-
|
129
|
-
|
130
|
-
|
142
|
+
def root_dir
|
143
|
+
@root_dir ||= Pathname.new(Dir.pwd)
|
144
|
+
end
|
131
145
|
|
132
|
-
|
133
|
-
|
134
|
-
|
146
|
+
def color(text, color)
|
147
|
+
color? ? shell.set_color(text, color) : text
|
148
|
+
end
|
135
149
|
|
136
|
-
|
137
|
-
|
150
|
+
def color?
|
151
|
+
shell.instance_of?(Thor::Shell::Color)
|
152
|
+
end
|
138
153
|
end
|
139
154
|
end
|
140
155
|
end
|
data/lib/kitabu/dependency.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kitabu
|
2
4
|
class Dependency
|
3
|
-
def self.
|
4
|
-
@
|
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` &&
|
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.
|
12
|
-
|
17
|
+
def self.macos?
|
18
|
+
RUBY_PLATFORM.include?("darwin")
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/kitabu/errors.rb
CHANGED
data/lib/kitabu/exporter/base.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
@@ -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
|
|
data/lib/kitabu/exporter/css.rb
CHANGED
@@ -1,23 +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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
load_paths: [root_dir.join("templates/styles")]
|
12
|
-
}
|
13
|
-
|
14
|
-
files.each do |file|
|
15
|
-
_, file_name, syntax = *File.basename(file).match(/(.*?)\.(.*?)$/)
|
16
|
-
engine = Sass::Engine.new(File.read(file), options.merge(syntax: syntax.to_sym))
|
17
|
-
target = root_dir.join("output/styles", "#{file_name}.css")
|
18
|
-
FileUtils.mkdir_p(File.dirname(target))
|
19
|
-
File.open(target, "w") {|io| io << engine.render }
|
20
|
-
end
|
9
|
+
FileUtils.cp_r(
|
10
|
+
root_dir.join("templates/styles").to_s,
|
11
|
+
root_dir.join("output/styles").to_s
|
12
|
+
)
|
21
13
|
end
|
22
14
|
end
|
23
15
|
end
|