erbook 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/LICENSE +1 -1
  2. data/Rakefile +6 -79
  3. data/bin/erbook +25 -319
  4. data/doc/HelloWorld.spec +23 -21
  5. data/doc/README +4 -3
  6. data/doc/api/ERBook.html +35 -0
  7. data/doc/api/ERBook/Document.html +673 -0
  8. data/doc/api/ERBook/Document/Node.html +102 -0
  9. data/doc/api/ERBook/Template.html +670 -0
  10. data/doc/api/RDoc.html +23 -0
  11. data/doc/api/RDoc/AnyMethod.html +302 -0
  12. data/doc/api/RDoc/DummyMarkup.html +73 -0
  13. data/doc/api/RDoc/DummyMixin.html +23 -0
  14. data/doc/api/RDoc/DummyOptions.html +140 -0
  15. data/doc/api/RDoc/TopLevel.html +465 -0
  16. data/doc/api/String.html +372 -0
  17. data/doc/api/all-methods.html +253 -0
  18. data/doc/api/all-namespaces.html +42 -0
  19. data/doc/api/app.js +18 -0
  20. data/doc/api/index.html +16 -22
  21. data/doc/api/jquery.js +11 -0
  22. data/doc/api/readme.html +35 -0
  23. data/doc/api/style.css +68 -0
  24. data/doc/api/syntax_highlight.css +21 -0
  25. data/doc/erbook.png +0 -0
  26. data/doc/erbook.svg +150 -88
  27. data/doc/formats.erb +387 -0
  28. data/doc/history.erb +62 -0
  29. data/doc/index.erb +8 -0
  30. data/doc/index.xhtml +846 -654
  31. data/doc/intro.erb +97 -0
  32. data/doc/setup.erb +62 -0
  33. data/doc/theory.erb +187 -0
  34. data/doc/usage.erb +39 -0
  35. data/fmt/xhtml.yaml +497 -372
  36. data/lib/erbook.rb +18 -10
  37. data/lib/erbook/document.rb +233 -0
  38. data/lib/erbook/template.rb +210 -0
  39. data/lib/erbook/to_xhtml.rb +25 -17
  40. metadata +39 -45
  41. data/README +0 -14
  42. data/doc/api/classes/ERBook.html +0 -164
  43. data/doc/api/classes/RDoc.html +0 -112
  44. data/doc/api/classes/RDoc/AnyMethod.html +0 -195
  45. data/doc/api/classes/RDoc/AnyMethod.src/M000003.html +0 -18
  46. data/doc/api/classes/RDoc/AnyMethod.src/M000004.html +0 -23
  47. data/doc/api/classes/RDoc/AnyMethod.src/M000005.html +0 -18
  48. data/doc/api/classes/RDoc/AnyMethod.src/M000006.html +0 -22
  49. data/doc/api/classes/RDoc/TopLevel.html +0 -250
  50. data/doc/api/classes/RDoc/TopLevel.src/M000007.html +0 -18
  51. data/doc/api/classes/RDoc/TopLevel.src/M000008.html +0 -18
  52. data/doc/api/classes/RDoc/TopLevel.src/M000009.html +0 -18
  53. data/doc/api/classes/RDoc/TopLevel.src/M000010.html +0 -29
  54. data/doc/api/classes/RDoc/TopLevel.src/M000011.html +0 -25
  55. data/doc/api/classes/RDoc/TopLevel.src/M000012.html +0 -18
  56. data/doc/api/classes/String.html +0 -196
  57. data/doc/api/classes/String.src/M000001.html +0 -18
  58. data/doc/api/classes/String.src/M000002.html +0 -31
  59. data/doc/api/created.rid +0 -1
  60. data/doc/api/files/lib/erbook/rdoc_rb.html +0 -116
  61. data/doc/api/files/lib/erbook/to_xhtml_rb.html +0 -125
  62. data/doc/api/files/lib/erbook_rb.html +0 -107
  63. data/doc/api/fr_class_index.html +0 -31
  64. data/doc/api/fr_file_index.html +0 -29
  65. data/doc/api/fr_method_index.html +0 -38
  66. data/doc/api/rdoc-style.css +0 -208
  67. data/doc/feed-icon-28x28.png +0 -0
  68. data/doc/manual.erb +0 -812
