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/templates/helper.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitabu
2
4
  module Helpers
3
5
  def lexers_list
4
- buffer = '<ul class="lexers">'
6
+ buffer = [%[<ul class="lexers">]]
5
7
 
6
8
  Rouge::Lexers.constants.each do |const|
7
9
  lexer = Rouge::Lexers.const_get(const)
@@ -10,19 +12,19 @@ module Kitabu
10
12
  title = lexer.title
11
13
  tag = lexer.tag
12
14
  description = lexer.desc
13
- rescue Exception => e
15
+ rescue StandardError
14
16
  next
15
17
  end
16
18
 
17
- buffer << '<li>'
19
+ buffer << "<li>"
18
20
  buffer << "<strong>#{title}</strong> "
19
21
  buffer << "<code>#{tag}</code><br>"
20
22
  buffer << "<span>#{description}</span>"
21
- buffer << '</li>'
23
+ buffer << "</li>"
22
24
  end
23
25
 
24
- buffer << '</ul>'
25
- buffer
26
+ buffer << "</ul>"
27
+ buffer.join
26
28
  end
27
29
  end
28
30
  end
@@ -0,0 +1 @@
1
+ @import "./files/normalize.css";
@@ -0,0 +1,351 @@
1
+ /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
2
+
3
+ /* Document
4
+ ========================================================================== */
5
+
6
+ /**
7
+ * 1. Correct the line height in all browsers.
8
+ * 2. Prevent adjustments of font size after orientation changes in iOS.
9
+ */
10
+
11
+ html {
12
+ line-height: 1.15; /* 1 */
13
+ -webkit-text-size-adjust: 100%; /* 2 */
14
+ }
15
+
16
+ /* Sections
17
+ ========================================================================== */
18
+
19
+ /**
20
+ * Remove the margin in all browsers.
21
+ */
22
+
23
+ body {
24
+ margin: 0;
25
+ }
26
+
27
+ /**
28
+ * Render the `main` element consistently in IE.
29
+ */
30
+
31
+ main {
32
+ display: block;
33
+ }
34
+
35
+ /**
36
+ * Correct the font size and margin on `h1` elements within `section` and
37
+ * `article` contexts in Chrome, Firefox, and Safari.
38
+ */
39
+
40
+ h1 {
41
+ font-size: 2em;
42
+ margin: 0.67em 0;
43
+ }
44
+
45
+ /* Grouping content
46
+ ========================================================================== */
47
+
48
+ /**
49
+ * 1. Add the correct box sizing in Firefox.
50
+ * 2. Show the overflow in Edge and IE.
51
+ */
52
+
53
+ hr {
54
+ box-sizing: content-box; /* 1 */
55
+ height: 0; /* 1 */
56
+ overflow: visible; /* 2 */
57
+ }
58
+
59
+ /**
60
+ * 1. Correct the inheritance and scaling of font size in all browsers.
61
+ * 2. Correct the odd `em` font sizing in all browsers.
62
+ */
63
+
64
+ pre {
65
+ font-family: monospace, monospace; /* 1 */
66
+ font-size: 1em; /* 2 */
67
+ }
68
+
69
+ /* Text-level semantics
70
+ ========================================================================== */
71
+
72
+ /**
73
+ * Remove the gray background on active links in IE 10.
74
+ */
75
+
76
+ a {
77
+ background-color: transparent;
78
+ }
79
+
80
+ /**
81
+ * 1. Remove the bottom border in Chrome 57-
82
+ * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
83
+ */
84
+
85
+ abbr[title] {
86
+ border-bottom: none; /* 1 */
87
+ text-decoration: underline; /* 2 */
88
+ text-decoration: underline dotted; /* 2 */
89
+ }
90
+
91
+ /**
92
+ * Add the correct font weight in Chrome, Edge, and Safari.
93
+ */
94
+
95
+ b,
96
+ strong {
97
+ font-weight: bolder;
98
+ }
99
+
100
+ /**
101
+ * 1. Correct the inheritance and scaling of font size in all browsers.
102
+ * 2. Correct the odd `em` font sizing in all browsers.
103
+ */
104
+
105
+ code,
106
+ kbd,
107
+ samp {
108
+ font-family: monospace, monospace; /* 1 */
109
+ font-size: 1em; /* 2 */
110
+ }
111
+
112
+ /**
113
+ * Add the correct font size in all browsers.
114
+ */
115
+
116
+ small {
117
+ font-size: 80%;
118
+ }
119
+
120
+ /**
121
+ * Prevent `sub` and `sup` elements from affecting the line height in
122
+ * all browsers.
123
+ */
124
+
125
+ sub,
126
+ sup {
127
+ font-size: 75%;
128
+ line-height: 0;
129
+ position: relative;
130
+ vertical-align: baseline;
131
+ }
132
+
133
+ sub {
134
+ bottom: -0.25em;
135
+ }
136
+
137
+ sup {
138
+ top: -0.5em;
139
+ }
140
+
141
+ /* Embedded content
142
+ ========================================================================== */
143
+
144
+ /**
145
+ * Remove the border on images inside links in IE 10.
146
+ */
147
+
148
+ img {
149
+ border-style: none;
150
+ }
151
+
152
+ /* Forms
153
+ ========================================================================== */
154
+
155
+ /**
156
+ * 1. Change the font styles in all browsers.
157
+ * 2. Remove the margin in Firefox and Safari.
158
+ */
159
+
160
+ button,
161
+ input,
162
+ optgroup,
163
+ select,
164
+ textarea {
165
+ font-family: inherit; /* 1 */
166
+ font-size: 100%; /* 1 */
167
+ line-height: 1.15; /* 1 */
168
+ margin: 0; /* 2 */
169
+ }
170
+
171
+ /**
172
+ * Show the overflow in IE.
173
+ * 1. Show the overflow in Edge.
174
+ */
175
+
176
+ button,
177
+ input {
178
+ /* 1 */
179
+ overflow: visible;
180
+ }
181
+
182
+ /**
183
+ * Remove the inheritance of text transform in Edge, Firefox, and IE.
184
+ * 1. Remove the inheritance of text transform in Firefox.
185
+ */
186
+
187
+ button,
188
+ select {
189
+ /* 1 */
190
+ text-transform: none;
191
+ }
192
+
193
+ /**
194
+ * Correct the inability to style clickable types in iOS and Safari.
195
+ */
196
+
197
+ button,
198
+ [type="button"],
199
+ [type="reset"],
200
+ [type="submit"] {
201
+ -webkit-appearance: button;
202
+ }
203
+
204
+ /**
205
+ * Remove the inner border and padding in Firefox.
206
+ */
207
+
208
+ button::-moz-focus-inner,
209
+ [type="button"]::-moz-focus-inner,
210
+ [type="reset"]::-moz-focus-inner,
211
+ [type="submit"]::-moz-focus-inner {
212
+ border-style: none;
213
+ padding: 0;
214
+ }
215
+
216
+ /**
217
+ * Restore the focus styles unset by the previous rule.
218
+ */
219
+
220
+ button:-moz-focusring,
221
+ [type="button"]:-moz-focusring,
222
+ [type="reset"]:-moz-focusring,
223
+ [type="submit"]:-moz-focusring {
224
+ outline: 1px dotted ButtonText;
225
+ }
226
+
227
+ /**
228
+ * Correct the padding in Firefox.
229
+ */
230
+
231
+ fieldset {
232
+ padding: 0.35em 0.75em 0.625em;
233
+ }
234
+
235
+ /**
236
+ * 1. Correct the text wrapping in Edge and IE.
237
+ * 2. Correct the color inheritance from `fieldset` elements in IE.
238
+ * 3. Remove the padding so developers are not caught out when they zero out
239
+ * `fieldset` elements in all browsers.
240
+ */
241
+
242
+ legend {
243
+ box-sizing: border-box; /* 1 */
244
+ color: inherit; /* 2 */
245
+ display: table; /* 1 */
246
+ max-width: 100%; /* 1 */
247
+ padding: 0; /* 3 */
248
+ white-space: normal; /* 1 */
249
+ }
250
+
251
+ /**
252
+ * Add the correct vertical alignment in Chrome, Firefox, and Opera.
253
+ */
254
+
255
+ progress {
256
+ vertical-align: baseline;
257
+ }
258
+
259
+ /**
260
+ * Remove the default vertical scrollbar in IE 10+.
261
+ */
262
+
263
+ textarea {
264
+ overflow: auto;
265
+ }
266
+
267
+ /**
268
+ * 1. Add the correct box sizing in IE 10.
269
+ * 2. Remove the padding in IE 10.
270
+ */
271
+
272
+ [type="checkbox"],
273
+ [type="radio"] {
274
+ box-sizing: border-box; /* 1 */
275
+ padding: 0; /* 2 */
276
+ }
277
+
278
+ /**
279
+ * Correct the cursor style of increment and decrement buttons in Chrome.
280
+ */
281
+
282
+ [type="number"]::-webkit-inner-spin-button,
283
+ [type="number"]::-webkit-outer-spin-button {
284
+ height: auto;
285
+ }
286
+
287
+ /**
288
+ * 1. Correct the odd appearance in Chrome and Safari.
289
+ * 2. Correct the outline style in Safari.
290
+ */
291
+
292
+ [type="search"] {
293
+ -webkit-appearance: textfield; /* 1 */
294
+ outline-offset: -2px; /* 2 */
295
+ }
296
+
297
+ /**
298
+ * Remove the inner padding in Chrome and Safari on macOS.
299
+ */
300
+
301
+ [type="search"]::-webkit-search-decoration {
302
+ -webkit-appearance: none;
303
+ }
304
+
305
+ /**
306
+ * 1. Correct the inability to style clickable types in iOS and Safari.
307
+ * 2. Change font properties to `inherit` in Safari.
308
+ */
309
+
310
+ ::-webkit-file-upload-button {
311
+ -webkit-appearance: button; /* 1 */
312
+ font: inherit; /* 2 */
313
+ }
314
+
315
+ /* Interactive
316
+ ========================================================================== */
317
+
318
+ /*
319
+ * Add the correct display in Edge, IE 10+, and Firefox.
320
+ */
321
+
322
+ details {
323
+ display: block;
324
+ }
325
+
326
+ /*
327
+ * Add the correct display in all browsers.
328
+ */
329
+
330
+ summary {
331
+ display: list-item;
332
+ }
333
+
334
+ /* Misc
335
+ ========================================================================== */
336
+
337
+ /**
338
+ * Add the correct display in IE 10+.
339
+ */
340
+
341
+ template {
342
+ display: none;
343
+ }
344
+
345
+ /**
346
+ * Add the correct display in IE 10.
347
+ */
348
+
349
+ [hidden] {
350
+ display: none;
351
+ }
@@ -1,7 +1,9 @@
1
- @import './files/normalize';
1
+ @import "./files/normalize.css";
2
2
 
