kitabu 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +7 -5
  5. data/lib/kitabu.rb +12 -1
  6. data/lib/kitabu/cli.rb +1 -1
  7. data/lib/kitabu/exporter.rb +5 -5
  8. data/lib/kitabu/{parser.rb → exporter/base.rb} +9 -11
  9. data/lib/kitabu/exporter/css.rb +24 -0
  10. data/lib/kitabu/{parser → exporter}/epub.rb +2 -2
  11. data/lib/kitabu/exporter/html.rb +109 -0
  12. data/lib/kitabu/{parser → exporter}/mobi.rb +2 -2
  13. data/lib/kitabu/exporter/pdf.rb +43 -0
  14. data/lib/kitabu/{parser → exporter}/txt.rb +2 -2
  15. data/lib/kitabu/footnotes/base.rb +33 -0
  16. data/lib/kitabu/footnotes/html.rb +52 -0
  17. data/lib/kitabu/footnotes/pdf.rb +47 -0
  18. data/lib/kitabu/source_list.rb +73 -0
  19. data/lib/kitabu/stats.rb +1 -1
  20. data/lib/kitabu/stream.rb +1 -1
  21. data/lib/kitabu/toc/html.rb +6 -6
  22. data/lib/kitabu/version.rb +1 -1
  23. data/spec/kitabu/exporter/css_spec.rb +16 -0
  24. data/spec/kitabu/{parser → exporter}/epub_spec.rb +3 -3
  25. data/spec/kitabu/exporter/html_spec.rb +36 -0
  26. data/spec/kitabu/{parser → exporter}/mobi_spec.rb +3 -3
  27. data/spec/kitabu/{parser → exporter}/pdf_spec.rb +3 -3
  28. data/spec/kitabu/{parser → exporter}/txt_spec.rb +3 -3
  29. data/spec/kitabu/footnotes/html_spec.rb +67 -0
  30. data/spec/kitabu/{parser/html_spec.rb → source_list_spec.rb} +5 -34
  31. data/spec/kitabu/stats_spec.rb +7 -7
  32. data/templates/templates/styles/pdf.scss +1 -47
  33. data/templates/text/04_Dynamic_Content.erb +1 -1
  34. metadata +29 -54
  35. data/examples/kitabu/output/epub/images/.gitkeep +0 -0
  36. data/examples/kitabu/output/epub/images/kitabu-icon.png +0 -0
  37. data/examples/kitabu/output/epub/images/kitabu-icon.svg +0 -19
  38. data/examples/kitabu/output/epub/images/kitabu-word.png +0 -0
  39. data/examples/kitabu/output/epub/images/kitabu-word.svg +0 -14
  40. data/examples/kitabu/output/epub/images/kitabu.png +0 -0
  41. data/examples/kitabu/output/epub/images/kitabu.svg +0 -20
  42. data/examples/kitabu/output/epub/section_0.html +0 -266
  43. data/examples/kitabu/output/epub/section_1.html +0 -246
  44. data/examples/kitabu/output/epub/section_2.html +0 -520
  45. data/examples/kitabu/output/epub/section_3.html +0 -282
  46. data/examples/kitabu/output/epub/section_4.html +0 -276
  47. data/examples/kitabu/output/epub/styles/epub.css +0 -437
  48. data/examples/kitabu/output/epub/styles/html.css +0 -712
  49. data/examples/kitabu/output/epub/styles/pdf.css +0 -840
  50. data/examples/kitabu/output/epub/styles/print.css +0 -1278
  51. data/examples/kitabu/output/epub/toc.html +0 -37
  52. data/examples/kitabu/output/images/.gitkeep +0 -0
  53. data/examples/kitabu/output/images/kitabu-icon.png +0 -0
  54. data/examples/kitabu/output/images/kitabu-icon.svg +0 -19
  55. data/examples/kitabu/output/images/kitabu-word.png +0 -0
  56. data/examples/kitabu/output/images/kitabu-word.svg +0 -14
  57. data/examples/kitabu/output/images/kitabu.png +0 -0
  58. data/examples/kitabu/output/images/kitabu.svg +0 -20
  59. data/examples/kitabu/output/kitabu.epub +0 -0
  60. data/examples/kitabu/output/kitabu.html +0 -513
  61. data/examples/kitabu/output/kitabu.mobi +0 -0
  62. data/examples/kitabu/output/kitabu.pdf +0 -0
  63. data/examples/kitabu/output/kitabu.pdf.html +0 -729
  64. data/examples/kitabu/output/kitabu.print.html +0 -729
  65. data/examples/kitabu/output/kitabu.print.pdf +0 -0
  66. data/examples/kitabu/output/kitabu.txt +0 -440
  67. data/examples/kitabu/output/styles/epub.css +0 -437
  68. data/examples/kitabu/output/styles/html.css +0 -712
  69. data/examples/kitabu/output/styles/pdf.css +0 -840
  70. data/examples/kitabu/output/styles/print.css +0 -1278
  71. data/lib/kitabu/parser/html.rb +0 -208
  72. data/lib/kitabu/parser/pdf.rb +0 -88
