glyph 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/AUTHORS.textile +8 -0
  2. data/CHANGELOG.textile +260 -0
  3. data/LICENSE.textile +26 -0
  4. data/README.textile +49 -21
  5. data/Rakefile +17 -7
  6. data/VERSION +1 -1
  7. data/book/config.yml +11 -5
  8. data/book/document.glyph +24 -13
  9. data/book/lib/macros/reference.rb +41 -14
  10. data/book/output/html/glyph.html +2298 -687
  11. data/book/output/pdf/glyph.pdf +6218 -2698
  12. data/book/script/authors +1 -0
  13. data/book/script/changelog +1 -0
  14. data/book/script/compile.rb +8 -0
  15. data/book/script/license +1 -0
  16. data/book/script/prof +1 -0
  17. data/book/script/prof_results.htm +21079 -0
  18. data/book/script/readme +1 -0
  19. data/book/snippets.yml +3 -4
  20. data/book/text/acknowledgement.glyph +8 -0
  21. data/book/text/authoring.glyph +548 -0
  22. data/book/text/changelog.glyph +76 -0
  23. data/book/text/extending.glyph +224 -0
  24. data/book/text/{getting_started.textile → getting_started.glyph} +30 -24
  25. data/book/text/{introduction.textile → introduction.glyph} +22 -12
  26. data/book/text/license.glyph +21 -0
  27. data/book/text/{ref_commands.textile → ref_commands.glyph} +30 -8
  28. data/book/text/ref_config.glyph +108 -0
  29. data/book/text/ref_macros.glyph +378 -0
  30. data/book/text/troubleshooting.glyph +179 -0
  31. data/config.yml +16 -4
  32. data/glyph.gemspec +83 -22
  33. data/lib/glyph.rb +164 -31
  34. data/lib/glyph/commands.rb +98 -23
  35. data/lib/glyph/document.rb +13 -7
  36. data/lib/glyph/glyph_language.rb +9 -1
  37. data/lib/glyph/glyph_language.treetop +1 -1
  38. data/lib/glyph/interpreter.rb +19 -9
  39. data/lib/glyph/macro.rb +88 -11
  40. data/lib/glyph/macro_validators.rb +48 -0
  41. data/lib/glyph/node.rb +13 -1
  42. data/lib/glyph/system_extensions.rb +0 -28
  43. data/macros/common.rb +125 -31
  44. data/macros/filters.rb +19 -13
  45. data/macros/html/block.rb +119 -68
  46. data/macros/html/inline.rb +29 -3
  47. data/macros/html/structure.rb +40 -40
  48. data/spec/files/article.glyph +5 -0
  49. data/spec/lib/commands_spec.rb +98 -3
  50. data/spec/lib/document_spec.rb +15 -2
  51. data/spec/lib/glyph_spec.rb +39 -10
  52. data/spec/lib/interpreter_spec.rb +8 -2
  53. data/spec/lib/macro_spec.rb +54 -6
  54. data/spec/lib/macro_validators_spec.rb +33 -0
  55. data/spec/lib/node_spec.rb +11 -3
  56. data/spec/macros/filters_spec.rb +5 -5
  57. data/spec/macros/macros_spec.rb +185 -8
  58. data/spec/macros/textile_spec.rb +217 -0
  59. data/spec/spec_helper.rb +25 -15
  60. data/spec/tasks/generate_spec.rb +3 -3
  61. data/spec/tasks/load_spec.rb +11 -1
  62. data/spec/tasks/project_spec.rb +0 -3
  63. data/styles/coderay.css +121 -0
  64. data/styles/default.css +54 -20
  65. data/{book/styles/css3.css → styles/pagination.css} +35 -7
  66. data/styles/ultraviolet/active4d.css +114 -0
  67. data/styles/ultraviolet/all_hallows_eve.css +72 -0
  68. data/styles/ultraviolet/amy.css +147 -0
  69. data/styles/ultraviolet/blackboard.css +88 -0
  70. data/styles/ultraviolet/brilliance_black.css +605 -0
  71. data/styles/ultraviolet/brilliance_dull.css +599 -0
  72. data/styles/ultraviolet/cobalt.css +149 -0
  73. data/styles/ultraviolet/dawn.css +121 -0
  74. data/styles/ultraviolet/eiffel.css +121 -0
  75. data/styles/ultraviolet/espresso_libre.css +109 -0
  76. data/styles/ultraviolet/idle.css +62 -0
  77. data/styles/ultraviolet/iplastic.css +80 -0
  78. data/styles/ultraviolet/lazy.css +73 -0
  79. data/styles/ultraviolet/mac_classic.css +123 -0
  80. data/styles/ultraviolet/magicwb_amiga.css +104 -0
  81. data/styles/ultraviolet/pastels_on_dark.css +188 -0
  82. data/styles/ultraviolet/slush_poppies.css +85 -0
  83. data/styles/ultraviolet/spacecadet.css +51 -0
  84. data/styles/ultraviolet/sunburst.css +180 -0
  85. data/styles/ultraviolet/twilight.css +137 -0
  86. data/styles/ultraviolet/zenburnesque.css +91 -0
  87. data/tasks/generate.rake +45 -26
  88. data/tasks/load.rake +21 -18
  89. data/tasks/project.rake +3 -1
  90. metadata +210 -41
  91. data/book/styles/default.css +0 -190
  92. data/book/text/authoring.textile +0 -351
  93. data/book/text/extending.textile +0 -148
  94. data/book/text/ref_config.textile +0 -0
  95. data/book/text/ref_macros.textile +0 -256
  96. data/book/text/troubleshooting.textile +0 -118
  97. data/styles/css3.css +0 -220
