kitabu 1.0.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -3
  3. data/.travis.yml +18 -0
  4. data/CHANGELOG.md +9 -0
  5. data/Gemfile.lock +67 -50
  6. data/README.md +235 -0
  7. data/attachments/browser-version.png +0 -0
  8. data/attachments/cover.png +0 -0
  9. data/attachments/kitabu.epub +0 -0
  10. data/attachments/kitabu.mobi +0 -0
  11. data/attachments/kitabu.pdf +0 -0
  12. data/{spec/support/mybook/output → examples/kitabu/output/epub/images}/.gitkeep +0 -0
  13. data/examples/kitabu/output/epub/images/kitabu-icon.png +0 -0
  14. data/examples/kitabu/output/epub/images/kitabu-icon.svg +19 -0
  15. data/examples/kitabu/output/epub/images/kitabu-word.png +0 -0
  16. data/examples/kitabu/output/epub/images/kitabu-word.svg +14 -0
  17. data/examples/kitabu/output/epub/images/kitabu.png +0 -0
  18. data/examples/kitabu/output/epub/images/kitabu.svg +20 -0
  19. data/examples/kitabu/output/epub/section_0.html +266 -0
  20. data/examples/kitabu/output/epub/section_1.html +246 -0
  21. data/examples/kitabu/output/epub/section_2.html +520 -0
  22. data/examples/kitabu/output/epub/section_3.html +282 -0
  23. data/examples/kitabu/output/epub/section_4.html +276 -0
  24. data/examples/kitabu/output/epub/styles/epub.css +437 -0
  25. data/examples/kitabu/output/epub/styles/html.css +712 -0
  26. data/examples/kitabu/output/epub/styles/pdf.css +840 -0
  27. data/examples/kitabu/output/epub/styles/print.css +1278 -0
  28. data/examples/kitabu/output/epub/toc.html +37 -0
  29. data/{spec/support/mybook/templates/epub/style.css → examples/kitabu/output/images/.gitkeep} +0 -0
  30. data/examples/kitabu/output/images/kitabu-icon.png +0 -0
  31. data/examples/kitabu/output/images/kitabu-icon.svg +19 -0
  32. data/examples/kitabu/output/images/kitabu-word.png +0 -0
  33. data/examples/kitabu/output/images/kitabu-word.svg +14 -0
  34. data/examples/kitabu/output/images/kitabu.png +0 -0
  35. data/examples/kitabu/output/images/kitabu.svg +20 -0
  36. data/examples/kitabu/output/kitabu.epub +0 -0
  37. data/examples/kitabu/output/kitabu.html +513 -0
  38. data/examples/kitabu/output/kitabu.mobi +0 -0
  39. data/examples/kitabu/output/kitabu.pdf +0 -0
  40. data/examples/kitabu/output/kitabu.pdf.html +729 -0
  41. data/examples/kitabu/output/kitabu.print.html +729 -0
  42. data/examples/kitabu/output/kitabu.print.pdf +0 -0
  43. data/examples/kitabu/output/kitabu.txt +440 -0
  44. data/examples/kitabu/output/styles/epub.css +437 -0
  45. data/examples/kitabu/output/styles/html.css +712 -0
  46. data/examples/kitabu/output/styles/pdf.css +840 -0
  47. data/examples/kitabu/output/styles/print.css +1278 -0
  48. data/kitabu.gemspec +7 -5
  49. data/lib/kitabu.rb +10 -20
  50. data/lib/kitabu/cli.rb +0 -5
  51. data/lib/kitabu/dependency.rb +0 -4
  52. data/lib/kitabu/exporter.rb +2 -0
  53. data/lib/kitabu/extensions/rouge.rb +9 -0
  54. data/lib/kitabu/generator.rb +9 -21
  55. data/lib/kitabu/helpers.rb +47 -0
  56. data/lib/kitabu/markdown.rb +31 -0
  57. data/lib/kitabu/parser.rb +21 -3
  58. data/lib/kitabu/parser/epub.rb +31 -18
  59. data/lib/kitabu/parser/html.rb +48 -29
  60. data/lib/kitabu/parser/mobi.rb +1 -1
  61. data/lib/kitabu/parser/pdf.rb +52 -8
  62. data/lib/kitabu/version.rb +2 -2
  63. data/spec/kitabu/cli/export_spec.rb +4 -4
  64. data/spec/kitabu/cli/new_spec.rb +2 -2
  65. data/spec/kitabu/markdown_spec.rb +24 -0
  66. data/spec/kitabu/parser/html_spec.rb +20 -25
  67. data/spec/kitabu/parser/mobi_spec.rb +14 -0
  68. data/spec/kitabu/parser/pdf_spec.rb +18 -1
  69. data/spec/kitabu/parser/txt_spec.rb +14 -0
  70. data/spec/spec_helper.rb +10 -6
  71. data/spec/support/mybook/config/helper.rb +4 -29
  72. data/spec/support/mybook/config/kitabu.yml +0 -10
  73. data/spec/support/mybook/templates/epub/cover.erb +4 -3
  74. data/{templates → spec/support/mybook/templates/epub}/cover.png +0 -0
  75. data/spec/support/mybook/templates/epub/page.erb +3 -2
  76. data/spec/support/mybook/templates/html/layout.erb +10 -13
  77. data/spec/support/mybook/templates/styles/epub.scss +3 -0
  78. data/spec/support/mybook/templates/styles/html.scss +3 -0
  79. data/spec/support/mybook/templates/styles/pdf.scss +3 -0
  80. data/spec/support/mybook/templates/styles/print.scss +3 -0
  81. data/spec/support/mybook/text/{01_Markdown_Chapter.markdown → 01_Markdown_Chapter.md} +2 -3
  82. data/spec/support/mybook/text/02_ERB_Chapter.md.erb +7 -0
  83. data/spec/support/mybook/text/{04_With_Directory/Some_Chapter.mkdn → 03_With_Directory/Some_Chapter.md} +0 -0
  84. data/spec/support/mybook/text/{CHANGELOG.textile → CHANGELOG.md} +2 -2
  85. data/spec/support/mybook/text/{TOC.textile → TOC.md} +0 -0
  86. data/spec/support/mybook/text/{_00_Introduction.markdown → _00_Introduction.md} +0 -0
  87. data/spec/support/shared.rb +14 -10
  88. data/templates/Gemfile +3 -3
  89. data/templates/Guardfile +1 -5
  90. data/templates/config.erb +5 -5
  91. data/templates/cover.erb +4 -3
  92. data/templates/epub.erb +3 -2
  93. data/templates/helper.rb +28 -29
  94. data/templates/images/.gitkeep +0 -0
  95. data/templates/images/kitabu-icon.png +0 -0
  96. data/templates/images/kitabu-icon.svg +19 -0
  97. data/templates/images/kitabu-word.png +0 -0
  98. data/templates/images/kitabu-word.svg +14 -0
  99. data/templates/images/kitabu.png +0 -0
  100. data/templates/images/kitabu.svg +20 -0
  101. data/{examples/RailsGuides/templates → templates/templates/epub}/cover.erb +4 -3
  102. data/templates/templates/epub/cover.png +0 -0
  103. data/templates/templates/epub/page.erb +16 -0
  104. data/templates/{layout.erb → templates/html/layout.erb} +22 -11
  105. data/templates/templates/styles/epub.scss +1 -0
  106. data/templates/templates/styles/files/_normalize.scss +427 -0
  107. data/templates/templates/styles/html.scss +252 -0
  108. data/templates/templates/styles/pdf.scss +371 -0
  109. data/templates/templates/styles/print.scss +2 -0
  110. data/templates/text/01_Getting_Started.md +26 -0
  111. data/templates/text/02_Creating_Chapters.md +22 -0
  112. data/templates/text/03_Syntax_Highlighting.erb +69 -0
  113. data/templates/text/04_Dynamic_Content.erb +64 -0
  114. data/templates/text/05_Exporting_Files.md +49 -0
  115. metadata +143 -83
  116. data/README.rdoc +0 -218
  117. data/examples/RailsGuides/config/helper.rb +0 -29
  118. data/examples/RailsGuides/config/kitabu.yml +0 -44
  119. data/examples/RailsGuides/images/challenge.png +0 -0
  120. data/examples/RailsGuides/images/posts_index.png +0 -0
  121. data/examples/RailsGuides/images/rails_welcome.png +0 -0
  122. data/examples/RailsGuides/output/RailsGuides.epub +0 -0
  123. data/examples/RailsGuides/output/RailsGuides.html +0 -1556
  124. data/examples/RailsGuides/output/RailsGuides.pdf +3 -4934
  125. data/examples/RailsGuides/templates/layout.css +0 -352
  126. data/examples/RailsGuides/templates/layout.erb +0 -43
  127. data/examples/RailsGuides/templates/syntax.css +0 -62
  128. data/examples/RailsGuides/templates/user.css +0 -19
  129. data/examples/RailsGuides/text/01_Guide_Assumptions.mkdn +0 -13
  130. data/examples/RailsGuides/text/02_What_is_Rails.mkdn +0 -106
  131. data/examples/RailsGuides/text/03_Creating_a_new_Rails_project.mkdn +0 -200
  132. data/examples/RailsGuides/text/04_Hello_Rails.mkdn +0 -62
  133. data/examples/RailsGuides/text/05_Getting_Up_and_Running_Quickly_with_Scaffolding.mkdn +0 -4
  134. data/examples/RailsGuides/text/06_Creating_a_resource.mkdn +0 -503
  135. data/examples/RailsGuides/text/07_Adding_a_second_model.mkdn +0 -232
  136. data/examples/RailsGuides/text/08_Refactoring.mkdn +0 -123
  137. data/examples/RailsGuides/text/09_Deleting_comments.mkdn +0 -57
  138. data/examples/RailsGuides/text/09_Security.mkdn +0 -56
  139. data/examples/RailsGuides/text/10_Building_a_multi_model_form.mkdn +0 -130
  140. data/examples/RailsGuides/text/11_View_helpers.mkdn +0 -50
  141. data/examples/RailsGuides/text/12_Whats_next.mkdn +0 -14
  142. data/examples/RailsGuides/text/13_Configuration_gotchas.mkdn +0 -10
  143. data/lib/kitabu/adapters/markdown.rb +0 -34
  144. data/lib/kitabu/extensions/redcloth.rb +0 -69
  145. data/lib/kitabu/syntax.rb +0 -130
  146. data/spec/kitabu/extensions/redcloth_spec.rb +0 -57
  147. data/spec/kitabu/syntax_spec.rb +0 -106
  148. data/spec/support/mybook/templates/html/layout.css +0 -353
  149. data/spec/support/mybook/templates/html/syntax.css +0 -58
  150. data/spec/support/mybook/templates/html/user.css +0 -1
  151. data/spec/support/mybook/text/02_Textile_Chapter.textile +0 -3
  152. data/spec/support/mybook/text/03_HTML_Chapter.html +0 -3
  153. data/templates/epub.css +0 -500
  154. data/templates/layout.css +0 -353
  155. data/templates/sample.md +0 -6
  156. data/templates/syntax.css +0 -58
  157. data/templates/user.css +0 -1