3
- $cover-color: #5091b1;
4
- $link-color: $cover-color;
3
+ :root {
4
+ --cover-color: #5091b1;
5
+ --link-color: var(--cover-color);
6
+ }
5
7
 
6
8
  html {
7
9
  background: #eee;
@@ -17,17 +19,17 @@ body {
17
19
  }
18
20
 
19
21
  a {
20
- color: $link-color;
22
+ color: var(--link-color);
21
23
  }
22
24
 
23
25
  p code,
24
26
  li code {
25
- color: #3F9C55;
27
+ color: #3f9c55;
26
28
  }
27
29
 
28
- // Format cover page.
30
+ /* Format cover page. */
29
31
  .frontcover {
30
- background: $cover-color;
32
+ background: var(--cover-color);
31
33
  color: #fff;
32
34
  padding: 50px;
33
35
  margin: -50px -50px 50px -50px;
@@ -41,7 +43,7 @@ li code {
41
43
  .frontcover .description {
42
44
  width: 45%;
43
45
  margin: 20px auto;
44
- color: rgba(#fff, .7);
46
+ color: rgba(#fff, 0.7);
45
47
  }
46
48
 
47
49
  .frontcover .authors {
@@ -50,9 +52,9 @@ li code {
50
52
  font-size: 24px;
51
53
  }
52
54
 
53
- // Define asterism.
55
+ /* Define asterism. */
54
56
  .chapter + .chapter:before {
55
- content: '\2234';
57
+ content: "\2234";
56
58
  display: block;
57
59
  text-align: center;
58
60
  font-size: 24px;
@@ -73,7 +75,7 @@ li code {
73
75
  padding-right: 15px;
74
76
  }
75
77
 
76
- // Table of contents
78
+ /* Table of contents */
77
79
  .toc {
78
80
  padding-bottom: 50px;
79
81
  margin-bottom: 50px;
@@ -90,11 +92,11 @@ li code {
90
92
  }
91
93
 
92
94
  .chapter h2:before {
93
- content: 'Chapter ' counter(chapter);
95
+ content: "Chapter " counter(chapter);
94
96
  display: block;
95
97
  text-transform: uppercase;
96
98
  font-weight: normal;
97
- color: #DB0209;
99
+ color: #db0209;
98
100
  font-size: 14px;
99
101
  }
100
102
 
@@ -102,7 +104,7 @@ li code {
102
104
  margin-top: 50px;
103
105
  }
104
106
 
105
- // Footnotes
107
+ /* Footnotes */
106
108
  .footnotes {
107
109
  margin-top: 50px;
108
110
  padding-top: 25px;
@@ -113,7 +115,7 @@ li code {
113
115
  display: none;
114
116
  }
115
117
 
116
- // Notes
118
+ /* Notes */
117
119
  .note {
118
120
  font-size: 13px;
119
121
  float: right;
@@ -124,7 +126,7 @@ li code {
124
126
  }
125
127
 
126
128
  .note:before {
127
- content: '!';
129
+ content: "!";
128
130
  display: inline-block;
129
131
  font-size: 25px;
130
132
  width: 10px;
@@ -149,7 +151,7 @@ li code {
149
151
  color: #fff;
150
152
  }
151
153
 
152
- // Format lexers list
154
+ /* Format lexers list */
153
155
  .lexers-list {
154
156
  margin: 0;
155
157
  padding: 0;
@@ -170,7 +172,7 @@ li code {
170
172
  margin-top: 15px;
171
173
  }
172
174
 
173
- // Format imprint
175
+ /* Format imprint */
174
176
  .imprint {
175
177
  margin-top: 50px;
176
178
  padding-top: 50px;
@@ -186,7 +188,7 @@ li code {
186
188
  margin-bottom: 10px;
187
189
  }
188
190
 
189
- // Table of contents
191
+ /* Table of contents */
190
192
  .table-of-contents {
191
193
  padding-bottom: 50px;
192
194
  margin-bottom: 50px;
@@ -208,7 +210,7 @@ li code {
208
210
  }
209
211
 
210
212
  .table-of-contents .level2:before {
211
- content: 'Chapter ' counter(toc-level2);
213
+ content: "Chapter " counter(toc-level2);
212
214
  font-size: 13px;
213
215
  text-transform: uppercase;
214
216
  font-weight: bold;
@@ -230,7 +232,7 @@ li code {
230
232
  break-inside: avoid-column;
231
233
  }
232
234
 
233
- // Go top
235
+ /* Go top */
234
236
  .go-top {
235
237
  font-size: 50px;
236
238
  text-decoration: none;
@@ -239,14 +241,14 @@ li code {
239
241
  right: 25px;
240
242
  width: 60px;
241
243
  display: inline-block;
242
- background: rgba(#000, .2);
244
+ background: rgba(#000, 0.2);
243
245
  text-align: center;
244
246
  border-radius: 10px;
245
247
  line-height: 1;
246
- color: rgba(#fff, .4);
248
+ color: rgba(#fff, 0.4);
247
249
  padding-top: 10px;
250
+ }
248
251
 
249
- &:hover {
250
- color: #fff;
251
- }
252
+ .go-top:hover {
253
+ color: #fff;
252
254
  }