@@ -1,282 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
- <html class="epub" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
- <head>
5
- <title></title>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
7
- <link name="stylesheet" rel="stylesheet" type="text/css" href="styles/epub.css" />
8
- <style type="text/css">.highlight table td { padding: 5px; }
9
- .highlight table pre { margin: 0; }
10
- .highlight .cm {
11
- color: #999988;
12
- font-style: italic;
13
- }
14
- .highlight .cp {
15
- color: #999999;
16
- font-weight: bold;
17
- }
18
- .highlight .c1 {
19
- color: #999988;
20
- font-style: italic;
21
- }
22
- .highlight .cs {
23
- color: #999999;
24
- font-weight: bold;
25
- font-style: italic;
26
- }
27
- .highlight .c, .highlight .cd {
28
- color: #999988;
29
- font-style: italic;
30
- }
31
- .highlight .err {
32
- color: #a61717;
33
- background-color: #e3d2d2;
34
- }
35
- .highlight .gd {
36
- color: #000000;
37
- background-color: #ffdddd;
38
- }
39
- .highlight .ge {
40
- color: #000000;
41
- font-style: italic;
42
- }
43
- .highlight .gr {
44
- color: #aa0000;
45
- }
46
- .highlight .gh {
47
- color: #999999;
48
- }
49
- .highlight .gi {
50
- color: #000000;
51
- background-color: #ddffdd;
52
- }
53
- .highlight .go {
54
- color: #888888;
55
- }
56
- .highlight .gp {
57
- color: #555555;
58
- }
59
- .highlight .gs {
60
- font-weight: bold;
61
- }
62
- .highlight .gu {
63
- color: #aaaaaa;
64
- }
65
- .highlight .gt {
66
- color: #aa0000;
67
- }
68
- .highlight .kc {
69
- color: #000000;
70
- font-weight: bold;
71
- }
72
- .highlight .kd {
73
- color: #000000;
74
- font-weight: bold;
75
- }
76
- .highlight .kn {
77
- color: #000000;
78
- font-weight: bold;
79
- }
80
- .highlight .kp {
81
- color: #000000;
82
- font-weight: bold;
83
- }
84
- .highlight .kr {
85
- color: #000000;
86
- font-weight: bold;
87
- }
88
- .highlight .kt {
89
- color: #445588;
90
- font-weight: bold;
91
- }
92
- .highlight .k, .highlight .kv {
93
- color: #000000;
94
- font-weight: bold;
95
- }
96
- .highlight .mf {
97
- color: #009999;
98
- }
99
- .highlight .mh {
100
- color: #009999;
101
- }
102
- .highlight .il {
103
- color: #009999;
104
- }
105
- .highlight .mi {
106
- color: #009999;
107
- }
108
- .highlight .mo {
109
- color: #009999;
110
- }
111
- .highlight .m, .highlight .mb, .highlight .mx {
112
- color: #009999;
113
- }
114
- .highlight .sb {
115
- color: #d14;
116
- }
117
- .highlight .sc {
118
- color: #d14;
119
- }
120
- .highlight .sd {
121
- color: #d14;
122
- }
123
- .highlight .s2 {
124
- color: #d14;
125
- }
126
- .highlight .se {
127
- color: #d14;
128
- }
129
- .highlight .sh {
130
- color: #d14;
131
- }
132
- .highlight .si {
133
- color: #d14;
134
- }
135
- .highlight .sx {
136
- color: #d14;
137
- }
138
- .highlight .sr {
139
- color: #009926;
140
- }
141
- .highlight .s1 {
142
- color: #d14;
143
- }
144
- .highlight .ss {
145
- color: #990073;
146
- }
147
- .highlight .s {
148
- color: #d14;
149
- }
150
- .highlight .na {
151
- color: #008080;
152
- }
153
- .highlight .bp {
154
- color: #999999;
155
- }
156
- .highlight .nb {
157
- color: #0086B3;
158
- }
159
- .highlight .nc {
160
- color: #445588;
161
- font-weight: bold;
162
- }
163
- .highlight .no {
164
- color: #008080;
165
- }
166
- .highlight .nd {
167
- color: #3c5d5d;
168
- font-weight: bold;
169
- }
170
- .highlight .ni {
171
- color: #800080;
172
- }
173
- .highlight .ne {
174
- color: #990000;
175
- font-weight: bold;
176
- }
177
- .highlight .nf {
178
- color: #990000;
179
- font-weight: bold;
180
- }
181
- .highlight .nl {
182
- color: #990000;
183
- font-weight: bold;
184
- }
185
- .highlight .nn {
186
- color: #555555;
187
- }
188
- .highlight .nt {
189
- color: #000080;
190
- }
191
- .highlight .vc {
192
- color: #008080;
193
- }
194
- .highlight .vg {
195
- color: #008080;
196
- }
197
- .highlight .vi {
198
- color: #008080;
199
- }
200
- .highlight .nv {
201
- color: #008080;
202
- }
203
- .highlight .ow {
204
- color: #000000;
205
- font-weight: bold;
206
- }
207
- .highlight .o {
208
- color: #000000;
209
- font-weight: bold;
210
- }
211
- .highlight .w {
212
- color: #bbbbbb;
213
- }
214
- .highlight {
215
- background-color: #f8f8f8;
216
- }</style>
217
- </head>
218
-
219
- <body>
220
- <div class="chapter">
221
- <h2 id="dynamic-content">Dynamic Content</h2>
222
-
223
- <p>Sometimes you may find useful to generate content dynamically. Maybe you’re going to read some configuration file, or maybe you just want to define some helpers. Kitabu has support for ERb files; all you need to do is naming your text file as <code>.erb</code>.</p>
224
-
225
- <p>On the previous chapter, we listed all supported Rouge lexers. To do that, I created a helper that looks like this:</p>
226
- <pre class="highlight ruby"><code><span class="k">module</span> <span class="nn">Kitabu</span>
227
- <span class="k">module</span> <span class="nn">Helpers</span>
228
- <span class="k">def</span> <span class="nf">lexers_list</span>
229
- <span class="n">buffer</span> <span class="o">=</span> <span class="s1">'&lt;ul class="lexers"&gt;'</span>
230
-
231
- <span class="no">Rouge</span><span class="o">::</span><span class="no">Lexers</span><span class="p">.</span><span class="nf">constants</span><span class="p">.</span><span class="nf">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">const</span><span class="o">|</span>
232
- <span class="n">lexer</span> <span class="o">=</span> <span class="no">Rouge</span><span class="o">::</span><span class="no">Lexers</span><span class="p">.</span><span class="nf">const_get</span><span class="p">(</span><span class="n">const</span><span class="p">)</span>
233
-
234
- <span class="k">begin</span>
235
- <span class="n">title</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">title</span>
236
- <span class="n">tag</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">tag</span>
237
- <span class="n">description</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">desc</span>
238
- <span class="k">rescue</span> <span class="no">Exception</span> <span class="o">=&gt;</span> <span class="n">e</span>
239
- <span class="k">next</span>
240
- <span class="k">end</span>
241
-
242
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;li&gt;'</span>
243
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s2">"&lt;strong&gt;</span><span class="si">#{</span><span class="n">title</span><span class="si">}</span><span class="s2">&lt;/strong&gt; "</span>
244
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s2">"&lt;code&gt;</span><span class="si">#{</span><span class="n">tag</span><span class="si">}</span><span class="s2">&lt;/code&gt;&lt;br&gt;"</span>
245
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s2">"&lt;span&gt;</span><span class="si">#{</span><span class="n">description</span><span class="si">}</span><span class="s2">&lt;/span&gt;"</span>
246
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;/li&gt;'</span>
247
- <span class="k">end</span>
248
-
249
- <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;/ul&gt;'</span>
250
- <span class="n">buffer</span>
251
- <span class="k">end</span>
252
- <span class="k">end</span>
253
- <span class="k">end</span>
254
- </code></pre>
255
-
256
- <p>To use it, I just needed to add <code>&lt;%= lexers_list %&gt;</code> to my text file. This allows you to create anything you need!</p>
257
-
258
- <p>Kitabu comes with some built-in helpers, such as <code>note</code>. With this helper, you can create a note that generates a HTML structure, so you can easily style it. The syntax for using the <code>note</code> helper is <code>note(type, &amp;block)</code>.</p>
259
- <pre class="highlight erb"><code><span class="cp">&lt;%</span> <span class="n">note</span> <span class="k">do</span> <span class="cp">%&gt;</span>
260
- Some text that will be parsed as Markdown.
261
- <span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span>
262
- </code></pre>
263
-
264
- <p>By default, this will generate a <code>&lt;div class="note info"&gt;</code> tag, but you can use anything you want.</p>
265
- <pre class="highlight erb"><code><span class="cp">&lt;%</span> <span class="n">note</span> <span class="ss">:warning</span> <span class="k">do</span> <span class="cp">%&gt;</span>
266
- Some text that will be parsed as Markdown.
267
- <span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span>
268
- </code></pre>
269
-
270
- <p><a href="https://github.com/fnando/kitabu/blob/cleanup/lib/kitabu/helpers.rb">Check out the source</a> for a sample on how to create block helpers like <code>note</code>.</p>
271
-
272
- <h3 id="escaping-erb-code">Escaping ERb code</h3>
273
-
274
- <p>If you want to write a book about Rails, you’re likely to use lots of ERb tags. In this case, make sure you escape the <code>and</code> markers as <code>&lt;% %&gt;</code> and <code>&lt;%= %&gt;</code>; otherwise you’ll have a syntax error.</p>
275
- <pre class="highlight plaintext"><code>&lt;%%= Date.today %&gt;
276
- </code></pre>
277
-
278
-
279
-
280
- </div>
281
- </body>
282
- </html>
@@ -1,276 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
- <html class="epub" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
- <head>
5
- <title></title>
6
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
7
- <link name="stylesheet" rel="stylesheet" type="text/css" href="styles/epub.css" />
8
- <style type="text/css">.highlight table td { padding: 5px; }
9
- .highlight table pre { margin: 0; }
10
- .highlight .cm {
11
- color: #999988;
12
- font-style: italic;
13
- }
14
- .highlight .cp {
15
- color: #999999;
16
- font-weight: bold;
17
- }
18
- .highlight .c1 {
19
- color: #999988;
20
- font-style: italic;
21
- }
22
- .highlight .cs {
23
- color: #999999;
24
- font-weight: bold;
25
- font-style: italic;
26
- }
27
- .highlight .c, .highlight .cd {
28
- color: #999988;
29
- font-style: italic;
30
- }
31
- .highlight .err {
32
- color: #a61717;
33
- background-color: #e3d2d2;
34
- }
35
- .highlight .gd {
36
- color: #000000;
37
- background-color: #ffdddd;
38
- }
39
- .highlight .ge {
40
- color: #000000;
41
- font-style: italic;
42
- }
43
- .highlight .gr {
44
- color: #aa0000;
45
- }
46
- .highlight .gh {
47
- color: #999999;
48
- }
49
- .highlight .gi {
50
- color: #000000;
51
- background-color: #ddffdd;
52
- }
53
- .highlight .go {
54
- color: #888888;
55
- }
56
- .highlight .gp {
57
- color: #555555;
58
- }
59
- .highlight .gs {
60
- font-weight: bold;
61
- }
62
- .highlight .gu {
63
- color: #aaaaaa;
64
- }
65
- .highlight .gt {
66
- color: #aa0000;
67
- }
68
- .highlight .kc {
69
- color: #000000;
70
- font-weight: bold;
71
- }
72
- .highlight .kd {
73
- color: #000000;
74
- font-weight: bold;
75
- }
76
- .highlight .kn {
77
- color: #000000;
78
- font-weight: bold;
79
- }
80
- .highlight .kp {
81
- color: #000000;
82
- font-weight: bold;
83
- }
84
- .highlight .kr {
85
- color: #000000;
86
- font-weight: bold;
87
- }
88
- .highlight .kt {
89
- color: #445588;
90
- font-weight: bold;
91
- }
92
- .highlight .k, .highlight .kv {
93
- color: #000000;
94
- font-weight: bold;
95
- }
96
- .highlight .mf {
97
- color: #009999;
98
- }
99
- .highlight .mh {
100
- color: #009999;
101
- }
102
- .highlight .il {
103
- color: #009999;
104
- }
105
- .highlight .mi {
106
- color: #009999;
107
- }
108
- .highlight .mo {
109
- color: #009999;
110
- }
111
- .highlight .m, .highlight .mb, .highlight .mx {
112
- color: #009999;
113
- }
114
- .highlight .sb {
115
- color: #d14;
116
- }
117
- .highlight .sc {
118
- color: #d14;
119
- }
120
- .highlight .sd {
121
- color: #d14;
122
- }
123
- .highlight .s2 {
124
- color: #d14;
125
- }
126
- .highlight .se {
127
- color: #d14;
128
- }
129
- .highlight .sh {
130
- color: #d14;
131
- }
132
- .highlight .si {
133
- color: #d14;
134
- }
135
- .highlight .sx {
136
- color: #d14;
137
- }
138
- .highlight .sr {
139
- color: #009926;
140
- }
141
- .highlight .s1 {
142
- color: #d14;
143
- }
144
- .highlight .ss {
145
- color: #990073;
146
- }
147
- .highlight .s {
148
- color: #d14;
149
- }
150
- .highlight .na {
151
- color: #008080;
152
- }
153
- .highlight .bp {
154
- color: #999999;
155
- }
156
- .highlight .nb {
157
- color: #0086B3;
158
- }
159
- .highlight .nc {
160
- color: #445588;
161
- font-weight: bold;
162
- }
163
- .highlight .no {
164
- color: #008080;
165
- }
166
- .highlight .nd {
167
- color: #3c5d5d;
168
- font-weight: bold;
169
- }
170
- .highlight .ni {
171
- color: #800080;
172
- }
173
- .highlight .ne {
174
- color: #990000;
175
- font-weight: bold;
176
- }
177
- .highlight .nf {
178
- color: #990000;
179
- font-weight: bold;
180
- }
181
- .highlight .nl {
182
- color: #990000;
183
- font-weight: bold;
184
- }
185
- .highlight .nn {
186
- color: #555555;
187
- }
188
- .highlight .nt {
189
- color: #000080;
190
- }
191
- .highlight .vc {
192
- color: #008080;
193
- }
194
- .highlight .vg {
195
- color: #008080;
196
- }
197
- .highlight .vi {
198
- color: #008080;
199
- }
200
- .highlight .nv {
201
- color: #008080;
202
- }
203
- .highlight .ow {
204
- color: #000000;
205
- font-weight: bold;
206
- }
207
- .highlight .o {
208
- color: #000000;
209
- font-weight: bold;
210
- }
211
- .highlight .w {
212
- color: #bbbbbb;
213
- }
214
- .highlight {
215
- background-color: #f8f8f8;
216
- }</style>
217
- </head>
218
-
219
- <body>
220
- <div class="chapter">
221
- <h2 id="exporting-files">Exporting Files</h2>
222
-
223
- <p>You can generate files as you go. Just execute <code>kitabu export</code> from your book’s root directory.</p>
224
- <pre class="highlight plaintext"><code>$ kitabu export
225
- ** e-book has been exported
226
- </code></pre>
227
-
228
- <p>This command will generate all supported formats<sup id="fnref1"><a href="section_4.html#fn1" rel="footnote">1</a></sup>. The generated files will be placed on your <code>output</code> directory; the following output list only the relevant files.</p>
229
- <pre class="highlight plaintext"><code>$ tree output
230
- output
231
- ├── images
232
- │   ├── kitabu.png
233
- │   └── kitabu.svg
234
- ├── kitabu.epub
235
- ├── kitabu.html
236
- ├── kitabu.mobi
237
- ├── kitabu.pdf
238
- ├── kitabu.print.pdf
239
- ├── kitabu.txt
240
- └── styles
241
- ├── epub.css
242
- ├── html.css
243
- ├── pdf.css
244
- └── print.css
245
- </code></pre>
246
-
247
- <p>This can take a while depending on your book size, but usually the process is pretty fast. If you want to generate a specific format faster, provide the <code>--only</code> flag.</p>
248
- <pre class="highlight plaintext"><code>$ kitabu export --only pdf
249
- </code></pre>
250
-
251
- <p>You can also automatically generate files when something changes. You can use <a href="http://rubygems.org/gems/guard">Guard</a> for this, and Kitabu even generates a sample file for you. All you have to do is running <code>bundle exec guard</code>.</p>
252
- <pre class="highlight plaintext"><code>$ bundle exec guard
253
- 20:38:10 - INFO - Guard is now watching at '/Users/fnando/Projects/kitabu/examples/kitabu'
254
- ** e-book has been exported
255
- </code></pre>
256
-
257
- <h3 id="exporting-pdf-with-docraptor">Exporting PDF with DocRaptor</h3>
258
-
259
- <p>After exporting your files (you can use <code>--only pdf</code> for this), upload files to somewhere public, possibly your <a href="http://dropbox.com">Dropbox</a> account. You can even use curl; since the command is quite long, you can view it at <a href="https://gist.github.com/fnando/de555a08e7aab14a661a">https://gist.github.com/fnando/de555a08e7aab14a661a</a>.</p>
260
-
261
- <div class="footnotes">
262
- <hr />
263
- <ol>
264
-
265
- <li id="fn1">
266
- <p>Depend on Prince, html2text and KindleGen being available on your <code>$PATH</code>. <a href="section_4.html#fnref1" rev="footnote">↩</a></p>
267
- </li>
268
-
269
- </ol>
270
- </div>
271
-
272
-
273
-
274
- </div>
275
- </body>
276
- </html>