rpub 0.4.0 → 0.5.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 (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -1
  3. data/.rspec +0 -1
  4. data/.travis.yml +3 -4
  5. data/.yardopts +1 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +70 -46
  8. data/Guardfile +6 -0
  9. data/HISTORY.md +10 -0
  10. data/README.md +1 -1
  11. data/Rakefile +7 -2
  12. data/bin/rpub +64 -1
  13. data/doc/.gitignore +8 -0
  14. data/doc/api/Rpub.html +339 -0
  15. data/doc/api/Rpub/Book.html +983 -0
  16. data/doc/api/Rpub/Chapter.html +737 -0
  17. data/doc/api/Rpub/Command.html +356 -0
  18. data/doc/api/Rpub/Commands.html +117 -0
  19. data/doc/api/Rpub/Commands/Clean.html +216 -0
  20. data/doc/api/Rpub/Commands/Compile.html +218 -0
  21. data/doc/api/Rpub/Commands/Generate.html +242 -0
  22. data/doc/api/Rpub/Commands/Package.html +230 -0
  23. data/doc/api/Rpub/Commands/Preview.html +216 -0
  24. data/doc/api/Rpub/Commands/Stats.html +226 -0
  25. data/doc/api/Rpub/Compressor.html +687 -0
  26. data/doc/api/Rpub/Context.html +553 -0
  27. data/doc/api/Rpub/Document.html +647 -0
  28. data/doc/api/Rpub/Document/OutlineElement.html +388 -0
  29. data/doc/api/Rpub/Epub.html +465 -0
  30. data/doc/api/Rpub/Epub/Container.html +224 -0
  31. data/doc/api/Rpub/Epub/Content.html +344 -0
  32. data/doc/api/Rpub/Epub/Cover.html +236 -0
  33. data/doc/api/Rpub/Epub/HtmlToc.html +240 -0
  34. data/doc/api/Rpub/Epub/Toc.html +244 -0
  35. data/doc/api/Rpub/FilesystemSource.html +544 -0
  36. data/doc/api/Rpub/HashDelegation.html +281 -0
  37. data/doc/api/Rpub/HashDelegation/ClassMethods.html +175 -0
  38. data/doc/api/Rpub/MediaType.html +192 -0
  39. data/doc/api/Rpub/Preview.html +464 -0
  40. data/doc/api/Rpub/XmlFile.html +457 -0
  41. data/doc/api/_index.html +405 -0
  42. data/doc/api/class_list.html +54 -0
  43. data/doc/api/css/common.css +1 -0
  44. data/doc/api/css/full_list.css +57 -0
  45. data/doc/api/css/style.css +339 -0
  46. data/doc/api/file.HISTORY.html +131 -0
  47. data/doc/api/file.LICENSE.html +92 -0
  48. data/doc/api/file.README.html +337 -0
  49. data/doc/api/file_list.html +62 -0
  50. data/doc/api/frames.html +26 -0
  51. data/doc/api/index.html +337 -0
  52. data/doc/api/js/app.js +219 -0
  53. data/doc/api/js/full_list.js +178 -0
  54. data/doc/api/js/jquery.js +4 -0
  55. data/doc/api/method_list.html +533 -0
  56. data/doc/api/top-level-namespace.html +112 -0
  57. data/doc/index.html +312 -0
  58. data/doc/javascripts/scale.fix.js +17 -0
  59. data/doc/params.json +1 -0
  60. data/doc/stylesheets/pygment_trac.css +69 -0
  61. data/doc/stylesheets/styles.css +255 -0
  62. data/features/clean.feature +31 -0
  63. data/features/compile.feature +49 -0
  64. data/features/embedded_assets.feature +51 -0
  65. data/features/generate.feature +63 -0
  66. data/features/layout.feature +41 -0
  67. data/features/package.feature +30 -0
  68. data/features/previews.feature +66 -0
  69. data/features/stats.feature +18 -0
  70. data/features/step_definitions/general_steps.rb +60 -0
  71. data/features/styles.feature +33 -0
  72. data/features/support/env.rb +7 -0
  73. data/features/table_of_contents.feature +35 -0
  74. data/lib/rpub.rb +28 -31
  75. data/lib/rpub/book.rb +9 -16
  76. data/lib/rpub/chapter.rb +4 -54
  77. data/lib/rpub/command.rb +32 -0
  78. data/lib/rpub/commands/clean.rb +4 -49
  79. data/lib/rpub/commands/compile.rb +4 -49
  80. data/lib/rpub/commands/generate.rb +10 -67
  81. data/lib/rpub/commands/package.rb +9 -37
  82. data/lib/rpub/commands/preview.rb +4 -54
  83. data/lib/rpub/commands/stats.rb +6 -10
  84. data/lib/rpub/compressor.rb +3 -3
  85. data/lib/rpub/context.rb +48 -0
  86. data/lib/rpub/document.rb +68 -0
  87. data/lib/rpub/epub.rb +8 -7
  88. data/lib/rpub/epub/content.rb +9 -30
  89. data/lib/rpub/epub/cover.rb +1 -8
  90. data/lib/rpub/epub/html_toc.rb +4 -9
  91. data/lib/rpub/epub/toc.rb +16 -13
  92. data/lib/rpub/filesystem_source.rb +47 -0
  93. data/lib/rpub/media_type.rb +16 -0
  94. data/lib/rpub/preview.rb +29 -0
  95. data/lib/rpub/version.rb +1 -1
  96. data/lib/rpub/xml_file.rb +4 -1
  97. data/rpub.gemspec +6 -7
  98. data/spec/rpub/book_spec.rb +45 -45
  99. data/spec/rpub/chapter_spec.rb +87 -22
  100. data/spec/rpub/epub/container_spec.rb +3 -5
  101. data/spec/rpub/epub/content_spec.rb +62 -41
  102. data/spec/rpub/epub/cover_spec.rb +3 -5
  103. data/spec/rpub/epub/html_toc_spec.rb +8 -8
  104. data/spec/rpub/epub/toc_spec.rb +20 -22
  105. data/spec/rpub_spec.rb +1 -3
  106. data/spec/spec_helper.rb +28 -0
  107. data/support/config.yml +1 -0
  108. data/support/styles.css +3 -3
  109. metadata +131 -120
  110. data/lib/rpub/commander.rb +0 -23
  111. data/lib/rpub/commands/base.rb +0 -33
  112. data/lib/rpub/commands/help.rb +0 -37
  113. data/lib/rpub/commands/main.rb +0 -45
  114. data/lib/rpub/compilation_helpers.rb +0 -73
  115. data/lib/rpub/subclass_tracker.rb +0 -53
  116. data/spec/rpub/commands/clean_spec.rb +0 -46
  117. data/spec/rpub/commands/generate_spec.rb +0 -52
  118. data/spec/rpub/commands/main_spec.rb +0 -26
  119. data/spec/rpub/commands/package_spec.rb +0 -33
  120. data/spec/rpub/commands/preview_spec.rb +0 -43
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+ <title>Rpub, a simple ePub generator library in Ruby</title>
8
+ </head>
9
+ <script type="text/javascript" charset="utf-8">
10
+ window.onload = function() {
11
+ var match = unescape(window.location.hash).match(/^#!(.+)/);
12
+ var name = match ? match[1] : 'index.html';
13
+ name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
14
+ document.writeln('<frameset cols="20%,*">' +
15
+ '<frame name="list" src="class_list.html" />' +
16
+ '<frame name="main" src="' + escape(name) + '" />' +
17
+ '</frameset>');
18
+ }
19
+ </script>
20
+ <noscript>
21
+ <frameset cols="20%,*">
22
+ <frame name="list" src="class_list.html" />
23
+ <frame name="main" src="index.html" />
24
+ </frameset>
25
+ </noscript>
26
+ </html>
@@ -0,0 +1,337 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Rpub, a simple ePub generator library in Ruby
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!file.README.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+ <span class="title">File: README</span>
36
+
37
+
38
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
39
+ </div>
40
+
41
+ <div id="search">
42
+
43
+ <a class="full_list_link" id="class_list_link"
44
+ href="class_list.html">
45
+ Class List
46
+ </a>
47
+
48
+ <a class="full_list_link" id="method_list_link"
49
+ href="method_list.html">
50
+ Method List
51
+ </a>
52
+
53
+ <a class="full_list_link" id="file_list_link"
54
+ href="file_list.html">
55
+ File List
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <iframe id="search_frame"></iframe>
63
+
64
+ <div id="content"><div id='filecontents'><h1 id="rpub----an-epub-generator-in-ruby-build-statushttpssecuretravis-ciorgavdgaagrpubpngbranchmasterhttptravis-ciorgavdgaagrpub-coverage-statushttpscoverallsioreposavdgaagrpubbadgepnghttpscoverallsioravdgaagrpub">Rpub – an ePub generator in Ruby <a href="http://travis-ci.org/avdgaag/rpub"><img src="https://secure.travis-ci.org/avdgaag/rpub.png?branch=master" alt="Build Status" /></a> <a href="https://coveralls.io/r/avdgaag/rpub"><img src="https://coveralls.io/repos/avdgaag/rpub/badge.png" alt="Coverage Status" /></a></h1>
65
+
66
+ <h2 id="introduction">Introduction</h2>
67
+
68
+ <p>Rpub is a command-line tool that generates a collection of plain text input
69
+ files into an eBook in ePub format. It provides several related functions to
70
+ make working with ePub files a little easier:</p>
71
+
72
+ <ul>
73
+ <li>Generation of table of contents</li>
74
+ <li>Packaging your eBook in an archive with additional README file</li>
75
+ <li>Embedding fonts</li>
76
+ <li>Easy previewing as you write</li>
77
+ <li>.mobi compatibility</li>
78
+ </ul>
79
+
80
+ <h2 id="installation">Installation</h2>
81
+
82
+ <p>Rpub is distributed as a Ruby gem, which should be installed on most Macs and
83
+ Linux systems. Once you have ensured you have a working installation of Ruby
84
+ and Ruby gems, install the gem as follows from the command line:</p>
85
+
86
+ <pre class="code ruby"><code class="ruby">$ gem install rpub
87
+ </code></pre>
88
+
89
+ <p>You can verify the gem has installed correctly by checking its version number:</p>
90
+
91
+ <pre class="code ruby"><code class="ruby">$ rpub -v
92
+ </code></pre>
93
+
94
+ <p>If this generates an error, something has gone wrong. You should see something
95
+ along the lines of <code>rpub 1.0.0</code>.</p>
96
+
97
+ <h2 id="usage">Usage</h2>
98
+
99
+ <h3 id="basics">Basics</h3>
100
+
101
+ <p>ePubs are basically collections of HTML files, combined in a single archive
102
+ according to a set of predefined rules. Rpub generates these files for you from
103
+ simple text files written in <a href="http://daringfireball.net/projects/markdown">Markdown</a>, a very readable markup language created
104
+ by <a href="http://daringfireball.net">John Gruber</a>. This very README file is an example of a Markdown document.</p>
105
+
106
+ <p>The idea is you write several Markdown files using your favourite text editor,
107
+ and save them as plain text in your project directory. Usually you would write
108
+ one file per chapter. By invoking the <code>rpub</code> program you convert those files to
109
+ HTML and combine them in an ePub archive:</p>
110
+
111
+ <pre class="code ruby"><code class="ruby">$ rpub compile
112
+ Generating my-new-book-0.1.0.epub... Done!
113
+ </code></pre>
114
+
115
+ <p>After you have run the <code>rpub compile</code> command, you will find a new <code>.epub</code> file
116
+ in your project directory. The name of this file depends on the title of your
117
+ book, and its version number. You can set these values, as well as a few others,
118
+ in a special configuration file called <code>config.yml</code>:</p>
119
+
120
+ <pre class="code ruby"><code class="ruby">---
121
+ author: Your Name
122
+ title: My new book
123
+ version: 0.1.0
124
+ </code></pre>
125
+
126
+ <p>This file is written in <a href="http://yaml.org">YAML</a> and sets basic properties of
127
+ your book project.</p>
128
+
129
+ <p>Since regenerating your ePub file and opening it in a suitable reader
130
+ application is cumbersome, Rpub can generate a simple preview document for you:</p>
131
+
132
+ <pre class="code ruby"><code class="ruby">$ rpub preview
133
+ </code></pre>
134
+
135
+ <p>This will generate a new HTML file in your project directory with a name similar
136
+ to your ePub file. This is the entire text of your book as a single web page for
137
+ easy viewing in any browser.</p>
138
+
139
+ <h3 id="generating-a-mobi-file">Generating a .mobi file</h3>
140
+
141
+ <p>Since the ePub and Mobipocket file formats are very (<em>very</em>) similar it is
142
+ quite easy to create a <code>.mobi</code> version of your book, suitable for reading on
143
+ Amazon’s Kindle. To do so, you will need to install the <a href="http://www.amazon.com/gp/feature.html?ie=UTF8&amp;docId=1000765211">kindlegen program
144
+ Amazon provides</a>.</p>
145
+
146
+ <p>Here’s how it works:</p>
147
+
148
+ <ol>
149
+ <li>Install <code>kindlegen</code> (<a href="http://www.amazon.com/gp/feature.html?ie=UTF8&amp;docId=1000765211">download it here</a>)</li>
150
+ <li>Compile your book as usual using <code>rpub compile</code></li>
151
+ <li>Compile <code>my-book.epub</code> to <code>my-book.mobi</code>: <code>kindlegen my-book.epub</code>.</li>
152
+ </ol>
153
+
154
+ <p>Optionally, include your <code>my-book.mobi</code> in your package by adding it to your
155
+ list of packaged files (see “Packaging for distribution”).</p>
156
+
157
+ <h3 id="advanced-features">Advanced features</h3>
158
+
159
+ <h4 id="packaging-for-distribution">Packaging for distribution</h4>
160
+
161
+ <p>Often you want to distribute your ebook over the internet, along with some
162
+ extra files. You’ll probably want to include a README file, a license or
163
+ references to extra online resources. A <code>package</code> task is defined to generate a
164
+ single compressed archive file from your generated ebook along with such
165
+ additional files.</p>
166
+
167
+ <p>You list the files to include with your ebook in your <code>config.yml</code> file, along
168
+ with the resulting packaged file name:</p>
169
+
170
+ <pre class="code ruby"><code class="ruby">---
171
+ package_file: mybook.zip
172
+ package:
173
+ - README
174
+ - license.txt
175
+ - code-samples.rb
176
+ </code></pre>
177
+
178
+ <p>All the filenames listed under <code>package</code> are looked up in the root of your
179
+ project directory. These files will be combined with the ebook in the
180
+ <code>mybook.zip</code> file in your project directory.</p>
181
+
182
+ <h4 id="automatic-table-of-contents">Automatic table of contents</h4>
183
+
184
+ <p>Rpub automatically generates a table of contents for you, if you want it to. It
185
+ does this by scanning all your markdown files for headings and listing them on
186
+ a single page in the ebook. Each entry in the table of contents is linked to
187
+ its appropriate heading in the chapter, and has various hooks for your
188
+ stylesheet to determine its formatting.</p>
189
+
190
+ <p>To enable the automatic generation of a table of contents, add the following
191
+ configuration to your <code>config.yml</code> file:</p>
192
+
193
+ <pre class="code ruby"><code class="ruby">toc: true
194
+ </code></pre>
195
+
196
+ <p>Note that this only affects the human-readable table of contents, represented
197
+ as a page in your book. Rpub will alway generate the .epub table of contents
198
+ for you, which contains the machine-readable references to your chapters. It
199
+ will, by default, reference all chapter titles and subheadings for you, but
200
+ you can customize the number of levels that will be included using the
201
+ following in your <code>config.yml</code> file:</p>
202
+
203
+ <pre class="code ruby"><code class="ruby">max_level: 3
204
+ </code></pre>
205
+
206
+ <h4 id="custom-layout-and-styles">Custom layout and styles</h4>
207
+
208
+ <p>When you compile a set of Markdown files to an ePub file, rpub uses a default
209
+ HTML layout and set of styles to determine the look and feel of the book. These
210
+ will do fine for most cases, but you can provide your own, if you are so
211
+ inclined.</p>
212
+
213
+ <p>Simply define a <code>layout.html</code> and/or <code>styles.css</code> in your project directory.
214
+ Your HTML file will be parsed with Erb, an so you can include your writing
215
+ using the <code>@body</code> instance variable:</p>
216
+
217
+ <pre class="code ruby"><code class="ruby">&lt;html&gt;
218
+ &lt;body&gt;
219
+ &lt;%= @body %&gt;
220
+ &lt;/body&gt;
221
+ &lt;/html&gt;
222
+ </code></pre>
223
+
224
+ <p><strong>Note 1</strong>: this feature is actually provided by the <a href="http://kramdown.rubyforge.org">Kramdown gem</a>,
225
+ so have a look at <a href="https://github.com/gettalong/kramdown/blob/master/data/kramdown/document.html">the standard Kramdown document template</a> to see some
226
+ nifty tricks.</p>
227
+
228
+ <p><strong>Note 2</strong>: despite the name ‘html’ and <code>.html</code> extension, your file actually has
229
+ to be XHTML-compliant.</p>
230
+
231
+ <p>You can also provide custom layouts or styles to use when invoking the <code>compile</code>
232
+ or <code>preview</code> commands, using the <code>-l</code> or <code>-s</code> options:</p>
233
+
234
+ <pre class="code ruby"><code class="ruby">$ rpub compile -l /tmp/my-layout.html
235
+ </code></pre>
236
+
237
+ <p>If you like the default layout or styles, but want to adapt them, you can copy
238
+ those files into your project using the <code>generate</code> subcommand:</p>
239
+
240
+ <pre class="code ruby"><code class="ruby">$ rpub generate
241
+ </code></pre>
242
+
243
+ <h3 id="command-reference">Command reference</h3>
244
+
245
+ <dl>
246
+ <dt><code>rpub compile</code></dt>
247
+ <dd>generate .epub file</dd>
248
+ <dt><code>rpub package</code></dt>
249
+ <dd>create zip file with compiled book and other listed files</dd>
250
+ <dt><code>rpub preview</code></dt>
251
+ <dd>generate preview HTML file</dd>
252
+ <dt><code>rpub generate</code></dt>
253
+ <dd>copy default layout.html, styles.css and config.yml</dd>
254
+ <dt><code>rpub help</code></dt>
255
+ <dd>get help on subcommands</dd>
256
+ <dt><code>rpub clean</code></dt>
257
+ <dd>remove generated files</dd>
258
+ </dl>
259
+
260
+ <h3 id="configuration-reference">Configuration reference</h3>
261
+
262
+ <dl>
263
+ <dt><code>title</code></dt>
264
+ <dd>the book title (string)</dd>
265
+ <dt><code>descrption</code></dt>
266
+ <dd>one-line summary of the book (string)</dd>
267
+ <dt><code>creator</code></dt>
268
+ <dd>author name (string)</dd>
269
+ <dt><code>publisher</code></dt>
270
+ <dd>publisher name (string)</dd>
271
+ <dt><code>subject</code></dt>
272
+ <dd>book subject/category (string)</dd>
273
+ <dt><code>language</code></dt>
274
+ <dd>language code of the book contents, e.g. ‘en’ (string)</dd>
275
+ <dt><code>rights</code></dt>
276
+ <dd>copyright line (string)</dd>
277
+ <dt><code>version</code></dt>
278
+ <dd>version number of the book to include in the .epub filename (string)</dd>
279
+ <dt><code>toc</code></dt>
280
+ <dd>whether to generate a table of contents as book page (boolean, default false)</dd>
281
+ <dt><code>max_level</code></dt>
282
+ <dd>the maximum depth of the .epub table of contents (number, default 2)</dd>
283
+ <dt><code>ignore</code></dt>
284
+ <dd>list of files not to include in the epub, that otherwise would (array)</dd>
285
+ <dt><code>package</code></dt>
286
+ <dd>list of files to be included in the archive created by the package task (array)</dd>
287
+ </dl>
288
+
289
+ <h3 id="examples">Examples</h3>
290
+
291
+ <p>See the <a href="https://github.com/avdgaag/rpub/tree/master/example">examples directory</a> for two example projects.</p>
292
+
293
+ <h3 id="documentation">Documentation</h3>
294
+
295
+ <p>See the inline <a href="http://rubydoc.info/github/avdgaag/rpub/master/frames">API docs</a> for more information.</p>
296
+
297
+ <h2 id="other">Other</h2>
298
+
299
+ <h3 id="note-on-patchespull-requests">Note on Patches/Pull Requests</h3>
300
+
301
+ <ol>
302
+ <li>Fork the project.</li>
303
+ <li>Make your feature addition or bug fix.</li>
304
+ <li>Add tests for it. This is important so I don’t break it in a future version
305
+ unintentionally.</li>
306
+ <li>Commit, do not mess with rakefile, version, or history. (if you want to have
307
+ your own version, that is fine but bump version in a commit by itself I can
308
+ ignore when I pull)</li>
309
+ <li>Send me a pull request. Bonus points for topic branches.</li>
310
+ </ol>
311
+
312
+ <h3 id="issues">Issues</h3>
313
+
314
+ <p>Please report any issues, defects or suggestions in the <a href="https://github.com/avdgaag/rpub/issues">Github issue
315
+ tracker</a>.</p>
316
+
317
+ <h3 id="what-has-changed">What has changed?</h3>
318
+
319
+ <p>See the <a href="https://github.com/avdgaag/rpub/blob/master/HISTORY.md">HISTORY</a> file for a detailed changelog.</p>
320
+
321
+ <h3 id="credits">Credits</h3>
322
+
323
+ <p>Created by: Arjan van der Gaag<br />
324
+ URL: <a href="http://arjanvandergaag.nl">http://arjanvandergaag.nl</a><br />
325
+ Project homepage: <a href="http://avdgaag.github.com/rpub">http://avdgaag.github.com/rpub</a><br />
326
+ Date: april 2012<br />
327
+ License: <a href="https://github.com/avdgaag/rpub/LICENSE">MIT-license</a> (same as Ruby)</p>
328
+ </div></div>
329
+
330
+ <div id="footer">
331
+ Generated on Thu Aug 14 19:54:32 2014 by
332
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
333
+ 0.8.7.4 (ruby-2.1.2).
334
+ </div>
335
+
336
+ </body>
337
+ </html>
@@ -0,0 +1,219 @@
1
+ function createSourceLinks() {
2
+ $('.method_details_list .source_code').
3
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
+ $('.toggleSource').toggle(function() {
5
+ $(this).parent().nextAll('.source_code').slideDown(100);
6
+ $(this).text("Hide source");
7
+ },
8
+ function() {
9
+ $(this).parent().nextAll('.source_code').slideUp(100);
10
+ $(this).text("View source");
11
+ });
12
+ }
13
+
14
+ function createDefineLinks() {
15
+ var tHeight = 0;
16
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17
+ $('.toggleDefines').toggle(function() {
18
+ tHeight = $(this).parent().prev().height();
19
+ $(this).prev().show();
20
+ $(this).parent().prev().height($(this).parent().height());
21
+ $(this).text("(less)");
22
+ },
23
+ function() {
24
+ $(this).prev().hide();
25
+ $(this).parent().prev().height(tHeight);
26
+ $(this).text("more...");
27
+ });
28
+ }
29
+
30
+ function createFullTreeLinks() {
31
+ var tHeight = 0;
32
+ $('.inheritanceTree').toggle(function() {
33
+ tHeight = $(this).parent().prev().height();
34
+ $(this).parent().toggleClass('showAll');
35
+ $(this).text("(hide)");
36
+ $(this).parent().prev().height($(this).parent().height());
37
+ },
38
+ function() {
39
+ $(this).parent().toggleClass('showAll');
40
+ $(this).parent().prev().height(tHeight);
41
+ $(this).text("show all");
42
+ });
43
+ }
44
+
45
+ function fixBoxInfoHeights() {
46
+ $('dl.box dd.r1, dl.box dd.r2').each(function() {
47
+ $(this).prev().height($(this).height());
48
+ });
49
+ }
50
+
51
+ function searchFrameLinks() {
52
+ $('.full_list_link').click(function() {
53
+ toggleSearchFrame(this, $(this).attr('href'));
54
+ return false;
55
+ });
56
+ }
57
+
58
+ function toggleSearchFrame(id, link) {
59
+ var frame = $('#search_frame');
60
+ $('#search a').removeClass('active').addClass('inactive');
61
+ if (frame.attr('src') == link && frame.css('display') != "none") {
62
+ frame.slideUp(100);
63
+ $('#search a').removeClass('active inactive');
64
+ }
65
+ else {
66
+ $(id).addClass('active').removeClass('inactive');
67
+ frame.attr('src', link).slideDown(100);
68
+ }
69
+ }
70
+
71
+ function linkSummaries() {
72
+ $('.summary_signature').click(function() {
73
+ document.location = $(this).find('a').attr('href');
74
+ });
75
+ }
76
+
77
+ function framesInit() {
78
+ if (hasFrames) {
79
+ document.body.className = 'frames';
80
+ $('#menu .noframes a').attr('href', document.location);
81
+ try {
82
+ window.top.document.title = $('html head title').text();
83
+ } catch(error) {
84
+ // some browsers will not allow this when serving from file://
85
+ // but we don't want to stop the world.
86
+ }
87
+ }
88
+ else {
89
+ $('#menu .noframes a').text('frames').attr('href', framesUrl);
90
+ }
91
+ }
92
+
93
+ function keyboardShortcuts() {
94
+ if (window.top.frames.main) return;
95
+ $(document).keypress(function(evt) {
96
+ if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
97
+ if (typeof evt.target !== "undefined" &&
98
+ (evt.target.nodeName == "INPUT" ||
99
+ evt.target.nodeName == "TEXTAREA")) return;
100
+ switch (evt.charCode) {
101
+ case 67: case 99: $('#class_list_link').click(); break; // 'c'
102
+ case 77: case 109: $('#method_list_link').click(); break; // 'm'
103
+ case 70: case 102: $('#file_list_link').click(); break; // 'f'
104
+ default: break;
105
+ }
106
+ });
107
+ }
108
+
109
+ function summaryToggle() {
110
+ $('.summary_toggle').click(function() {
111
+ if (localStorage) {
112
+ localStorage.summaryCollapsed = $(this).text();
113
+ }
114
+ $('.summary_toggle').each(function() {
115
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
116
+ var next = $(this).parent().parent().nextAll('ul.summary').first();
117
+ if (next.hasClass('compact')) {
118
+ next.toggle();
119
+ next.nextAll('ul.summary').first().toggle();
120
+ }
121
+ else if (next.hasClass('summary')) {
122
+ var list = $('<ul class="summary compact" />');
123
+ list.html(next.html());
124
+ list.find('.summary_desc, .note').remove();
125
+ list.find('a').each(function() {
126
+ $(this).html($(this).find('strong').html());
127
+ $(this).parent().html($(this)[0].outerHTML);
128
+ });
129
+ next.before(list);
130
+ next.toggle();
131
+ }
132
+ });
133
+ return false;
134
+ });
135
+ if (localStorage) {
136
+ if (localStorage.summaryCollapsed == "collapse") {
137
+ $('.summary_toggle').first().click();
138
+ }
139
+ else localStorage.summaryCollapsed = "expand";
140
+ }
141
+ }
142
+
143
+ function fixOutsideWorldLinks() {
144
+ $('a').each(function() {
145
+ if (window.location.host != this.host) this.target = '_parent';
146
+ });
147
+ }
148
+
149
+ function generateTOC() {
150
+ if ($('#filecontents').length === 0) return;
151
+ var _toc = $('<ol class="top"></ol>');
152
+ var show = false;
153
+ var toc = _toc;
154
+ var counter = 0;
155
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
156
+ var i;
157
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
158
+ for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
159
+ var lastTag = parseInt(tags[0][1], 10);
160
+ $(tags.join(', ')).each(function() {
161
+ if ($(this).parents('.method_details .docstring').length != 0) return;
162
+ if (this.id == "filecontents") return;
163
+ show = true;
164
+ var thisTag = parseInt(this.tagName[1], 10);
165
+ if (this.id.length === 0) {
166
+ var proposedId = $(this).attr('toc-id');
167
+ if (typeof(proposedId) != "undefined") this.id = proposedId;
168
+ else {
169
+ var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
170
+ if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
171
+ this.id = proposedId;
172
+ }
173
+ }
174
+ if (thisTag > lastTag) {
175
+ for (i = 0; i < thisTag - lastTag; i++) {
176
+ var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
177
+ }
178
+ }
179
+ if (thisTag < lastTag) {
180
+ for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
181
+ }
182
+ var title = $(this).attr('toc-title');
183
+ if (typeof(title) == "undefined") title = $(this).text();
184
+ toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
185
+ lastTag = thisTag;
186
+ });
187
+ if (!show) return;
188
+ html = '<div id="toc"><p class="title"><a class="hide_toc" href="#"><strong>Table of Contents</strong></a> <small>(<a href="#" class="float_toc">left</a>)</small></p></div>';
189
+ $('#content').prepend(html);
190
+ $('#toc').append(_toc);
191
+ $('#toc .hide_toc').toggle(function() {
192
+ $('#toc .top').slideUp('fast');
193
+ $('#toc').toggleClass('hidden');
194
+ $('#toc .title small').toggle();
195
+ }, function() {
196
+ $('#toc .top').slideDown('fast');
197
+ $('#toc').toggleClass('hidden');
198
+ $('#toc .title small').toggle();
199
+ });
200
+ $('#toc .float_toc').toggle(function() {
201
+ $(this).text('float');
202
+ $('#toc').toggleClass('nofloat');
203
+ }, function() {
204
+ $(this).text('left');
205
+ $('#toc').toggleClass('nofloat');
206
+ });
207
+ }
208
+
209
+ $(framesInit);
210
+ $(createSourceLinks);
211
+ $(createDefineLinks);
212
+ $(createFullTreeLinks);
213
+ $(fixBoxInfoHeights);
214
+ $(searchFrameLinks);
215
+ $(linkSummaries);
216
+ $(keyboardShortcuts);
217
+ $(summaryToggle);
218
+ $(fixOutsideWorldLinks);
219
+ $(generateTOC);