@@ -0,0 +1 @@
1
+ glyph compile text/introduction.glyph ../README.textile
data/book/snippets.yml CHANGED
@@ -5,9 +5,8 @@
5
5
  :gcode: "The following Glyph code:"
6
6
  :htmlcode: "Is translated into the following HTML code:"
7
7
  :markups: Textile or Markdown
8
- :prince: "=>[http://www.princexml.com/|Prince]"
9
8
  :filter_by_ext: "the $>[filters.by_file_extension] is @true@"
10
9
  :called_on_files: "If &[filter_by_ext], this macro is called automatically on =>[#m_include|included] files"
11
- :test: |-
12
- This is a
13
- Test snippet
10
+ :only_after_declaration: "can only be used _after_ its declaration"
11
+ :coderay: "=>[http://coderay.rubychan.de/|Coderay]"
12
+ :uv: "=>[http://ultraviolet.rubyforge.org/|Ultraviolet]"
@@ -0,0 +1,8 @@
1
+ Glyph was designed and developed by =>[http://www.h3rald.com|Fabio Cevasco] (h3rald).
2
+
3
+ Special thanks to the following individuals who contributed to Glyph by reporting and fixing issues and/or proposing and implementing new features:
4
+ * =>[http://www.jabbslad.com|Jamie Atkinson] (Jabbslad)
5
+ * =>[http://koraktor.github.com|Sebastian Staudt] (koraktor)
6
+
7
+
8
+
@@ -0,0 +1,548 @@
1
+ section[header[Text Editing]
2
+
3
+ One of the main purposes of Glyph is streamlining text editing. Glyph accomplishes this through its own macro language that can be used in conjunction with &[markups].
4
+
5
+ section[header[Introducing &[macros]]
6
+
7
+ By now you probably figured out what a macro looks like: it's an identifier of some kind that wraps a value or parameters within square brackets. More specifically:
8
+ * The macro identifier can contain _any_ character except for: @\[@, @\]@, @\\@, @\|@ or spaces.
9
+ * The delimiters can be either @\[@ and @\]@ or @\[=@ and @=\]@ (\.fmi[differences between delimiters|#esc_quot]).
10
+ * The value can be anything, even other macros. If a macro supports more than one parameter, they must be separated with @\|@. For example, the %>[link] can take an optional second parameter for the link text: @\..[=link[#link_id\|This is the link text]=]@.
11
+
12
+ A macro can often have one or more aliases. For example, @=>@ is an alias for the %>[link], so the following macro calls are equivalent:
13
+
14
+ codeph[=\.=>[#test\|Test Section]=]
15
+ codeph[=\.link[#test\|Test Section]=]
16
+
17
+ ]
18
+
19
+ section[header[Escaping and Quoting|esc_quot]
20
+
21
+ Glyph doesn't require any special control characters like LaTeX, and its macro syntax is very straightforward and liberal. This however comes with a price: because square brackets are used as delimiters, you must escape any square bracket in your text with a backslash. That's not _too_ bad if you think about it, unless you're writing programming code, in which case escaping every single square bracket can be painful.
22
+
23
+ If a portion of your text contains an excessive amount of square brackets, you may consider using the %>[escape] (or its alias @.@) with the @\[=@ and @=\]@ delimiters. By itself, the escape macro doesn't do anything: it just evaluates to its contents, but the special delimiters act as an escape for any square bracket within them. As a consequence, any macro within @\[=@ and @=\]@ will _not_ be evaluated.
24
+
25
+ You can use the quoting delimiters with _any_ macro identifier. Obviously, using them as delimiters for things like %>[section]s may not be a good idea, but they should be more or less mandatory with the %>[code], like this:
26
+
27
+ code[=
28
+ code\[=
29
+ section[header[A section]
30
+
31
+ This is a section.
32
+
33
+ section[header[A nested section]
34
+ This is another section.
35
+ ]
36
+ ]
37
+ \=]
38
+ =]
39
+
40
+ note[Although quoting delimiters allow you to use square brackets without escaping them, you must still escape them if you want to escape quoting delimiters themselves.]
41
+
42
+ Besides square brackets, there are other characters that must or can be escaped with backslashes, as shown in the following table
43
+
44
+ table[
45
+ tr[
46
+ th[Escape Sequence]
47
+ th[Evaluates to...]
48
+ th[Notes]
49
+ ]
50
+ tr[
51
+ td[@\\\[@]
52
+ td[@\[@]
53
+ td[&[sq_esc]]
54
+ ]
55
+ tr[
56
+ td[@\\\]@]
57
+ td[@\]@]
58
+ td[&[sq_esc]]
59
+ ]
60
+ tr[
61
+ td[@\\\\@]
62
+ td[@\\@]
63
+ td[Backslashes do not have to be escaped by default, but an escaped backslash will evaluate to itself.]
64
+ ]
65
+ tr[
66
+ td[@\\\=@]
67
+ td[@=@]
68
+ td[Equal signs do not have to be escaped by default, but an escaped equal sign will evaluate to iself.]
69
+ ]
70
+ tr[
71
+ td[@\\\|@]
72
+ td[@\|@]
73
+ td[Pipes must be escaped (even within quoting macros) unless they are used to separate macro parameters.]
74
+ ]
75
+ tr[
76
+ td[@\\\..@]
77
+ td[ ]
78
+ td[An escaped dot evaluates to nothing. Useful to separate macro identifiers from other characters:
79
+ codeph[= _\\..=>[#link\|This link is emphasized using Textile]_ =]
80
+ ]
81
+ ]
82
+ ]
83
+
84
+ ] --[End section]
85
+
86
+ section[header[Sections and Headers|sec_head]
87
+
88
+ Glyph documents are normally organized as a hierarchical tree of nested chapters, appendixes, sections, etc. To define a section, use the %>[section], like so:
89
+
90
+ code[=
91
+ section[
92
+ header[Section #1]
93
+
94
+ Write the section contents here...
95
+
96
+ section[
97
+ header[Section #2]
98
+
99
+ This section is nested into the previous one.
100
+
101
+ ] --[End of Section #2]
102
+ ] --[End of Section #1]
103
+ =]
104
+
105
+ This example defines two nested sections, each with its own header. The header is _mandatory_: it will be displayed at the start of the section and in the Table of Contents.
106
+
107
+ Note an important difference from HTML: there is no explicit level for the headers, as it will be determined at runtime when the document is compiled, based on how sections are nested. The previous code snippet (taken as it is), for example, will be transformed into the following HTML code:
108
+
109
+ <notextile>
110
+ highlight[=html|
111
+ <div class="section">
112
+ <h2>Section #1</h2>
113
+ <p>Write the section contents here...</p>
114
+ <div class="section">
115
+ <h3>Section #2</h3>
116
+ <p>This section is nested in the previous one</p>
117
+ </div>
118
+ </div>
119
+ =]
120
+ </notextile>
121
+
122
+ By default, in Glyph the first header level is _2_, so the two headers are rendered as @h2@ and @h3@, respectively (@--\[...\]@ macros are _comments_, therefore they are not included in the final output).
123
+
124
+ There are _a lot_ of macros that can be used in the same way as @section@, one for each element commonly used in =>[http://en.wikipedia.org/wiki/Book_design|Book Design]. Each one of them is a simple wrapper for a @<div>@ tag with a @class@ attribute set to its name.
125
+
126
+ The following table lists the identifiers of all section-like macros, divided according to the part of the book they should be placed in:
127
+
128
+ table[
129
+ tr[
130
+ td[*Frontmatter*]
131
+ td[@imprint@ ^†^, @dedication@ ^†^, @inspiration@ ^†^, @foreword@ ^‡^, @introduction@ ^‡^, @acknowledgement@ ^‡^, @prologue@ ^‡^, @toc@ ^*^]
132
+ ]
133
+ tr[
134
+ td[*Bodymatter*]
135
+ td[@volume@, @book@, @part@, @chapter@]
136
+ ]
137
+ tr[
138
+ td[*Backmatter*]
139
+ td[@epilogue@ ^‡^, @afterword@ ^‡^, @postscript@ ^†^, @appendix@, @addendum@ ^‡^, @glossary@ ^**‡^, @colophon@ ^†^, @bibliography@ ^**‡^, @promotion@ ^†^, @references@ ^**‡^, @index@ ^**‡^, @lot@ ^**‡^, @lof@ ^**‡^]
140
+ ]
141
+ ]
142
+
143
+ <notextile>*</notextile>: The %>[toc] is used to generate the Table of Contents automatically, and it must be used with no contents (i.e.: @toc\[\]@).
144
+
145
+ <notextile>**</notextile>: This macro is likely to be extended in future versions to generate/aggregate content automatically.
146
+
147
+ †: This section is not listed in the Table of Contents.
148
+
149
+ ‡: Any subsection of this section is not listed in the Table of Contents.
150
+
151
+ note[@frontmatter@, @bodymatter@ and @backmatter@ are also valid (and mandatory!) macro identifiers, typically already included in the default @document.glyph@ file of every project.]
152
+
153
+ ] --[End section]
154
+
155
+ section[header[Including Files and Snippets|incl]
156
+
157
+ If you're authoring a user manual, a long article or a book, writing everything inside a single file (@document.glyph@) may not be optimal. For this reason, Glyph provides an %>[include] (aliased by codeph[@]) that can be used to include the contents of any file within the @text/@ directory:
158
+
159
+ codeph[=@[introduction.textile]=]
160
+
161
+ The macro call above loads the contents of the @introduction.textile@ file, that can be stored _anywhere_ within the @text/@ directory.
162
+
163
+ note[Unlike with =>[img_fig|image and figures] that must be included with their _relative_ path to the @images/@ folder, you must not specify a relative path when including text files. This is due to the fact that images are copied _as they are_ in the @output/<format>/images/@ directory and they have to be linked from the output file.
164
+
165
+ A possible downside of this behavior is that file names must be unique within the entire @text/@ directory and any of its subdirectories]
166
+
167
+ When including a text file, an input filter macro is applied to its contents by default, based on the file extension used:
168
+ * @.textile@ &rarr; %>[textile]
169
+ * @.markdown@ or @.md@ &rarr; %>[markdown]
170
+
171
+ tip[You can override this behavior by setting the @filters.by_file_extensions@ configuration setting to @false@, like this:
172
+
173
+ @glyph config filters.by_file_extensions false@]
174
+
175
+ While including the context of an entire file is definitely a useful feature for content reuse, sometimes it can be an overkill. What if, for example, you just want to reuse a short procedure or even a sentence? In this case, you may want to consider using a _snippet_ instead.
176
+
177
+ Snippets are text strings saved in YAML format in the @snippets.yml@ file. They can be included anywhere in your document using the %>[snippet] (or its alias @&@).
178
+
179
+ tip[Besides storing snippets in the @snippets.yml@ file, you can also define them right in your document, using the %>[snippet:].]
180
+
181
+ box[Example|
182
+ Consider the following @snippets.yml@ file:
183
+
184
+ <notextile>
185
+ highlight[=yaml|
186
+ ---
187
+ :glang: Glyph Language
188
+ :macros: Glyph Macros
189
+ :sq_esc: \\\|-
190
+ Square brackets must be escaped
191
+ unless used as macro delimiters or within a quoting macro.
192
+ :markups: Textile or Markdown
193
+ :test: \\\|-
194
+ This is a
195
+ Test snippet
196
+ =]
197
+ </notextile>
198
+
199
+ You can use codeph[=&[markups]=] anywhere in your document instead of having to type "Textile or Markdown" every time. Additionally, later on you can change the value of the @markups@ snippets only in the @snippets.yml@ file to change it everywhere else in the document.
200
+ ] --[End Example]
201
+ tip[
202
+ Snippets (or any other macro) can be nested within other snippets. Glyph takes care of checking if you nested snippets or macros mutually and warns you as necessary.
203
+ ]
204
+
205
+ ] --[End Section]
206
+
207
+
208
+ section[header[Links and Bookmarks|links]
209
+
210
+ Lightweight markups let you create internal and external links in a very easy way, and you can still do so in Glyph. However, if you do so:
211
+ * There is no built-in way to check if they are valid
212
+ * There is no built-in way to determine the title of a link automatically
213
+
214
+ If you care about link validation and you want to save some keystrokes, then you should use the following markup-agnostic macros:
215
+ * @link@ (aliased to @=>@) -- to create internal and external links.
216
+ * @anchor@ (aliased to @#@) -- to create named anchors (bookmarks) within your document.
217
+
218
+ box[Example|
219
+
220
+ &[gcode]
221
+
222
+ code[=
223
+ This is a link to link[#test].
224
+
225
+ ...
226
+
227
+ This is link[#wrong].
228
+
229
+ This is a #[test\\\|test anchor].=]
230
+
231
+ &[htmlcode]
232
+
233
+ <notextile>
234
+ highlight[=html|
235
+ <p>This is a link to <a href="#test">test anchor</a>.</p>
236
+ <p>...</p>
237
+ <p>This is <a href="#wrong">#wrong</a>.</p>
238
+ <p>This is a <a id="test">test anchor</a>.</p>
239
+ =]
240
+ </notextile>
241
+
242
+ Additionally, the following warning message is displayed when =>[#compile|compiling]:
243
+
244
+ <notextile>
245
+ code[=
246
+ warning: Bookmark 'wrong' does not exist
247
+ -> source: @: aurhoting.textile
248
+ -> path: document/body/bodymatter/chapter/@/textile/section/section/box/link
249
+ =]
250
+ </notextile>
251
+
252
+ ]
253
+
254
+ Basically, if you use the %>[link] and the %>[anchor], Glyph makes sure that:
255
+ * All links point to valid anchors within the document (regardless if the anchors are before or after the link, in snippets or included files).
256
+ * There are no duplicate anchors within the documents.
257
+ * If no title is specified as second parameter for the %>[link], the anchor's title is used as such.
258
+
259
+ Besides using the %>[anchor] macro, you can also create an anchor for a header by passing an extra parameter to the %>[header], like this: codeph[=header[Header Title\|my_anchor]=].
260
+
261
+ note[
262
+ At present, link validation and automatic title retrieval only works with internal links (i.e. the check occurs if the first parameter of the %>[link] starts with a @#@). In the future, the macro could be extended to support external links as well.
263
+ ]
264
+
265
+ ] --[End section]
266
+
267
+ section[header[Evaluating Ruby code and Configuration Settings]
268
+
269
+ &[glang] is not a full-blown programming language, as it does not provide control flow or variables, for example.
270
+ However, it is possible to evaluate simple ruby code snippets using the @ruby@ macro (aliased to @%@), like this:
271
+ * codeph[=%[2 + 2]=] &rarr; 4
272
+ * codeph[=%[Time.now]=] &rarr; %[Time.now]
273
+ * codeph[=%[Glyph::VERSION]=] &rarr; %[Glyph::VERSION]
274
+
275
+ The scope for the code evaluation is the Kernel module, (with all inclusions required by Glyph itself).
276
+
277
+ Although it is possible to retrieve Glyph configuration settings in this way (e.g. codeph[=%[cfg('document.author')]=]), the %>[config] (aliased to @$@) makes things slightly simpler (e.g. codeph[=$[document.author]=]).
278
+
279
+ ]
280
+
281
+ section[header[Conditional Macros|cond_macros]
282
+
283
+ Sometimes you may want text to be included in a document only if certain conditions are satisfied. For example, you may want to display a disclaimer section only if the document is a draft (see $>[document.draft]), or use a particular stylesheet only if when you generate a PDF document.
284
+
285
+ To do so, you can use the %>[condition] (aliased by @?@), and a set of additional macros that can be used as conditional operators i.e.:
286
+ * %>[eq]
287
+ * %>[not]
288
+ * %>[and]
289
+ * %>[or]
290
+ * %>[match]
291
+
292
+ Consider the following code:
293
+
294
+ code[=
295
+ ?[$[document.draft]\|
296
+ This is a first draft of the Glyph Book]
297
+ ?[not[$[document.draft]]\|
298
+ This is the official version of the Glyph Book]
299
+ =]
300
+
301
+ In this case, if @document.draft@ is set to @true@, "This is a first draft of the Glyph Book" will be displayed; if not, "This is the official version of the Glyph Book" will be displayed instead.
302
+
303
+ The %>[condition] takes two parameters:
304
+ * the first one is the condition to evaluate
305
+ * the second one is the text to include in the document only if the condition is satisfied.
306
+
307
+ Note that _both_ parameters can contain macros, of course, so you can write things like:
308
+
309
+ code[=
310
+ ?[and[
311
+ eq[$[document.output]\|pdf]
312
+ \|
313
+ eq[$[tools.pdf_generator]\|prince]
314
+ ]
315
+ \|
316
+ style[pagination.css]]
317
+ =]
318
+
319
+ In this case, the @pagination.css@ stylesheet is included only when you're generating a PDF document using Prince XML.
320
+
321
+ section[header[Using macros inside the condition macro]
322
+ Conditionals are not implemented at parser level. This means that macros specified as the second parameter of a %>[condition] are _always_ parsed and _executed_, even _before_ that the condition is evaluated! Besides being inefficient, this can also lead to dangerous results if you're the %>[config:] or the %>[ruby], for example: because in that case a configuration setting or a piece of Ruby code is always executed...
323
+
324
+ To avoid this potentially dangerous side effect, you can _\.=>[#m_encode|encode]_ the second parameter of the condition macro, like this:
325
+
326
+ code[=
327
+ ?[$[document.draft]\|
328
+ *\[\= $:[document.output|html] \=\]]
329
+ =]
330
+
331
+ If you do so, if the condition is satisfied, the condition macro decodes the second parameter and interprets its contents. In this way, if @document.draft@ is true, @document.output@ will be set to @html@, otherwise it will be left unchanged.
332
+ ]
333
+
334
+ section[header[Results of conditional expressions]
335
+ The %>[condition] in Glyph works in a similar way as conditionals in programming languages: if the conditional expression (supplied as first parameter) is satisfied then the second parameter is executed or displayed. But when is a conditional expression satisfied? Glyph is a simple mini-language to perform text manipulation, and has no types, it can only understand text, therefore:
336
+ * A conditional expression is satisfied if it evaluates to a non-empty string except "false".
337
+ * A conditional expression is not satisfied if it evaluates to an empty string or the string "false".
338
+ ]
339
+
340
+ ] --[End section]
341
+
342
+ section[header[Images and Figures|img_fig]
343
+
344
+ Same as for =>[#links|links], you can also include images and figures using &[markups]. If you want additional features, you can use the %>[img] and the %>[fig], as shown in the following example:
345
+
346
+ box[Example|
347
+
348
+ &[gcode]
349
+
350
+ code[=
351
+ img[glyph.svg\|20%\|20%]
352
+
353
+ fig[example.png\|An example figure.]
354
+ =]
355
+
356
+ &[htmlcode]
357
+
358
+ <notextile>
359
+ highlight[=html|
360
+ <img src="images/glyph.svg" width="20%" height="20%" alt="-" />
361
+
362
+ <div class="figure">
363
+ <img src="images/example.png" alt="-"/>
364
+ <div class="caption">An example figure.</div>
365
+ </div>
366
+ =]
367
+ </notextile>
368
+ ]
369
+
370
+ note[
371
+ In future releases, figures will be numbered automatically and included in a _List of Figures_ section.
372
+ ]
373
+
374
+ ] --[End of section]
375
+
376
+ section[header[Source code|source_code]
377
+ If you're a programmer, chances are that you're going to include some source code in your articles and books. Glyph providers different ways to format source code, as described in the following sections.
378
+
379
+ section[header[Inline code]
380
+ The %>[codeph] can be used to format inline code. That's exactly the same as using @<code>@ tags, just remember to use =>[#esc_quot|escaping delimiters] and to escape pipes.
381
+ ]
382
+
383
+ section[header[Code block]
384
+ For code blocks, you have two choices: the %>[code], which simply wraps text into @<pre>@ and @<code>@ tags, or the %>[highlight] macro. The last one requires either &[coderay] or &[uv], but it highlights the most common programming language.
385
+
386
+ Cosider the following piece of ruby code:
387
+
388
+ code[=
389
+ def find_child(&block)
390
+ children.each do \|c\|
391
+ c.descend do \|node, level\|
392
+ return node if block.call(node)
393
+ end
394
+ end
395
+ nil
396
+ end
397
+ =]
398
+
399
+ It can be wrapped in a highlight macro, like so:
400
+
401
+ code[=
402
+ highlight[\=ruby\|
403
+ def find_child(&block)
404
+ children.each do \\\.\|c\\\.\|
405
+ c.descend do \\\.\|node, level\\\.\|
406
+ return node if block.call(node)
407
+ end
408
+ end
409
+ nil
410
+ end
411
+ \=]
412
+ =]
413
+
414
+ ...to produce the following, using the $[highlighters.current] highlighter:
415
+
416
+ <notextile>
417
+ highlight[=ruby|
418
+ def find_child(&block)
419
+ children.each do \|c\|
420
+ c.descend do \|node, level\|
421
+ return node if block.call(node)
422
+ end
423
+ end
424
+ nil
425
+ end
426
+ =]
427
+ </notextile>
428
+
429
+ box[Some Remarks|
430
+ * Highlighters require some configuration. For more information on relevant configuration settings, see the @highlighters.*@ configuration settings.
431
+ * If you're using the %>[highlight] together with %>[textile], you must wrap the macro call within @<notextile>@ tags.
432
+ * You must always escape pipes (@\|@) with the code or the highlight macro.
433
+ ]
434
+ ]
435
+
436
+ ] --[End of section]
437
+
438
+
439
+ ] --[End of Text Editing section]
440
+
441
+ section[header[Compiling your project|compile]
442
+
443
+ By default, a Glyph project can be _compiled_ into an HTML document. Additionally, Glyph can also be used to produce PDF documents through &[prince], and in future releases more formats could be supported.
444
+
445
+ section[header[Adding Stylesheets|stylesheets]
446
+
447
+ Currently, Glyph does not provide any native way to format text and pages. The reason is that there's absolutely no need for that: CSS does the job just fine. In particular, CSS3 offers specific attributes and elements that can be used specifically for paginated documents. That's no replacement for LaTeX by any means, but it is enough if you're not looking for advanced typographical features.
448
+
449
+ You can embed CSS files using the %>[style], like this:
450
+
451
+ code[= style[default.css] =]
452
+
453
+ In this case, the %>[style] looks for a @default.css@ file in the @/styles@ folder of your Glyph project _and_ among the default Glyph stylesheets, and embeds it within a @<style>@ tag. If you supply a file with a @.sass@ extension, it will interpret it as a Sass file and convert it to CSS automatically (if the _Haml_ gem is installed).
454
+
455
+ section[header[Default Stylesheets|default_styles]
456
+ Glyph provides the following default stylesheets, that can be referenced directly using the %>[style] macro:
457
+
458
+ table[
459
+ tr[
460
+ th[File name]
461
+ th[Notes]
462
+ ]
463
+ tr[
464
+ td[@default.css@]
465
+ td[The default stylesheet used for this book.]
466
+ ]
467
+ tr[
468
+ td[@pagination.css@]
469
+ td[A CSS3-compliant stylesheet used for pagination, suitable for PDF generation using Prince.]
470
+ ]
471
+ tr[
472
+ td[@coderay.css@]
473
+ td[The default &[coderay] stylesheet, used for syntax highlighting.]
474
+ ]
475
+ tr[
476
+ td[@ultraviolet/*@]
477
+ td[This folder contains the following &[uv] stylesheets, used for syntax highlighting: codeph[%[(Glyph::HOME/"styles/ultraviolet").children.sort.map{|c| c.basename}.join(", ")]]]
478
+ ]
479
+ ]
480
+
481
+ ]
482
+
483
+ ]
484
+
485
+ section[header[HTML output]
486
+
487
+ To compile a Glyph project to an HTML document, use the #>[compile] within your Glyph project folder. Glyph parses the @document.glyph@ file (and all included files and snippets); if no errors are found, Glyph creates an HTML document in the @/output/html@ folder.
488
+
489
+ The name of the HTML file can be set in the configuration (@document.filename@ setting).
490
+ ]
491
+
492
+ section[header[PDF Output]
493
+
494
+ To generate a PDF document, you must specify @pdf@ as format, like this:
495
+
496
+ code[= glyph compile -f pdf =]
497
+
498
+ The command above will attempt to compile the project into an HTML document and then call Prince to generate a PDF document from it. In order for this to work, you must download and install &[prince]. It's not open source, but the free version is fully functional, and it just adds a small logo on the first page.
499
+
500
+ note[Glyph v\.%[Glyph::VERSION.strip] has been successfully tested with Prince v7.0, and the PDF version of this very book was generated with it.]
501
+
502
+ ]
503
+
504
+ section[header[Auto Regeneration|auto_regeneration]
505
+ You can also call the #>[compile] with a @--auto@ switch. If you do so, your project will be recompiled automatically every time any source file is changed.
506
+
507
+ note[Auto regeneration requires the =>[http://rubygems.org/gems/directory_watcher|directory_watcher] gem to be installed.]
508
+
509
+ ]
510
+
511
+ ]
512
+
513
+ section[header[Compiling single Glyph files|lite_mode]
514
+ Glyph's primary goal is to author complex documents like books or manuals. In order to do so, a Glyph project is required to keep everything organized and automated via a set of predefined conventions, exactly like Ruby on Rails or other similar frameworks do.
515
+
516
+ If you want to write a one-page article or a short draft, however, creating and managing Glyph projects can be an unnecessary burden. Luckily, you don't have to: you can use Glyph to compile single files containing Glyph code, by adding one parameter (or two if you want to specify a custom destination file) to the #>[compile], like this:
517
+
518
+ codeph[glyph compile source.glyph destination.htm]
519
+
520
+ This command will process a file called @source.glyph@ and produce an HTML file called @destination.htm@.
521
+
522
+ section[header[Limitations|lite_limitations]
523
+ &:[only_defined_through|can only be defined inside the source file, using the]
524
+ This sort of "lite" mode comes with a few minor limitations:
525
+ * Snippets &[only_defined_through] %>[snippet:] macro.
526
+ * Project configuration settings &[only_defined_through] %>[config:] macro.
527
+ * Custom macros &[only_defined_through] %>[macro:] macro.
528
+ * Images must be linked with their absolute path, or a path relative to the current directory, and will not be copied anywhere when the output file is generated.
529
+ * Stylesheets must be referenced with their absolute path, a path relative to the current directory, or the name of an existing Glyph system stylesheet ![link to system stylesheet list].
530
+ * The %>[include] cannot be used (if you need to include other text files, you should probably use a Glyph project...)
531
+ ]
532
+ ]
533
+
534
+ section[header[Using Glyph programmatically]
535
+ Besides using Glyph from the command line, you can also use it straight from your code. Glyph's public =>[http://yardoc.org/docs/glyph/Glyph|API] is simple and can be used to:
536
+ * Retrieve and update configuration settings (using @Glyph\[\]@ and @Glyph\[\]=@)
537
+ * Filter text to HTML (using @Glyph#filter@)
538
+ * Compile Glyph source files into HTML or PDF files (using @Glyph#compile@)
539
+
540
+ That's pretty much it. Of course, both the @filter@ and @compile@ method cause Glyph to run in =>[#lite_mode|_lite_ mode], so the same =>[#lite_limitations|limitations] apply.
541
+
542
+ tip[For an example on how to use Glyph programmatically (specifically in conjunction with the =>[http://nanoc.stoneship.org/|nanoc] static site generator), see =>[http://github.com/h3rald/h3rald|h3rald.com source code], in particular:
543
+ * =>[http://github.com/h3rald/h3rald/blob/master/lib/glyph-data.rb|lib/glyph-data.rb] -- updating configuration settings.
544
+ * =>[http://github.com/h3rald/h3rald/blob/master/lib/glyph-filter.rb|lib/glyph-data.rb] -- using the @Glyph#filter@ method.
545
+ * =>[http://github.com/h3rald/h3rald/blob/master/Rules|Rules] -- using the @Glyph#compile@ method to generate PDF files.
546
+ ]
547
+
548
+ ]