@@ -0,0 +1,729 @@
1
+ <!DOCTYPE html>
2
+ <html class="print">
3
+ <head>
4
+ <title>Kitabu</title>
5
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6
+ <link name="stylesheet" rel="stylesheet" type="text/css" href="styles/print.css">
7
+ <meta name="author" content="Nando Vieira">
8
+ <meta name="subject" content="This guide will help you understand how all of the pieces fit together on Kitabu.">
9
+ <meta name="keywords" content="[Your book keywords (comma-separated)]">
10
+ <meta name="date" content="2015-03-13">
11
+ <style type="text/css">.highlight table td { padding: 5px; }
12
+ .highlight table pre { margin: 0; }
13
+ .highlight .cm {
14
+ color: #999988;
15
+ font-style: italic;
16
+ }
17
+ .highlight .cp {
18
+ color: #999999;
19
+ font-weight: bold;
20
+ }
21
+ .highlight .c1 {
22
+ color: #999988;
23
+ font-style: italic;
24
+ }
25
+ .highlight .cs {
26
+ color: #999999;
27
+ font-weight: bold;
28
+ font-style: italic;
29
+ }
30
+ .highlight .c, .highlight .cd {
31
+ color: #999988;
32
+ font-style: italic;
33
+ }
34
+ .highlight .err {
35
+ color: #a61717;
36
+ background-color: #e3d2d2;
37
+ }
38
+ .highlight .gd {
39
+ color: #000000;
40
+ background-color: #ffdddd;
41
+ }
42
+ .highlight .ge {
43
+ color: #000000;
44
+ font-style: italic;
45
+ }
46
+ .highlight .gr {
47
+ color: #aa0000;
48
+ }
49
+ .highlight .gh {
50
+ color: #999999;
51
+ }
52
+ .highlight .gi {
53
+ color: #000000;
54
+ background-color: #ddffdd;
55
+ }
56
+ .highlight .go {
57
+ color: #888888;
58
+ }
59
+ .highlight .gp {
60
+ color: #555555;
61
+ }
62
+ .highlight .gs {
63
+ font-weight: bold;
64
+ }
65
+ .highlight .gu {
66
+ color: #aaaaaa;
67
+ }
68
+ .highlight .gt {
69
+ color: #aa0000;
70
+ }
71
+ .highlight .kc {
72
+ color: #000000;
73
+ font-weight: bold;
74
+ }
75
+ .highlight .kd {
76
+ color: #000000;
77
+ font-weight: bold;
78
+ }
79
+ .highlight .kn {
80
+ color: #000000;
81
+ font-weight: bold;
82
+ }
83
+ .highlight .kp {
84
+ color: #000000;
85
+ font-weight: bold;
86
+ }
87
+ .highlight .kr {
88
+ color: #000000;
89
+ font-weight: bold;
90
+ }
91
+ .highlight .kt {
92
+ color: #445588;
93
+ font-weight: bold;
94
+ }
95
+ .highlight .k, .highlight .kv {
96
+ color: #000000;
97
+ font-weight: bold;
98
+ }
99
+ .highlight .mf {
100
+ color: #009999;
101
+ }
102
+ .highlight .mh {
103
+ color: #009999;
104
+ }
105
+ .highlight .il {
106
+ color: #009999;
107
+ }
108
+ .highlight .mi {
109
+ color: #009999;
110
+ }
111
+ .highlight .mo {
112
+ color: #009999;
113
+ }
114
+ .highlight .m, .highlight .mb, .highlight .mx {
115
+ color: #009999;
116
+ }
117
+ .highlight .sb {
118
+ color: #d14;
119
+ }
120
+ .highlight .sc {
121
+ color: #d14;
122
+ }
123
+ .highlight .sd {
124
+ color: #d14;
125
+ }
126
+ .highlight .s2 {
127
+ color: #d14;
128
+ }
129
+ .highlight .se {
130
+ color: #d14;
131
+ }
132
+ .highlight .sh {
133
+ color: #d14;
134
+ }
135
+ .highlight .si {
136
+ color: #d14;
137
+ }
138
+ .highlight .sx {
139
+ color: #d14;
140
+ }
141
+ .highlight .sr {
142
+ color: #009926;
143
+ }
144
+ .highlight .s1 {
145
+ color: #d14;
146
+ }
147
+ .highlight .ss {
148
+ color: #990073;
149
+ }
150
+ .highlight .s {
151
+ color: #d14;
152
+ }
153
+ .highlight .na {
154
+ color: #008080;
155
+ }
156
+ .highlight .bp {
157
+ color: #999999;
158
+ }
159
+ .highlight .nb {
160
+ color: #0086B3;
161
+ }
162
+ .highlight .nc {
163
+ color: #445588;
164
+ font-weight: bold;
165
+ }
166
+ .highlight .no {
167
+ color: #008080;
168
+ }
169
+ .highlight .nd {
170
+ color: #3c5d5d;
171
+ font-weight: bold;
172
+ }
173
+ .highlight .ni {
174
+ color: #800080;
175
+ }
176
+ .highlight .ne {
177
+ color: #990000;
178
+ font-weight: bold;
179
+ }
180
+ .highlight .nf {
181
+ color: #990000;
182
+ font-weight: bold;
183
+ }
184
+ .highlight .nl {
185
+ color: #990000;
186
+ font-weight: bold;
187
+ }
188
+ .highlight .nn {
189
+ color: #555555;
190
+ }
191
+ .highlight .nt {
192
+ color: #000080;
193
+ }
194
+ .highlight .vc {
195
+ color: #008080;
196
+ }
197
+ .highlight .vg {
198
+ color: #008080;
199
+ }
200
+ .highlight .vi {
201
+ color: #008080;
202
+ }
203
+ .highlight .nv {
204
+ color: #008080;
205
+ }
206
+ .highlight .ow {
207
+ color: #000000;
208
+ font-weight: bold;
209
+ }
210
+ .highlight .o {
211
+ color: #000000;
212
+ font-weight: bold;
213
+ }
214
+ .highlight .w {
215
+ color: #bbbbbb;
216
+ }
217
+ .highlight {
218
+ background-color: #f8f8f8;
219
+ }</style>
220
+ </head>
221
+
222
+ <body>
223
+ <div class="frontcover container">
224
+ <div>
225
+ <div class="logo"><img src="images/kitabu.svg"></div>
226
+ <p class="description">This guide will help you understand how all of the pieces fit together on Kitabu.</p>
227
+ <p class="authors">Nando Vieira</p>
228
+ </div>
229
+ </div>
230
+
231
+ <div class="white-page"></div>
232
+
233
+ <div class="table-of-contents">
234
+ <h2 class="no-toc">Contents</h2>
235
+ <div id="toc">
236
+ <div class="level2 getting-started"><a href="#getting-started"><span>Getting Started</span></a></div>
237
+ <div class="level3 installing-ruby"><a href="#installing-ruby"><span>Installing Ruby</span></a></div>
238
+ <div class="level3 installing-princexml"><a href="#installing-princexml"><span>Installing PrinceXML</span></a></div>
239
+ <div class="level3 installing-kindlegen"><a href="#installing-kindlegen"><span>Installing KindleGen</span></a></div>
240
+ <div class="level2 creating-chapters"><a href="#creating-chapters"><span>Creating Chapters</span></a></div>
241
+ <div class="level2 syntax-highlighting"><a href="#syntax-highlighting"><span>Syntax Highlighting</span></a></div>
242
+ <div class="level3 what-about-the-syntax"><a href="#what-about-the-syntax"><span>What about the syntax</span></a></div>
243
+ <div class="level3 lexers"><a href="#lexers"><span>Lexers</span></a></div>
244
+ <div class="level2 dynamic-content"><a href="#dynamic-content"><span>Dynamic Content</span></a></div>
245
+ <div class="level3 escaping-erb-code"><a href="#escaping-erb-code"><span>Escaping ERb code</span></a></div>
246
+ <div class="level2 exporting-files"><a href="#exporting-files"><span>Exporting Files</span></a></div>
247
+ <div class="level3 exporting-pdf-with-docraptor"><a href="#exporting-pdf-with-docraptor"><span>Exporting PDF with DocRaptor</span></a></div>
248
+ </div>
249
+ </div>
250
+
251
+ <div id="chapters">
252
+
253
+ <div class="chapter">
254
+ <h2 id="getting-started">Getting Started</h2>
255
+
256
+ <p>This guide is designed for beginners who want to get started with Kitabu from scratch. However, to get the most out of it, you need to have some prerequisites installed:</p>
257
+
258
+ <ul>
259
+ <li>The <a href="http://ruby-lang.org">Ruby</a> interpreter version 2.0.0 or greater.</li>
260
+ <li>The <a href="http://princexml.com">PrinceXML</a> converter version 9.0 or greater.</li>
261
+ <li>The <a href="http://www.amazon.com/gp/feature.html?docId=1000765211">KindleGen</a> converter.</li>
262
+ </ul>
263
+
264
+ <h3 id="installing-ruby">Installing Ruby</h3>
265
+
266
+ <p>To install Ruby, consider using <a href="http://rvm.io">RVM</a> or <a href="http://rbenv.org">rbenv</a>, both available for Mac OSX and Linux distros. If you’re running a Windows, well, I can’t help you. I don’t even know if Kitabu runs over Windows boxes, so if you find any bugs, make sure you <a href="http://github.com/fnando/kitabu/issues">let me know</a>.</p>
267
+
268
+ <h3 id="installing-princexml">Installing PrinceXML</h3>
269
+
270
+ <p><a href="http://princexml.com">PrinceXML</a> is the best HTML to PDF converter available. You can use advanced CSS features to style your book in any way you want. But good things don’t come for free, and PrinceXML is no exception. The Professional License, which you grant you a installation on a single computer by a single user costs 495USD. If you don’t like the price tag, consider using <a href="http://docraptor.com">DocRaptor</a> when you’re ready to publish your book.</p>
271
+
272
+ <p>To install PrinceXML, go to the website and download the correct version for your platform; you can choose from Mac OSX, to Linux and Windows.</p>
273
+
274
+ <h3 id="installing-kindlegen">Installing KindleGen</h3>
275
+
276
+ <p>KindleGen is the command-line tool that allows you to convert e-pubs into <code>.mobi</code> files. You can’t sell these files, though.<sup class="fn-ref"></sup><span class="fn-desc">You can, but that would be a violation of Amazon’s terms of use. </span> So if that’s the case, consider using <a href="http://calibre-ebook.com/">Calibre</a> for this task.<sup class="fn-ref"></sup><span class="fn-desc">Calibre is not perfect, but does a good job. </span></p>
277
+
278
+ <p>If you’re running <a href="http://brew.sh">Homebrew</a> on the Mac OSX, you can install it with <code>brew install kindlegen</code>. Go to <a href="http://www.amazon.com/gp/feature.html?docId=1000765211">KindleGen’s website</a> and download the appropriate installer otherwise.</p>
279
+
280
+
281
+
282
+
283
+ </div>
284
+ <div class="chapter">
285
+ <h2 id="creating-chapters">Creating Chapters</h2>
286
+
287
+ <p>You can create chapters by having multiple files or directories. They’re alphabetically sorted, so make sure you use a prefixed file name like <code>01_Introduction.md</code> as the file name.</p>
288
+
289
+ <p>If you’re going to write a long book, make sure you use the directory organization. This way you can have smaller text files, which will be easier to read and change as you go. A file structure suggestion for a book about <a href="http://guides.rubyonrails.com">Ruby on Rails</a> would be:</p>
290
+ <pre class="highlight plaintext"><code>getting-started-with-rails
291
+ ├── text
292
+    └── 01_Guide_Assumptions.md
293
+    └── 02_Whats_Rails.md
294
+    └── 03_Creating_A_New_Project
295
+    └── 01_Installing_Rails.md
296
+    └── 02_Creating_The_Blog_Application.md
297
+    └── 04_Hello_Rails
298
+    └── 01_Starting_Up_The_Web_Server.md
299
+    └── 02_Say_Hello_Rails.md
300
+    └── 03_Setting_The_Application_Home_Page.md
301
+    └── ...
302
+ </code></pre>
303
+
304
+ <p>Notice that the file name does not need to be readable, but it will make your life easier.</p>
305
+
306
+
307
+ </div>
308
+ <div class="chapter">
309
+ <h2 id="syntax-highlighting">Syntax Highlighting</h2>
310
+
311
+ <h3 id="what-about-the-syntax">What about the syntax</h3>
312
+
313
+ <p>Kitabu uses <a href="http://rubygems.org/gems/rouge">Route</a> as the syntax highlight formatter. It emits an output compatible with stylesheets designed for <a href="https://pygments.org">pygments</a>, the Python library used by many.</p>
314
+
315
+ <p>To highlight a code block, use the fenced block syntax. The following example would be formatted as Ruby.</p>
316
+ <pre class="highlight plaintext"><code>```ruby
317
+ class User
318
+ attr_accessor :name, :email
319
+
320
+ def initialize(name, email)
321
+ @name = name
322
+ @email = email
323
+ end
324
+ end
325
+ ```
326
+ </code></pre>
327
+
328
+ <p>The output would be something like this:</p>
329
+ <pre class="highlight ruby"><code><span class="k">class</span> <span class="nc">User</span>
330
+ <span class="kp">attr_accessor</span> <span class="ss">:name</span><span class="p">,</span> <span class="ss">:email</span>
331
+
332
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">email</span><span class="p">)</span>
333
+ <span class="vi">@name</span> <span class="o">=</span> <span class="nb">name</span>
334
+ <span class="vi">@email</span> <span class="o">=</span> <span class="n">email</span>
335
+ <span class="k">end</span>
336
+ <span class="k">end</span>
337
+ </code></pre>
338
+
339
+ <div class="note info">
340
+ <p>If you’re using Sublime Text, make sure you install the <a href="https://packagecontrol.io/packages/Markdown%20Extended">Markdown Extended</a> plugin; it enables code syntax highlighting on your Markdown files.</p>
341
+ </div>
342
+
343
+ <p>You can also provide inline options such as line numbers and inline rendering.</p>
344
+ <pre class="highlight plaintext"><code>```ruby?line_numbers=1
345
+ class User
346
+ attr_accessor :name, :email
347
+
348
+ def initialize(name, email)
349
+ @name = name
350
+ @email = email
351
+ end
352
+ end
353
+ ```
354
+ </code></pre>
355
+
356
+ <p>This would be rendered like this:</p>
357
+ <div class="highlight ruby">
358
+ <table style="border-spacing: 0"><tbody><tr>
359
+ <td class="gutter gl" style="text-align: right"><pre class="lineno">1
360
+ 2
361
+ 3
362
+ 4
363
+ 5
364
+ 6
365
+ 7
366
+ 8</pre></td>
367
+ <td class="code"><pre><span class="k">class</span> <span class="nc">User</span>
368
+ <span class="kp">attr_accessor</span> <span class="ss">:name</span><span class="p">,</span> <span class="ss">:email</span>
369
+
370
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">email</span><span class="p">)</span>
371
+ <span class="vi">@name</span> <span class="o">=</span> <span class="nb">name</span>
372
+ <span class="vi">@email</span> <span class="o">=</span> <span class="n">email</span>
373
+ <span class="k">end</span>
374
+ <span class="k">end</span>
375
+ </pre></td>
376
+ </tr></tbody></table>
377
+ </div>
378
+
379
+ <h3 id="lexers">Lexers</h3>
380
+
381
+ <p>Rouge comes with dozens of lexers. Check out this list, generated dynamically when you export your e-book.</p>
382
+
383
+ <ul class="lexers-list">
384
+ <li>
385
+ <strong>Apache</strong> <code>apache</code><br><span>configuration files for Apache web server</span>
386
+ </li>
387
+ <li>
388
+ <strong>AppleScript</strong> <code>applescript</code><br><span>The AppleScript scripting language by Apple Inc. (http://developer.apple.com/applescript/)</span>
389
+ </li>
390
+ <li>
391
+ <strong>C</strong> <code>c</code><br><span>The C programming language</span>
392
+ </li>
393
+ <li>
394
+ <strong>Clojure</strong> <code>clojure</code><br><span>The Clojure programming language (clojure.org)</span>
395
+ </li>
396
+ <li>
397
+ <strong>CoffeeScript</strong> <code>coffeescript</code><br><span>The Coffeescript programming language (coffeescript.org)</span>
398
+ </li>
399
+ <li>
400
+ <strong>Common Lisp</strong> <code>common_lisp</code><br><span>The Common Lisp variant of Lisp (common-lisp.net)</span>
401
+ </li>
402
+ <li>
403
+ <strong>Config File</strong> <code>conf</code><br><span>A generic lexer for configuration files</span>
404
+ </li>
405
+ <li>
406
+ <strong>C++</strong> <code>cpp</code><br><span>The C++ programming language</span>
407
+ </li>
408
+ <li>
409
+ <strong>C#</strong> <code>csharp</code><br><span>a multi-paradigm language targeting .NET</span>
410
+ </li>
411
+ <li>
412
+ <strong>CSS</strong> <code>css</code><br><span>Cascading Style Sheets, used to style web pages</span>
413
+ </li>
414
+ <li>
415
+ <strong>Dart</strong> <code>dart</code><br><span>The Dart programming language (dartlang.com)</span>
416
+ </li>
417
+ <li>
418
+ <strong>diff</strong> <code>diff</code><br><span>Lexes unified diffs or patches</span>
419
+ </li>
420
+ <li>
421
+ <strong>Elixir</strong> <code>elixir</code><br><span>Elixir language (elixir-lang.org)</span>
422
+ </li>
423
+ <li>
424
+ <strong>ERB</strong> <code>erb</code><br><span>Embedded ruby template files</span>
425
+ </li>
426
+ <li>
427
+ <strong>Erlang</strong> <code>erlang</code><br><span>The Erlang programming language (erlang.org)</span>
428
+ </li>
429
+ <li>
430
+ <strong>Factor</strong> <code>factor</code><br><span>Factor, the practical stack language (factorcode.org)</span>
431
+ </li>
432
+ <li>
433
+ <strong>Gherkin</strong> <code>gherkin</code><br><span>A business-readable spec DSL ( github.com/cucumber/cucumber/wiki/Gherkin )</span>
434
+ </li>
435
+ <li>
436
+ <strong>Go</strong> <code>go</code><br><span>The Go programming language (http://golang.org)</span>
437
+ </li>
438
+ <li>
439
+ <strong>Groovy</strong> <code>groovy</code><br><span>The Groovy programming language (groovy.codehaus.org)</span>
440
+ </li>
441
+ <li>
442
+ <strong>Haml</strong> <code>haml</code><br><span>The Haml templating system for Ruby (haml.info)</span>
443
+ </li>
444
+ <li>
445
+ <strong>Handlebars</strong> <code>handlebars</code><br><span>the Handlebars and Mustache templating languages</span>
446
+ </li>
447
+ <li>
448
+ <strong>Haskell</strong> <code>haskell</code><br><span>The Haskell programming language (haskell.org)</span>
449
+ </li>
450
+ <li>
451
+ <strong>HTML</strong> <code>html</code><br><span>HTML, the markup language of the web</span>
452
+ </li>
453
+ <li>
454
+ <strong>HTTP</strong> <code>http</code><br><span>http requests and responses</span>
455
+ </li>
456
+ <li>
457
+ <strong>INI</strong> <code>ini</code><br><span>the INI configuration format</span>
458
+ </li>
459
+ <li>
460
+ <strong>Io</strong> <code>io</code><br><span>The IO programming language (http://iolanguage.com)</span>
461
+ </li>
462
+ <li>
463
+ <strong>Java</strong> <code>java</code><br><span>The Java programming language (java.com)</span>
464
+ </li>
465
+ <li>
466
+ <strong>JavaScript</strong> <code>javascript</code><br><span>JavaScript, the browser scripting language</span>
467
+ </li>
468
+ <li>
469
+ <strong>Json</strong> <code>json</code><br><span>JavaScript Object Notation (json.org)</span>
470
+ </li>
471
+ <li>
472
+ <strong>Liquid</strong> <code>liquid</code><br><span>Liquid is a templating engine for Ruby (liquidmarkup.org)</span>
473
+ </li>
474
+ <li>
475
+ <strong>Literate CoffeeScript</strong> <code>literate_coffeescript</code><br><span>Literate coffeescript</span>
476
+ </li>
477
+ <li>
478
+ <strong>Literate Haskell</strong> <code>literate_haskell</code><br><span>Literate haskell</span>
479
+ </li>
480
+ <li>
481
+ <strong>LLVM</strong> <code>llvm</code><br><span>The LLVM Compiler Infrastructure (http://llvm.org/)</span>
482
+ </li>
483
+ <li>
484
+ <strong>Lua</strong> <code>lua</code><br><span>Lua (http://www.lua.org)</span>
485
+ </li>
486
+ <li>
487
+ <strong>Make</strong> <code>make</code><br><span>Makefile syntax</span>
488
+ </li>
489
+ <li>
490
+ <strong>Markdown</strong> <code>markdown</code><br><span>Markdown, a light-weight markup language for authors</span>
491
+ </li>
492
+ <li>
493
+ <strong>MATLAB</strong> <code>matlab</code><br><span>Matlab</span>
494
+ </li>
495
+ <li>
496
+ <strong>MoonScript</strong> <code>moonscript</code><br><span>Moonscript (http://www.moonscript.org)</span>
497
+ </li>
498
+ <li>
499
+ <strong>nginx</strong> <code>nginx</code><br><span>configuration files for the nginx web server (nginx.org)</span>
500
+ </li>
501
+ <li>
502
+ <strong>Nim</strong> <code>nim</code><br><span>The Nim programming language (http://nim-lang.org/)</span>
503
+ </li>
504
+ <li>
505
+ <strong>Objective-C</strong> <code>objective_c</code><br><span>an extension of C commonly used to write Apple software</span>
506
+ </li>
507
+ <li>
508
+ <strong>OCaml</strong> <code>ocaml</code><br><span>Objective CAML (ocaml.org)</span>
509
+ </li>
510
+ <li>
511
+ <strong>Perl</strong> <code>perl</code><br><span>The Perl scripting language (perl.org)</span>
512
+ </li>
513
+ <li>
514
+ <strong>PHP</strong> <code>php</code><br><span>The PHP scripting language (php.net)</span>
515
+ </li>
516
+ <li>
517
+ <strong>Plain Text</strong> <code>plaintext</code><br><span>A boring lexer that doesn’t highlight anything</span>
518
+ </li>
519
+ <li>
520
+ <strong>Prolog</strong> <code>prolog</code><br><span>The Prolog programming language (http://en.wikipedia.org/wiki/Prolog)</span>
521
+ </li>
522
+ <li>
523
+ <strong>.properties</strong> <code>properties</code><br><span>.properties config files for Java</span>
524
+ </li>
525
+ <li>
526
+ <strong>Puppet</strong> <code>puppet</code><br><span>The Puppet configuration management language (puppetlabs.org)</span>
527
+ </li>
528
+ <li>
529
+ <strong>Python</strong> <code>python</code><br><span>The Python programming language (python.org)</span>
530
+ </li>
531
+ <li>
532
+ <strong>QML</strong> <code>qml</code><br><span>QML, a UI markup language</span>
533
+ </li>
534
+ <li>
535
+ <strong>R</strong> <code>r</code><br><span>The R statistics language (r-project.org)</span>
536
+ </li>
537
+ <li>
538
+ <strong>Racket</strong> <code>racket</code><br><span>Racket is a Lisp descended from Scheme (racket-lang.org)</span>
539
+ </li>
540
+ <li>
541
+ <strong>Ruby</strong> <code>ruby</code><br><span>The Ruby programming language (ruby-lang.org)</span>
542
+ </li>
543
+ <li>
544
+ <strong>Rust</strong> <code>rust</code><br><span>The Rust programming language (rust-lang.org)</span>
545
+ </li>
546
+ <li>
547
+ <strong>Sass</strong> <code>sass</code><br><span>The Sass stylesheet language language (sass-lang.com)</span>
548
+ </li>
549
+ <li>
550
+ <strong>Scala</strong> <code>scala</code><br><span>The Scala programming language (scala-lang.org)</span>
551
+ </li>
552
+ <li>
553
+ <strong>Scheme</strong> <code>scheme</code><br><span>The Scheme variant of Lisp</span>
554
+ </li>
555
+ <li>
556
+ <strong>SCSS</strong> <code>scss</code><br><span>SCSS stylesheets (sass-lang.com)</span>
557
+ </li>
558
+ <li>
559
+ <strong>sed</strong> <code>sed</code><br><span>sed, the ultimate stream editor</span>
560
+ </li>
561
+ <li>
562
+ <strong>shell</strong> <code>shell</code><br><span>Various shell languages, including sh and bash</span>
563
+ </li>
564
+ <li>
565
+ <strong>Slim</strong> <code>slim</code><br><span>The Slim template language</span>
566
+ </li>
567
+ <li>
568
+ <strong>Smalltalk</strong> <code>smalltalk</code><br><span>The Smalltalk programming language</span>
569
+ </li>
570
+ <li>
571
+ <strong>SML</strong> <code>sml</code><br><span>Standard ML</span>
572
+ </li>
573
+ <li>
574
+ <strong>SQL</strong> <code>sql</code><br><span>Structured Query Language, for relational databases</span>
575
+ </li>
576
+ <li>
577
+ <strong>Swift</strong> <code>swift</code><br><span>Multi paradigm, compiled programming language developed by Apple for iOS and OS X development. (developer.apple.com/swift)</span>
578
+ </li>
579
+ <li>
580
+ <strong>Tcl</strong> <code>tcl</code><br><span>The Tool Command Language (tcl.tk)</span>
581
+ </li>
582
+ <li>
583
+ <strong>TeX</strong> <code>tex</code><br><span>The TeX typesetting system</span>
584
+ </li>
585
+ <li>
586
+ <strong>TOML</strong> <code>toml</code><br><span>the TOML configuration format (https://github.com/mojombo/toml)</span>
587
+ </li>
588
+ <li>
589
+ <strong>Visual Basic</strong> <code>vb</code><br><span>Visual Basic</span>
590
+ </li>
591
+ <li>
592
+ <strong>VimL</strong> <code>viml</code><br><span>VimL, the scripting language for the Vim editor (vim.org)</span>
593
+ </li>
594
+ <li>
595
+ <strong>XML</strong> <code>xml</code><br><span><desc for="this-lexer">XML</desc></span>
596
+ </li>
597
+ <li>
598
+ <strong>YAML</strong> <code>yaml</code><br><span>Yaml Ain’t Markup Language (yaml.org)</span>
599
+ </li>
600
+ </ul>
601
+
602
+ <p>And if what you want is not on this list, make you <a href="https://github.com/jneen/rouge/issues">open a ticket</a> on the project.</p>
603
+
604
+
605
+ </div>
606
+ <div class="chapter">
607
+ <h2 id="dynamic-content">Dynamic Content</h2>
608
+
609
+ <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>
610
+
611
+ <p>On the previous chapter, we listed all supported Rouge lexers. To do that, I created a helper that looks like this:</p>
612
+ <pre class="highlight ruby"><code><span class="k">module</span> <span class="nn">Kitabu</span>
613
+ <span class="k">module</span> <span class="nn">Helpers</span>
614
+ <span class="k">def</span> <span class="nf">lexers_list</span>
615
+ <span class="n">buffer</span> <span class="o">=</span> <span class="s1">'&lt;ul class="lexers"&gt;'</span>
616
+
617
+ <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>
618
+ <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>
619
+
620
+ <span class="k">begin</span>
621
+ <span class="n">title</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">title</span>
622
+ <span class="n">tag</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">tag</span>
623
+ <span class="n">description</span> <span class="o">=</span> <span class="n">lexer</span><span class="p">.</span><span class="nf">desc</span>
624
+ <span class="k">rescue</span> <span class="no">Exception</span> <span class="o">=&gt;</span> <span class="n">e</span>
625
+ <span class="k">next</span>
626
+ <span class="k">end</span>
627
+
628
+ <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;li&gt;'</span>
629
+ <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>
630
+ <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>
631
+ <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>
632
+ <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;/li&gt;'</span>
633
+ <span class="k">end</span>
634
+
635
+ <span class="n">buffer</span> <span class="o">&lt;&lt;</span> <span class="s1">'&lt;/ul&gt;'</span>
636
+ <span class="n">buffer</span>
637
+ <span class="k">end</span>
638
+ <span class="k">end</span>
639
+ <span class="k">end</span>
640
+ </code></pre>
641
+
642
+ <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>
643
+
644
+ <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>
645
+ <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>
646
+ Some text that will be parsed as Markdown.
647
+ <span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span>
648
+ </code></pre>
649
+
650
+ <p>By default, this will generate a <code>&lt;div class="note info"&gt;</code> tag, but you can use anything you want.</p>
651
+ <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>
652
+ Some text that will be parsed as Markdown.
653
+ <span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span>
654
+ </code></pre>
655
+
656
+ <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>
657
+
658
+ <h3 id="escaping-erb-code">Escaping ERb code</h3>
659
+
660
+ <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>
661
+ <pre class="highlight plaintext"><code>&lt;%%= Date.today %&gt;
662
+ </code></pre>
663
+
664
+
665
+ </div>
666
+ <div class="chapter">
667
+ <h2 id="exporting-files">Exporting Files</h2>
668
+
669
+ <p>You can generate files as you go. Just execute <code>kitabu export</code> from your book’s root directory.</p>
670
+ <pre class="highlight plaintext"><code>$ kitabu export
671
+ ** e-book has been exported
672
+ </code></pre>
673
+
674
+ <p>This command will generate all supported formats<sup class="fn-ref"></sup><span class="fn-desc">Depend on Prince, html2text and KindleGen being available on your <code>$PATH</code>. </span>. The generated files will be placed on your <code>output</code> directory; the following output list only the relevant files.</p>
675
+ <pre class="highlight plaintext"><code>$ tree output
676
+ output
677
+ ├── images
678
+ │   ├── kitabu.png
679
+ │   └── kitabu.svg
680
+ ├── kitabu.epub
681
+ ├── kitabu.html
682
+ ├── kitabu.mobi
683
+ ├── kitabu.pdf
684
+ ├── kitabu.print.pdf
685
+ ├── kitabu.txt
686
+ └── styles
687
+ ├── epub.css
688
+ ├── html.css
689
+ ├── pdf.css
690
+ └── print.css
691
+ </code></pre>
692
+
693
+ <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>
694
+ <pre class="highlight plaintext"><code>$ kitabu export --only pdf
695
+ </code></pre>
696
+
697
+ <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>
698
+ <pre class="highlight plaintext"><code>$ bundle exec guard
699
+ 20:38:10 - INFO - Guard is now watching at '/Users/fnando/Projects/kitabu/examples/kitabu'
700
+ ** e-book has been exported
701
+ </code></pre>
702
+
703
+ <h3 id="exporting-pdf-with-docraptor">Exporting PDF with DocRaptor</h3>
704
+
705
+ <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>
706
+
707
+
708
+
709
+
710
+ </div>
711
+
712
+ </div>
713
+
714
+
715
+
716
+ <div class="white-page"></div>
717
+
718
+ <div class="imprint container">
719
+ <div>
720
+ <h2>Kitabu</h2>
721
+ <p class="description">This guide will help you understand how all of the pieces fit together on Kitabu.</p>
722
+ <p class="authors">Nando Vieira</p>
723
+ <p class="copyright">Copyright (C) 2015 Nando Vieira.</p>
724
+ </div>
725
+ </div>
726
+
727
+ <a href="#" class="go-top">⇧</a>
728
+ </body>
729
+ </html>