Binary file
data/doc/manual.erb DELETED
@@ -1,812 +0,0 @@
1
- <%
2
- ##
3
- # Welcome to the source of the erbook user manual.
4
- #
5
- # The nodes in this file are hierarchically indented. As a result, you must
6
- # process this file using the "--unindent" option to obtain proper output:
7
- #
8
- # erbook --unindent xhtml manual.erb > manual.xhtml
9
- #
10
- # Notice the '.xhtml' file extension in the output file name. Without that,
11
- # most web browsers will not display the embedded graphics in the output file.
12
- #
13
- ##
14
-
15
- # local variables for this document
16
- pkg_url = File.join(ERBook::WEBSITE, 'pkg')
17
- src_url = File.join(ERBook::WEBSITE, 'src')
18
- ann_url = File.join(ERBook::WEBSITE, 'ann')
19
- dev_url = File.join(ERBook::WEBSITE, 'dev')
20
- log_url = File.join(ERBook::WEBSITE, 'log')
21
-
22
- # parameters for the XHTML format
23
- $title = "#{ERBook::DISPLAY} user manual"
24
- $authors = { 'Suraj N. Kurapati' => 'http://snk.tuxfamily.org' }
25
- $feeds = { ann_url => :rss }
26
- $logo = '![erbook logo](erbook.png)'.to_xhtml
27
-
28
- def introduction
29
- %{erbook is an extensible document processor that emits #{ xref 'xhtml', "XHTML (web page)" }, #{ xref 'latex', "LaTeX (PDF)" }, #{ xref "man", "man (UNIX manual page)" }, #{ xref 'text', 'plain text' }, and #{ xref "HelloWorld", "any document format you can imagine" } from [eRuby templates](http://en.wikipedia.org/wiki/ERuby) that allow scripting and dynamic content generation.}
30
- end
31
- %>
32
-
33
- <% abstract do %>
34
- <%= introduction %> <span style="float: right; font-size: larger"><%= xref 'Introduction', 'Read more...' %></span>
35
-
36
- <% paragraph "Resources" do %>
37
- * [Release notes](<%= log_url %>) --- news of project releases. [![RSS feed](feed-icon-28x28.png)](<%= ann_url %>)
38
- * [Downloads](<%= pkg_url %>) --- obtain the newest release package.
39
- * [Source code](<%= src_url %>) --- obtain via [Git](http://git.or.cz) or browse online. [![RSS feed](feed-icon-28x28.png)](<%= dev_url %>)
40
- * [API reference](api/index.html) --- documentation for source code.
41
-
42
- To get help or provide feedback, simply <%= xref "License", "contact the author" %>.
43
- <% end %>
44
- <% end %>
45
-
46
- <% chapter "Introduction" do %>
47
- <%= introduction %>
48
-
49
- <% note "See the source of this manual" do %>
50
- Did you know that this manual was generated by erbook? Here is [the source document](manual.erb) to prove it!
51
- <% end %>
52
-
53
- <% section "Relevance" do %>
54
- Unlike document processors such as [DocBook](http://www.docbook.org), [Deplate](http://deplate.sourceforge.net), and [SiSU](http://www.jus.uio.no/sisu/SiSU/), erbook is:
55
- * *tiny* because its core contains less than 210 source lines of code
56
- * *extensible* because it lets you define <%= xref "HelloWorld", "your own custom document format" %>
57
-
58
- Unlike the documents of raw text processors such as [AsciiDoc](http://www.methods.co.nz/asciidoc/), [txt2tags](http://txt2tags.sourceforge.net), and [Grutatxt](http://www.triptico.com/software/grutatxt.html), erbook documents are *scriptable* eRuby templates, which means that you can inject arbitrary Ruby code into your documents for **dynamic content generation**.
59
-
60
- <% section "Reviews" do %>
61
- Vitor Peres in [ruby-talk](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/283052):
62
-
63
- > I actually felt like printing \[this manual], because it's just so well-thought typographically... Even if \[erbook] weren't great by itself, I'd feel good just looking at the manual.
64
-
65
-
66
- Ara T. Howard in [ruby-talk](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/282949):
67
-
68
- > \[this manual is] a insanely complete and nice looking bit of documentation \[... erbook] looks like a great project
69
-
70
-
71
- Martin DeMello in [ruby-talk](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/283304):
72
-
73
- > Very nice work indeed!
74
- <% end %>
75
- <% end %>
76
-
77
- <% section "Logistics" do %>
78
- erbook is <%= xref "License", "open source software" %> so feel free to contribute your improvements and discuss your ideas <%= xref "License", "with the author" %>. You can obtain the source code from [this source repository](<%= src_url %>) and monitor for changes by subscribing to [this news feed](<%= dev_url %>).
79
-
80
- <% section "Credits" do %>
81
- <%= File.read 'doc/README' %>
82
- <% end %>
83
-
84
- <% section "License" do %>
85
- <%= File.read 'LICENSE' %>
86
- <% end %>
87
-
88
- <% section 'Version numbers' do %>
89
- erbook releases are numbered in *major.minor.patch* form, according to the [RubyGems rational versioning policy](http://www.rubygems.org/read/chapter/7) which can be [summarized](http://ablog.apress.com/?p=738) thus:
90
-
91
- <table markdown="1">
92
- <thead>
93
- <tr>
94
- <td rowspan="2">What increased in the version number? </td>
95
- <td colspan="3">What does the increase signify about the release? </td>
96
- </tr>
97
- <tr>
98
- <th>Backwards compatible? </th>
99
- <th>New features? </th>
100
- <th>Bug fixes? </th>
101
- </tr>
102
- </thead>
103
- <tbody>
104
- <tr>
105
- <th>major </th>
106
- <td style="background-color: #FFE4E1;">No </td>
107
- <td>Yes </td>
108
- <td>Yes </td>
109
- </tr>
110
- <tr>
111
- <th>minor </th>
112
- <td>Yes </td>
113
- <td>Yes </td>
114
- <td>Yes </td>
115
- </tr>
116
- <tr>
117
- <th>patch </th>
118
- <td>Yes </td>
119
- <td style="background-color: #FFE4E1;">No </td>
120
- <td>Yes </td>
121
- </tr>
122
- </tbody>
123
- </table>
124
- <% end %>
125
- <% end %>
126
- <% end %>
127
-
128
- <% chapter "Setup" do %>
129
- <% section "Requirements" do %>
130
- Your system needs the following software to run erbook.
131
-
132
- | Software | Description | Notes |
133
- | -------- | ----------- | ----- |
134
- | [Ruby](http://ruby-lang.org) | Ruby language interpreter | Version 1.8.x is required. |
135
- | [Maruku](http://maruku.rubyforge.org) | Markdown processor | Required by the <%= xref 'xhtml', "default XHTML format" %>. |
136
- | [CodeRay](http://coderay.rubychan.de) | Syntax highlighter | Required by the <%= xref 'xhtml', "default XHTML format" %>. |
137
- | [Trollop](http://trollop.rubyforge.org) | Command-line option parser | Required by the *erbook* executable. |
138
-
139
- If your system has [RubyGems](http://rubygems.org), then you can install Maruku and CodeRay by running the following command:
140
-
141
- gem install trollop maruku coderay
142
-
143
- <% end %>
144
-
145
- <% section "Installation" do %>
146
- If your system has [RubyGems](http://rubygems.org), then you can install erbook by running the following commands:
147
-
148
- gem install erbook
149
- erbook -v
150
-
151
- Otherwise, follow these instructions:
152
-
153
- 1. Download the newest release package from [the download area](<%= pkg_url %>).
154
- 2. Extract the release package somewhere on your system.
155
- 3. Go inside the extracted directory and run the following command:
156
-
157
- ruby bin/erbook -v
158
-
159
- If the installation was successful, then you will see output like this:
160
- <pre><%= verbatim `ruby bin/erbook -v` %></pre>
161
-
162
- Otherwise, you can <%= xref "License", "contact the author" %> for help.
163
- <% end %>
164
-
165
- <% section "Manifest" do %>
166
- You will see the following items inside erbook's installation directory, whose path you can determine by running this command:
167
-
168
- erbook -v
169
-
170
- * <tt>bin/</tt> --- contains executable programs.
171
-
172
- * <tt>erbook</tt> --- core logic of erbook.
173
-
174
- * <tt>fmt/</tt> --- contains the predefined set of <%= xref 'SpecFile', "format specification files" %>. If you ever need to install your custom format specification file globally, then put it inside this directory.
175
-
176
- <% ERBook::FORMAT_FILES.each do |file| %>
177
- * <tt><%= File.basename(file) %></tt> --- <%= YAML.load_file(file)['desc'] %>
178
- <% end %>
179
-
180
- * <tt>lib/</tt> --- erbook automatically adds this directory to Ruby's load path.
181
-
182
- * <tt>erbook.rb</tt> --- project version information.
183
-
184
- * <tt>erbook/</tt>
185
-
186
- * <tt>to_xhtml.rb</tt> --- provides methods (see <%= xref "Text to XHTML conversion" %>) for the <%= xref 'xhtml' %> format.
187
-
188
- * <tt>rdoc.rb</tt> --- provides RDoc parse trees to Ruby code.
189
-
190
- * <tt>doc/</tt> --- contains this manual and other documentation.
191
-
192
- * <tt>erbook.svg</tt> --- source file of the erbook logo.
193
-
194
- * <tt>manual.erb</tt> --- source file of this manual.
195
-
196
- * <tt>api/</tt> --- contains API reference documentation for the provided Ruby code.
197
-
198
- * <tt>LICENSE</tt> --- project license and copyright notice.
199
- <% end %>
200
- <% end %>
201
-
202
- <% chapter "Theory of operation" do %>
203
- When you run erbook, it does the following:
204
-
205
- 1. Loads the <%= xref "SpecFile", "format specification file" %>.
206
-
207
- 2. Creates an **input document** by:
208
-
209
- * Reading the input (the content of either the input file or the standard input stream) into memory.
210
-
211
- * Evaluating <%= xref "include", "include directives" %> in the input.
212
-
213
- 3. Transforms the input document into a **processed document** by:
214
-
215
- * Building a **document tree** data structure from <%= xref "Nodes", "nodes" %> present in the input document.
216
-
217
- * Replacing every node in the input document with the result of its <%= xref "SpecFile.nodes.output", "node output template" %>.
218
-
219
- 4. Transforms the processed document into an **output document** according to the <%= xref "SpecFile.output", "document output template" %>.
220
-
221
- 5. Prints the output document to the standard output stream.
222
-
223
- Although there is only one document being processed here, we refer to it using three distinct terms: **input**, **processed**, and **output**; because the content of the document changes radically with every transformation.
224
-
225
- <% section "Nodes" do %>
226
- A node is a block of text that appears like this:
227
-
228
- <%% node_type node_argument1, node_argument2, ... do |node_object| %>
229
- node_content
230
- <%% end %>
231
-
232
- Or like this:
233
-
234
- <%% node_type node_argument1, node_argument2, ... do %>
235
- node_content
236
- <%% end %>
237
-
238
- Or like this:
239
-
240
- <%%= node_type node_argument1, node_argument2, ... %>
241
-
242
- Alternatively, you may omit the leading "<" and trailing "%>" characters from an eRuby directive if the directive spans an _entire_ line. So, the above examples become:
243
-
244
- %% node_type node_argument1, node_argument2, ... do |node_object|
245
- node_content
246
- %% end
247
-
248
- And:
249
-
250
- %% node_type node_argument1, node_argument2, ... do
251
- node_content
252
- %% end
253
-
254
- And:
255
-
256
- %%= node_type node_argument1, node_argument2, ...
257
-
258
- Technically, nodes are Ruby method invocations composed of the following:
259
-
260
- | Component | Description |
261
- | --------- | ----------- |
262
- | `node_type` | name of the method being invoked |
263
- | `node_argument1, node_argument2, ...` | arguments for the method invocation |
264
- | `node_content` | a block argument being passed to the method invocation |
265
- | `node_object` | a `ERBook::Node` object (see <%= xref "Node.class" %>) representing this method invocation |
266
-
267
- A <%= xref 'SpecFile', 'format specification file' %> defines what types of nodes an input document may use.
268
-
269
- <% section "The `ERBook::Node` class", "Node.class" do %>
270
- When erbook builds a document tree from the nodes in an input document, it stores information about these nodes into `ERBook::Node` objects. A `ERBook::Node` object has the following properties (methods):
271
-
272
- | Property | Type | Description |
273
- | -------- | ---- | ----------- |
274
- | type | `String` | Name of the type of this node. |
275
- | args | `Array` | Arguments passed to this node. |
276
- | content | `String` | The block of text passed to this node. |
277
- | output | `String` | Result of the node output template for the content of this node. |
278
- | digest | `String` | A unique identifier for the content of this node. |
279
- | trace | `Array` | A stack trace describing the location of this node in the input document. |
280
- | index | `String` | A LaTeX-style section number for this node. This property is only present if the **index** parameter is enabled in the definition of this type of node. |
281
- | number | `Integer` | An order-of-occurrence number for this node. This property is only present if the **number** parameter is enabled in the definition of this type of node. |
282
- | depth | `Integer` | Distance from the root of the document tree to this node. |
283
- | parent | `ERBook::Node` | The `ERBook::Node` object which contains this node. The value of this property will be `nil` if this node is a root of the document tree. |
284
- | children | `Array` of `ERBook::Node` | List of child nodes from the document tree. |
285
-
286
- Furthermore, the `ERBook::Node` class is derived from [Ruby's `OpenStruct` class](http://www.ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html), so you can define new properties for `ERBook::Node` objects dynamically.
287
- <% end %>
288
- <% end %>
289
-
290
- <% section "Format specification file", 'SpecFile' do %>
291
- A format specification file is a plain-text file marked up in [YAML syntax](http://yaml4r.sourceforge.net/cookbook/). Through the following parameters, it defines (1) what types of nodes an input document may contain, (2) how the content of those nodes is transformed into output, and (3) how the processed document is transformed into the output document.
292
-
293
- | Parameter | Type | Description |
294
- | --------- | ---- | ----------- |
295
- | desc | `String` | A short description of the output format. |
296
- | code | `String` | Ruby code that will be loaded before the input document is processed. This source code will be evaluated inside the main erbook executable, so any file-system or path-dependent portions of this source code should take appropriate precautions. |
297
- | nodes | Hash | A listing of <%= xref "SpecFile.nodes", "node definitions" %>. |
298
- | output | `String` | An eRuby template for the final output document. See <%= xref "SpecFile.output" %>. |
299
-
300
- <%
301
- # XXX: "declare" this local variable here (in the parent
302
- # scope) because it is initialized and used in two
303
- # different child scopes that exist at different depths
304
- common_template_vars = nil
305
- %>
306
-
307
- <% section "Node definition", "SpecFile.nodes" do %>
308
- A node definition is a mapping from a name (the "node type") to the following set of parameters:
309
-
310
- | Parameter | Type | Description |
311
- | --------- | ---- | ----------- |
312
- | index | Boolean | Assign a LaTeX-style section number to this node? |
313
- | number | Boolean | Assign an order-of-occurrence number to this node? |
314
- | silent | Boolean | Suppress the output of this node? |
315
- | output | `String` | An eRuby template for the content of this node. See <%= xref "SpecFile.nodes.output" %>. |
316
-
317
- You may define additional parameters in a node definition if you want.
318
-
319
- <% section "Node output template", "SpecFile.nodes.output" do %>
320
- A node output template (the **output** parameter in a node definition) is an eRuby template that transforms a node's content into output. During the processing stage, erbook replaces all nodes in the input document with the result of this template _unless_ the **silent** parameter is enabled in this node's definition.
321
-
322
- The following variables are available for use in this template:
323
-
324
- | Variable | Type | Description |
325
- | -------- | ---- | ----------- |
326
- | `@node` | `ERBook::Node` | The node for which this template is being evaluated. |
327
- <%= common_template_vars = %{
328
- | `@roots` | `Array` of `ERBook::Node` | All root nodes in the document tree. |
329
- | `@nodes` | `Array` of `ERBook::Node` | All nodes in the document tree. |
330
- | `@types` | `Hash` | Mapping from node type (`String`) to array of `ERBook::Node` objects having that type. |
331
- | `@spec` | `Hash` | Data from the format specification file. |
332
-
333
- erbook also provides the following mappings inside the `@spec` variable:
334
-
335
- | Expression | Type | Description |
336
- | ---------- | ---- | ----------- |
337
- | `@spec[:name]` | `String` | Short-hand name of the current format. |
338
- | `@spec[:file]` | `String` | Path of the current format specification file. |
339
- }.lstrip.gsub(/^ +/, '')
340
- %>
341
- <% end %>
342
- <% end %>
343
-
344
- <% section "Document output template", "SpecFile.output" do %>
345
- A document output template (the **output** parameter in a format specification file) is an eRuby template that transforms a processed document into the final output document.
346
-
347
- The following variables are available for use in this template:
348
-
349
- | Variable | Type | Description |
350
- | -------- | ---- | ----------- |
351
- | `@content` | `String` | Content of the processed document. |
352
- <%= common_template_vars %>
353
- <% end %>
354
-
355
- <% section "Creating your own document format", "HelloWorld" do %>
356
- Here is a working example to help you digest all that you've learned so far about format specification files. A few things to notice in this example are:
357
-
358
- * We define a `generate_name()` method in <%= xref "HelloWorld.spec" %> and make use of it in the <%= xref "HelloWorld.input" %>. This shows how to provide format-specific functionality to an input document.
359
-
360
- * We define a `$style` variable in <%= xref "HelloWorld.input" %> and make use of it in <%= xref "HelloWorld.spec" %>. This shows how to pass parameters from an input document to your format specification file.
361
-
362
- To run this example:
363
-
364
- 1. Save the code shown in <%= xref "HelloWorld.spec" %> to a file named <tt>HelloWorld.spec</tt>
365
-
366
- 2. Save the text shown in <%= xref "HelloWorld.input" %> to a file named <tt>HelloWorld.input</tt>
367
-
368
- 3. Run this command:
369
-
370
- erbook HelloWorld.spec HelloWorld.input > HelloWorld.output
371
-
372
- 4. Examine the <tt>HelloWorld.output</tt> file to your satisfaction!
373
-
374
- <% example "HelloWorld format specification file", "HelloWorld.spec" do %>
375
- <code lang="rhtml"><%= verbatim File.read('doc/HelloWorld.spec') %></code>
376
- <% end %>
377
-
378
- <% example "Input document for HelloWorld format", "HelloWorld.input" do %>
379
- <code lang="rhtml"><%= verbatim File.read('doc/HelloWorld.input') %></code>
380
- <% end %>
381
-
382
- <% example "Output of HelloWorld format", "HelloWorld.output" do %>
383
- <%= `ruby bin/erbook -u doc/HelloWorld.spec doc/HelloWorld.input` %>
384
- <% end %>
385
- <% end %>
386
- <% end %>
387
- <% end %>
388
-
389
- <% chapter "Usage" do %>
390
- <% section "Command-line invocation" do %>
391
- <%=
392
- `ruby bin/erbook -h`.
393
- gsub(/^ +(.*?):(.*)$/, "\\1\n: \\2\n"). # option listing
394
- gsub(/-\w\b|--\w{2,}/, '<tt>\&</tt>'). # option names
395
- gsub(/^\S+?: */, "<b>\\&</b>\n"). # section headings
396
- gsub(/^ *(erbook \[.*)/, '<pre>\1</pre>') # usage syntax
397
- %>
398
-
399
- <% paragraph "Command-line arguments" do %>
400
- The first command-line argument to erbook is either the name of a predefined format (FormatName) or the path to a <%= xref 'SpecFile', 'format specification file' %> (FormatFile).
401
-
402
- Predefined formats are simply short-hand names of format specification files located in the <tt>fmt/</tt> subdirectory of the erbook installation directory (see <%= xref "Manifest" %>).
403
- <% end %>
404
-
405
- <% paragraph "Saving the output to a file" do %>
406
- Simply redirect the standard ouput stream (STDOUT) to a file like this:
407
-
408
- erbook > YOUR_PATH_HERE
409
-
410
- In the above example, **YOUR\_PATH\_HERE** is the path of the file in which the output should be saved.
411
-
412
- <% important "Save XHTML output as <tt>.xhtml</tt>" do %>
413
- When you use the XHTML format, ensure that the file extension of your saved output document is either <tt>.xhtml</tt> or <tt>.xml</tt>. Alternatively, ensure that your saved output document is served to web browsers under the <tt>application/xhtml+xml</tt> mime type.
414
-
415
- Otherwise, most web browsers _will not display_ the icons and graphics embedded in the saved XHTML output document because they will treat it as HTML instead of as XML. See this [QuirksMode.org bug report](http://www.quirksmode.org/bugreports/archives/2005/02/custom_dtds_int_1.html) for details.
416
- <% end %>
417
- <% end %>
418
- <% end %>
419
-
420
- <% section "Including external documents", "include" do %>
421
- The **include** directive allows you to insert the content of an arbitrary file at a certain place in the input document. It is written like this:
422
-
423
- <%%# include YOUR_PATH_HERE #%>
424
-
425
- In the above example, **YOUR\_PATH\_HERE** is the path of the file whose content you wish to insert into the input document.
426
-
427
- You can divide a large document into separate files for easier editing and stitch them together, dynamically, into a single document using the **include** directive.
428
- <% end %>
429
-
430
- <% section "Unindenting nodes hierarchically" do %>
431
- When writing erbook documents, I prefer to indent the content of nodes according to their depth (as can be seen in <%= xref "See the source of this manual", "the source of this manual" %>) because my [text editor of choice](http://jedit.org) automatically folds blocks of text based on indentation.
432
-
433
- If you also prefer to write documents in this way, be sure to pass the <tt>--unindent</tt> option to **erbook** so that the indentation will not affect the resulting output.
434
- <% end %>
435
- <% end %>
436
-
437
- <% part "Formats" do %>
438
- This part describes the default formats provided along with erbook. The <%= xref "SpecFile", "format specification files" %> for these formats can be found in the <tt>fmt/</tt> directory of the erbook installation directory (see <%= xref "Manifest" %>).
439
-
440
- These formats are meant to serve as working examples. If you require more functionality from one of these formats, simply make a copy of the corresponding format specification file and edit the copy to suit your needs. If you would like to contribute or discuss your enhancements to these default formats, you can <%= xref "License", "contact the author" %>.
441
-
442
- <% chapter "XHTML (web page)", 'xhtml' do %>
443
- This format generates a _monolithic_ XHTML document that allows users to easily search for a particular topic using nothing more than their web browser's built-in text search mechanism. This facilitates offline reading, where an Internet search engine is not available.
444
-
445
- In the XHTML document, you will notice that the numbers of chapters, sections, figures, admonitions, etc. are hyperlinks that take you back to the corresponding place in the table of contents. These links make it easy to navigate the XHTML document, especially for users of text-only web browsers.
446
-
447
- Furthermore, the XHTML document comes equipped with a stylesheet that makes it suitable for printing. In particular, users of the [Mozilla](http://mozilla.org) and [Opera](http://www.opera.com/) family of web browsers will be pleasantly surprised to notice that all hyperlinks have been expanded to include their target URL next to the link text. So try using the "print preview" function of a graphical web browser to see how the XHTML document will appear when printed.
448
-
449
- <% section "Text to XHTML conversion" do %>
450
- The <tt>lib/erbook/to_xhtml.rb</tt> file inside erbook's installation directory (see <%= xref "Manifest" %>) defines the following methods:
451
-
452
- * `String#to_xhtml` - Transforms this string into XHTML while ensuring that the result contains one or more block-level elements at the root.
453
-
454
- * `String.to_inline_xhtml` - Transforms this string into an *inline* XHTML string (one that does not contain any block-level XHTML elements at the root).
455
-
456
- The default implementation of the `String#to_xhtml` method employs the [Markdown](http://daringfireball.net/projects/markdown/) markup system. If you do not like Markdown or wish to use a different markup system for text in your documents, then simply edit the <tt>to_xhtml.rb</tt> file and adjust the source code of the default `String#to_xhtml` and `String.to_inline_xhtml` methods accordingly.
457
-
458
- For example, if you replace the entire <tt>to_xhtml.rb</tt> file with the following code, then the output of all nodes will appear within red boxes in the final output document.
459
-
460
- <code>
461
- class String
462
- # Transforms this string into XHTML while ensuring that the
463
- # result contains one or more block-level elements at the root.
464
- def to_xhtml
465
- '<p style="border: thin solid red">' + self + '</p>'
466
- end
467
-
468
- # Transforms this string into an *inline* XHTML string (one that
469
- # does not contain any block-level XHTML elements at the root).
470
- def to_inline_xhtml
471
- self
472
- end
473
- end
474
- </code>
475
-
476
- In addition to supporting Markdown syntax, the default implementation has some additional features which are described in the following subsections.
477
-
478
- <% section "Syntax coloring for source code" do %>
479
- Syntax coloring is _automatically added_ to source code found inside the **&lt;code&gt;** and **&lt;/code&gt;** HTML tags. The syntax coloring library, [CodeRay](http://coderay.rubychan.de), currently supports the following programming languages:
480
- * Ruby
481
- * C
482
- * Delphi
483
- * HTML
484
- * RHTML (Rails)
485
- * Nitro-XHTML
486
-
487
- <% section "Specifying the programming language" do %>
488
- Because different programming languages have different syntax coloring schemes, you can specify the language of your source code using the `lang` attribute to ensure that only the appropriate coloring scheme is used. Note that unless the `lang` attribute is specified, _Ruby_ is assumed to be the programming language of all source code by default.
489
-
490
- <% sampleCode = %q{
491
- # Ruby ###########################
492
- def hello
493
- puts "Hello world!"
494
- end
495
-
496
-
497
- /* C ****************************/
498
- #include <stdio.h>
499
- int main(int argc, char **argv) {
500
- printf("Hello world!\n");
501
- return 0;
502
- }
503
-
504
-
505
- <!-- HTML ----------------------->
506
- <html>
507
- <body>
508
- Hello world!
509
- <body>
510
- </html>
511
- } %>
512
-
513
- For example, here is some source code _without_ the `lang` attribute:
514
-
515
- <code><%= verbatim sampleCode %></code>
516
-
517
- And here is the same source code with a `lang="c"` attribute:
518
-
519
- <code lang="c"><%= verbatim sampleCode %></code>
520
-
521
- And here is the same source code with a `lang="html"` attribute:
522
-
523
- <code lang="html"><%= verbatim sampleCode %></code>
524
- <% end %>
525
- <% end %>
526
-
527
- <% section "Smart sizing of source code" do %>
528
- Source code is _automatically sized_ to be displayed as either a line or paragraph of text, depending on whether it contains line breaks.
529
-
530
- For example, here is a single line <code>life = true or false</code> of code. And here is a paragraph <code>life =
531
- true or
532
- false</code> of code.
533
- <% end %>
534
-
535
- <% section "Protecting verbatim text" do %>
536
- Sometimes you just need to protect some text from being mangled by the text-to-XHTML conversion process . In such cases, you can wrap the text you want to proctect within **&lt;noformat&gt;** and **&lt;/noformat&gt;** tags.
537
- <% end %>
538
- <% end %>
539
-
540
- <% section "Parameters" do %>
541
- The XHTML format accepts the following document parameters.
542
-
543
- | Parameter | Type | Default value | Description |
544
- | --------- | ---- | ------------- | ----------- |
545
- | `$title` | `String` | `"$title"` | Title of the document. |
546
- | `$authors` | `Hash` | `{"$authors" => nil}` | A mapping of author name to author URL. You can obfuscate e-mail addresses using the provided `String#to_xml_entities` method like this: `{ "Y. Matsumoto" => "mailto:matz@ruby.invalid".to_xml_entities }` |
547
- | `$date` | `String` | `Time.now.strftime("%d %B %Y")` | Date when the document was written. |
548
- | `$logo` | `String` | `nil` | Arbitrary content that goes above the document title in the default header. |
549
- | `$feeds` | `Hash` | `nil` | A mapping of feed URL to feed format. Here is an example: <code>$feeds = { "my_rss_feed.xml" => "rss", "my_atom_feed.xml" => "atom" }</code> |
550
- <% end %>
551
-
552
- <% section "Methods" do %>
553
- The XHTML format provides the following methods. In the method declarations shown below,
554
- * a pound sign (#) indicates that the method is an *instance method*, meaning that it can only be invoked on instances of a class, not on the classes themselves.
555
- * a double colon sign (::) indicates that the method is a *class method*, meaning that it can only be invoked on a class.
556
-
557
- <%
558
- # load library for parsing method documentation
559
- require 'erbook/rdoc'
560
-
561
- RDoc::TopLevel.parse @spec['code']
562
- RDoc::TopLevel.parse_file 'lib/erbook/to_xhtml.rb'
563
- RDoc::TopLevel.all_methods.each do |m|
564
- section "`#{m.decl}`" do
565
- m.comment_html
566
- end
567
- end
568
- %>
569
- <% end %>
570
-
571
- <% chapter "Nodes", "xhtml.nodes" do %>
572
- Unless otherwise noted, all nodes defined by the XHTML format accept two arguments, in this order:
573
- 1. a required *title* for the node
574
- 2. an optional *unique identifier* for the node
575
-
576
- The second argument is used by the cross-referencing nodes (see <%= xref "xhtml.nodes.xref" %> and <%= xref "xhtml.nodes.cite" %>), which allow you to refer to another node in the document by its unique identifier.
577
-
578
- Furthermore, <%= xref "SpecFile.nodes", "node definitions" %> in the XHTML format have two additional parameters:
579
-
580
- | Parameter | Type | Description |
581
- | --------- | ---- | ----------- |
582
- | toc | Boolean | Include this node in the **Table of Contents** (TOC)? |
583
- | lof | Boolean | Include this node in the **List of Figures** (LOF)? |
584
-
585
- <% section "Structural nodes" do %>
586
- The nodes described in this section form the overall structure of the output document.
587
-
588
- <% section "header", "xhtml.nodes.header" do %>
589
- This node overrides the logo, title, list of authors, and date when the document was written, all of which are shown at the top of the document.
590
- <% end %>
591
-
592
- <% section "footer", "xhtml.nodes.footer" do %>
593
- This node overrides (1) the date when this document was generated and (2) the hyperlink to the erbook website, shown at the bottom of the document. The hyperlink is there as a way of saying thanks for erbook, the _wonderful_ little utility you have grown so fond of! ;-)
594
- <% end %>
595
-
596
- <% section "abstract", "xhtml.nodes.abstract" do %>
597
- A summary of the entire document. This is what most readers will _skim_ through, if you are lucky. Alas, nobody reads entire documents these days! :-(
598
- <% end %>
599
-
600
- <% section "xref", "xhtml.nodes.xref" do %>
601
- A cross-reference; a hyperlink that takes you to any node in the document.
602
-
603
- The first argument of this node is either the unique identifier or the user-defined title of the node you wish to cross-reference. If no nodes in the document have the given identifier or user-defined title, then an error will be raised.
604
-
605
- The second argument of this node overrides the default link text of the cross-reference.
606
-
607
- For example, this node in the input document:
608
-
609
- <%%= xref "SpecFile" %>
610
-
611
- appears in the output document like this: <%= xref "SpecFile" %>.
612
-
613
- As another example, this node in the input document:
614
-
615
- <%%= xref "SpecFile", "custom link text" %>
616
-
617
- appears in the output document like this: <%= xref "SpecFile", "custom link text" %>.
618
- <% end %>
619
- <% end %>
620
-
621
- <% section "Organizational nodes" do %>
622
- The nodes described in this section are meant to help organize the document's content logically. Based on how deeply these nodes are nested in the document, their heading will be larger (shallow depth) or smaller (deep depth).
623
-
624
- <% section "part", "xhtml.nodes.part" do %>
625
- A collection of chapters.
626
-
627
- <% part "An example" do %>
628
- This is how a **part** node appears.
629
- <% end %>
630
- <% end %>
631
-
632
- <% section "chapter", "xhtml.nodes.chapter" do %>
633
- A collection of sections.
634
-
635
- <% chapter "An example" do %>
636
- This is how a **chapter** node appears.
637
- <% end %>
638
- <% end %>
639
-
640
- <% section "section", "xhtml.nodes.section" do %>
641
- A collection of paragraphs about a particular topic.
642
-
643
- <% section "An example" do %>
644
- This is how a **section** node appears.
645
- <% end %>
646
- <% end %>
647
-
648
- <% section "paragraph", "xhtml.nodes.paragraph" do %>
649
- A collection of sentences about a particular idea.
650
-
651
- <% paragraph "An example" do %>
652
- This is how a **paragraph** node appears. Notice that there is no LaTeX-style index number in the heading of this **paragraph** node.
653
- <% end %>
654
- <% end %>
655
- <% end %>
656
-
657
- <% section "Admonition nodes" do %>
658
- An admonition is basically a box that is indented more deeply than the text surrounding it. It is typically used to convey extraneous or pertinent information about the application of ideas discussed in the surrounding text.
659
-
660
- I like to follow the KDE guidelines<%= cite "KDE.admonitions" %> when determining which admonition to use in my documents.
661
-
662
- <% reference "KDE.admonitions" do %>
663
- L. Watts, "Admonitions: Tips, hints, and Warnings", in _The KDE DocBook Authors guide_, Chapter 13, \[Online document], 22 September 2004 (Revision 1.00.00), \[cited 8 December 2007], Available at <%= hyperlink 'http://l10n.kde.org/docs/markup/tips-hints-etc.html' %>
664
- <% end %>
665
-
666
- <% section "warning", "xhtml.nodes.warning" do %>
667
- Use a **warning** node when "data loss could occur if you follow the procedure being described." <%= cite "KDE.admonitions" %>
668
-
669
- <% warning "An example" do %>
670
- This is how a **warning** node appears.
671
- <% end %>
672
- <% end %>
673
-
674
- <% section "caution", "xhtml.nodes.caution" do %>
675
- bq. A note of caution. Use this for example when the reader may lose easily recovered or replaceable information (e.g. user settings), or when they could cause data loss if they don't correctly follow the procedure being outlined. <%= cite "KDE.admonitions" %>
676
-
677
- <% caution "An example" do %>
678
- This is how a **caution** node appears.
679
- <% end %>
680
- <% end %>
681
-
682
- <% section "important", "xhtml.nodes.important" do %>
683
- Use an **important** node when:
684
-
685
- bq. When there is no danger of data loss, but you wish to make clear to the reader a consequence that isn't immediately obvious (e.g. when changing the font for one instance of a program also changes the default setting, and this isn't clear from the GUI.) <%= cite "KDE.admonitions" %>
686
-
687
- <% important "An example" do %>
688
- This is how a **important** node appears.
689
- <% end %>
690
- <% end %>
691
-
692
- <% section "note", "xhtml.nodes.note" do %>
693
- Use a **note** node to convey:
694
-
695
- bq. Information the user should be aware of, but is peripheral to the actual task being described. <%= cite "KDE.admonitions" %>
696
-
697
- <% note "An example" do %>
698
- This is how a **note** node appears.
699
- <% end %>
700
- <% end %>
701
-
702
- <% section "tip", "xhtml.nodes.tip" do %>
703
- Use a **tip** node when:
704
-
705
- bq. When you're giving a hint to make things easier or more productive for the reader. <%= cite "KDE.admonitions" %>
706
-
707
- <% tip "An example" do %>
708
- This is how a **tip** node appears.
709
- <% end %>
710
- <% end %>
711
- <% end %>
712
-
713
- <% section "Auxilary materials" do %>
714
- <% section "figure", "xhtml.nodes.figure" do %>
715
- A diagram, sketch, image, or illustration; something that visually depicts an idea or thought.
716
-
717
- <% figure "An example" do %>
718
- This is how a **figure** node appears.
719
- <% end %>
720
- <% end %>
721
-
722
- <% section "table", "xhtml.nodes.table" do %>
723
- Information (typically measurement data) represented in tabular form for easy reading, comparison, and analysis.
724
-
725
- <% table "An example" do %>
726
- This is how a **table** node appears.
727
- <% end %>
728
- <% end %>
729
-
730
- <% section "example", "xhtml.nodes.example" do %>
731
- A sample application of an idea or thought.
732
-
733
- <% example "An example" do %>
734
- This is how a **example** node appears.
735
- <% end %>
736
- <% end %>
737
-
738
- <% section "equation", "xhtml.nodes.equation" do %>
739
- A mathematical equation or formula.
740
-
741
- <% equation "An example" do %>
742
- This is how a **equation** node appears.
743
- <% end %>
744
- <% end %>
745
-
746
- <% section "procedure", "xhtml.nodes.procedure" do %>
747
- An outline; a series of steps outlining some kind of process.
748
-
749
- <% procedure "An example" do %>
750
- This is how a **procedure** node appears.
751
- <% end %>
752
- <% end %>
753
- <% end %>
754
-
755
- <% section "Bibliographical nodes" do %>
756
- The nodes in this section deal with attribution of ideas---an important weapon against plagiarism.
757
-
758
- <% section "reference", "xhtml.nodes.reference" do %>
759
- This node stores bibliography information about an information source that is relevant to your document.
760
-
761
- If you wish to cite a certain source in several places in your document, start by creating a **reference** node first and then use a **cite** node (see <%= xref "xhtml.nodes.cite" %>) to perform the citation.
762
-
763
- <% paragraph "An example" do %>
764
- See <%= xref 'xhtml.nodes.reference.example' %> for an example of how a **reference** node appears.
765
- <% end %>
766
-
767
- <% reference 'xhtml.nodes.reference.example' do %>
768
- This is how a **reference** node appears.
769
- <% end %>
770
- <% end %>
771
-
772
- <% section "cite", "xhtml.nodes.cite" do %>
773
- A citation to a **reference** node (see <%= xref 'xhtml.nodes.reference' %>) in the document's bibliography.
774
-
775
- The first argument of this node is the unique identifier of the reference node you wish to cite. You can specify additional arguments to give more detail about the citation.
776
-
777
- For example, this node in the input document:
778
-
779
- <%%= cite "xhtml.nodes.reference.example" %>
780
-
781
- appears in the output document like this: <%= cite "xhtml.nodes.reference.example" %>
782
-
783
- As another example, this node in the input document:
784
-
785
- <%%= cite "xhtml.nodes.reference.example", "chapter 10", "page 53", "..." %>
786
-
787
- appears in the output document like this: <%= cite "xhtml.nodes.reference.example", "chapter 10", "page 53", "..." %>
788
- <% end %>
789
- <% end %>
790
- <% end %>
791
- <% end %>
792
-
793
- <% patches_are_welcome = "This format is not yet implemented. I will do this evenually, but until then, **patches are welcome!** :-)" %>
794
-
795
- <% chapter "Plain text", 'text' do %>
796
- <%= patches_are_welcome %>
797
-
798
- <%= hyperlink 'http://en.wikipedia.org/wiki/Plain_text' %>
799
- <% end %>
800
-
801
- <% chapter "LaTeX (PDF)", 'latex' do %>
802
- <%= patches_are_welcome %>
803
-
804
- <%= hyperlink 'http://www.latex-project.org' %>
805
- <% end %>
806
-
807
- <% chapter "man (UNIX manual page)", 'man' do %>
808
- <%= patches_are_welcome %>
809
-
810
- <%= hyperlink 'http://en.wikipedia.org/wiki/Man_page' %>
811
- <% end %>
812
- <% end %>