glyph 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/Rakefile +19 -40
  2. data/benchmark.rb +1 -2
  3. data/book/config.yml +8 -8
  4. data/book/document.glyph +18 -19
  5. data/book/images/glyph/commands_tasks.png +0 -0
  6. data/book/lib/layouts/bookindex.glyph +113 -111
  7. data/book/lib/layouts/bookpage.glyph +112 -108
  8. data/book/lib/macros/reference.rb +2 -2
  9. data/book/lib/tasks/tasks.rake +1 -1
  10. data/book/text/acknowledgements.glyph +1 -0
  11. data/book/text/changelog.glyph +140 -112
  12. data/book/text/compiling/compiling.glyph +36 -24
  13. data/book/text/compiling/lite_mode.glyph +11 -11
  14. data/book/text/compiling/programmatic_usage.glyph +57 -57
  15. data/book/text/config/document.glyph +7 -1
  16. data/book/text/config/options.glyph +5 -3
  17. data/book/text/config/output.glyph +41 -8
  18. data/book/text/extending/bookmarks_headers.glyph +13 -11
  19. data/book/text/extending/command.glyph +1 -1
  20. data/book/text/extending/commands_tasks.glyph +2 -2
  21. data/book/text/extending/internals.glyph +29 -29
  22. data/book/text/extending/interpreting.glyph +48 -9
  23. data/book/text/extending/macro_def.glyph +80 -32
  24. data/book/text/extending/output_format.glyph +2 -2
  25. data/book/text/extending/placeholders.glyph +27 -15
  26. data/book/text/extending/validators.glyph +1 -1
  27. data/book/text/getting_started/configuration.glyph +1 -1
  28. data/book/text/getting_started/create_project.glyph +4 -5
  29. data/book/text/getting_started/structure.glyph +2 -2
  30. data/book/text/macros/macros_core.glyph +341 -199
  31. data/book/text/macros/macros_filters.glyph +1 -1
  32. data/book/text/macros/macros_inline.glyph +3 -3
  33. data/book/text/macros/macros_structure.glyph +1 -1
  34. data/book/text/ref_commands.glyph +98 -93
  35. data/book/text/snippets.glyph +18 -0
  36. data/book/text/stats/bookmarks.glyph +16 -16
  37. data/book/text/stats/links.glyph +23 -23
  38. data/book/text/stats/macros.glyph +14 -14
  39. data/book/text/stats/snippets.glyph +26 -26
  40. data/book/text/stats/stats.glyph +14 -15
  41. data/book/text/text_editing/attribute_intro.glyph +8 -8
  42. data/book/text/text_editing/code.glyph +16 -16
  43. data/book/text/text_editing/conditionals.glyph +12 -13
  44. data/book/text/text_editing/esc_quot.glyph +3 -3
  45. data/book/text/text_editing/evaluation.glyph +57 -3
  46. data/book/text/text_editing/inclusions.glyph +34 -25
  47. data/book/text/text_editing/macro_composition.glyph +28 -0
  48. data/book/text/text_editing/macro_intro.glyph +4 -4
  49. data/book/text/text_editing/section_aliases.glyph +23 -23
  50. data/book/text/text_editing/sections.glyph +22 -22
  51. data/book/text/text_editing/stylesheets.glyph +33 -33
  52. data/book/text/text_editing/topics.glyph +6 -6
  53. data/book/text/text_editing/xml_fallback.glyph +1 -1
  54. data/book/text/troubleshooting/errors_command.glyph +4 -4
  55. data/book/text/troubleshooting/errors_generic.glyph +16 -10
  56. data/book/text/troubleshooting/errors_macro.glyph +18 -21
  57. data/book/text/troubleshooting/errors_parser.glyph +7 -7
  58. data/config.yml +51 -29
  59. data/document.glyph +18 -18
  60. data/glyph.gemspec +39 -287
  61. data/layouts/web5/topic.glyph +1 -1
  62. data/lib/glyph.rb +42 -10
  63. data/lib/glyph/analyzer.rb +5 -2
  64. data/lib/glyph/bookmark.rb +3 -1
  65. data/lib/glyph/commands.rb +11 -9
  66. data/lib/glyph/commands/add.rb +3 -1
  67. data/lib/glyph/commands/compile.rb +10 -7
  68. data/lib/glyph/commands/config.rb +7 -5
  69. data/lib/glyph/commands/init.rb +2 -0
  70. data/lib/glyph/commands/outline.rb +2 -0
  71. data/lib/glyph/commands/stats.rb +3 -0
  72. data/lib/glyph/commands/todo.rb +2 -0
  73. data/lib/glyph/config.rb +2 -0
  74. data/lib/glyph/document.rb +34 -9
  75. data/lib/glyph/interpreter.rb +2 -0
  76. data/lib/glyph/macro.rb +97 -25
  77. data/lib/glyph/macro_validators.rb +9 -6
  78. data/lib/glyph/node.rb +3 -1
  79. data/lib/glyph/parser.rb +68 -33
  80. data/lib/glyph/reporter.rb +3 -1
  81. data/lib/glyph/syntax_node.rb +23 -28
  82. data/lib/glyph/system_extensions.rb +21 -0
  83. data/lib/glyph/utils.rb +24 -4
  84. data/macros/block.rb +111 -0
  85. data/macros/core.rb +163 -33
  86. data/macros/filters.rb +3 -2
  87. data/macros/inline.rb +97 -0
  88. data/macros/reps/html.rb +180 -0
  89. data/macros/reps/html5.rb +100 -0
  90. data/macros/reps/web.rb +4 -0
  91. data/macros/reps/web5.rb +4 -0
  92. data/macros/structure.rb +229 -0
  93. data/macros/xml.rb +29 -24
  94. data/spec/config.yml +7 -0
  95. data/spec/files/article.glyph +2 -2
  96. data/spec/files/web_doc.glyph +9 -5
  97. data/spec/lib/commands_spec.rb +13 -9
  98. data/spec/lib/config_spec.rb +2 -2
  99. data/spec/lib/document_spec.rb +10 -0
  100. data/spec/lib/glyph_spec.rb +30 -8
  101. data/spec/lib/macro_spec.rb +39 -4
  102. data/spec/lib/macro_validators_spec.rb +3 -4
  103. data/spec/lib/parser_spec.rb +7 -0
  104. data/spec/lib/reporter_spec.rb +1 -0
  105. data/spec/lib/syntax_node_spec.rb +40 -6
  106. data/spec/macros/core_spec.rb +154 -21
  107. data/spec/macros/filters_spec.rb +1 -1
  108. data/spec/macros/html5_spec.rb +4 -5
  109. data/spec/macros/macros_spec.rb +6 -7
  110. data/spec/macros/web5_spec.rb +3 -3
  111. data/spec/macros/web_spec.rb +10 -7
  112. data/spec/macros/xml_spec.rb +11 -2
  113. data/spec/spec_helper.rb +11 -5
  114. data/spec/tasks/generate_spec.rb +40 -5
  115. data/spec/tasks/load_spec.rb +1 -13
  116. data/styles/coderay.css +147 -38
  117. data/styles/default.css +19 -22
  118. data/styles/pagination.css +30 -30
  119. data/tasks/generate.rake +54 -18
  120. data/tasks/load.rake +9 -24
  121. data/tasks/project.rake +0 -2
  122. metadata +208 -207
  123. data/.gitignore +0 -7
  124. data/VERSION +0 -1
  125. data/book/snippets.yml +0 -18
  126. data/lib/glyph/macro_helpers.rb +0 -282
  127. data/macros/html/block.rb +0 -124
  128. data/macros/html/inline.rb +0 -42
  129. data/macros/html/structure.rb +0 -191
  130. data/macros/html5/block.rb +0 -69
  131. data/macros/html5/inline.rb +0 -24
  132. data/macros/html5/structure.rb +0 -140
@@ -1,38 +1,38 @@
1
1
  stats_for[
2
- @title[all snippets]
3
- @object[all snippets]
4
- @command[--snippets]
5
- @example[
2
+ @title[all snippets]
3
+ @object[all snippets]
4
+ @command[--snippets]
5
+ @example[
6
6
  ===== Snippets
7
7
  -- Total Snippets: 21
8
8
  -- Total Used Snippets: 21
9
9
  -- Total Unused Snippets: 0
10
10
  -- Snippets:
11
- bin_params called_on_files coderay filter_by_ext gcode
12
- glang htmlcode img_attrs img_file macros
13
- markups only_after_declaration only_defined_through opt prince
14
- referenced_with_path sq_esc unsafe uv wkhtml
15
- yardoc
11
+ bin_params called_on_files coderay filter_by_ext
12
+ glang htmlcode img_attrs img_file
13
+ markups only_after_declaration only_defined_through opt
14
+ referenced_with_path sq_esc unsafe uv
15
+ rubydoc
16
16
  -- Used Snippets:
17
- bin_params called_on_files coderay filter_by_ext gcode
18
- glang htmlcode img_attrs img_file macros
19
- markups only_after_declaration only_defined_through opt prince
20
- referenced_with_path sq_esc unsafe uv wkhtml
21
- yardoc
22
- ]
23
- @remarks[
17
+ bin_params called_on_files coderay filter_by_ext
18
+ glang htmlcode img_attrs img_file
19
+ markups only_after_declaration only_defined_through opt
20
+ referenced_with_path sq_esc unsafe uv
21
+ rubydoc
22
+ ]
23
+ @remarks[
24
24
  * Information on snippet usage and definitions is available only when displaying statistics for a single snippet.
25
- ]
25
+ ]
26
26
  ]
27
27
  stats_for[
28
- @title[a single snippet]
29
- @object[a single snippet (e.g. code[yardoc])]
30
- @command[--snippet=yardoc]
31
- @example[
32
- ===== Snippet 'yardoc'
28
+ @title[a single snippet]
29
+ @object[a single snippet (e.g. code[rubydoc])]
30
+ @command[--snippet=rubydoc]
31
+ @example[
32
+ ===== Snippet 'rubydoc'
33
33
  -- Definition:
34
34
  -------------------
35
- http://yardoc.org/docs/h3rald-glyph
35
+ http://rubydoc.info/gems/glyph
36
36
  -------------------
37
37
  -- Total Used Instances: 18
38
38
  -- Usage Details:
@@ -43,8 +43,8 @@ http://yardoc.org/docs/h3rald-glyph
43
43
  - text/extending/validators.glyph (1)
44
44
  - text/macros/macros_core.glyph (2)
45
45
  - text/stats/macros.glyph (1)
46
- ]
47
- @remarks[
46
+ ]
47
+ @remarks[
48
48
  * Nested snippets appear as within the file containing the top-level snippet.
49
- ]
49
+ ]
50
50
  ]
@@ -1,25 +1,24 @@
1
- rewrite:[stats_for|
2
- section[
3
- @title[Displaying stats about {{title}}]
4
- txt[To display statistics about {{object}}, execute code[glyph stats {{command}}]. Glyph displays something like this:]
5
- highlight[=html|
1
+ def:[stats_for|
2
+ section[
3
+ @title[Displaying stats about {{title}}]
4
+ txt[To display statistics about {{object}}, execute code[glyph stats {{command}}]. Glyph displays something like this:]
5
+ highlight[=html|
6
6
  {{example}}
7
- =]
8
- section[
9
- @title[Remarks]
10
- txt[
7
+ =]
8
+ section[
9
+ @title[Remarks]
10
+ txt[
11
11
  {{remarks}}
12
- ]
13
- ]
14
- ]
12
+ ]
13
+ ]
14
+ ]
15
15
  ]
16
16
  p[Glyph includes a #>[stats] that can be used to display useful statistics about your Glyph project. If you try running Glyph's command help, you'll see that this command can take quite a few options:
17
17
  ]
18
18
  highlight[html|
19
19
  $ glyph help stats
20
- =====================================
21
- Glyph v\.%[Glyph::VERSION]
22
- =====================================
20
+ Glyph v0.5.0
21
+
23
22
  stats \[options\]
24
23
  Display statistics
25
24
 
@@ -1,22 +1,22 @@
1
- txt[
1
+ txt[
2
2
  Although a macro can take any number of parameters, they are often no more than two or three, for readibility reasons: parameters have no name, but their position within a macro is significant.
3
3
 
4
4
  If you have something like this:
5
- ]
5
+ ]
6
6
 
7
- highlight[=html|custom_image[test.png\|50%\|50%\|Test Image]=]
8
- txt[
7
+ highlight[=html|custom_image[test.png\|50%\|50%\|Test Image]=]
8
+ txt[
9
9
  it may still be easy enough to understand what each parameter is used for, but:
10
10
  * you can easily forget that the third parameter is the image width
11
11
  * if you don't want to resize the image, you still have to pass _empty parameters_ to the macro, like this: code[=custom_image[test2.png\|\|\|Test Image]=]
12
12
 
13
13
  To avoid these situations, some macros which would normally take three or four parameters take optional attributes instead, so you can write:
14
- ]
15
- highlight[=html|
14
+ ]
15
+ highlight[=html|
16
16
  image[test.png
17
17
  @width[50%]
18
18
  @alt[Test Image]
19
19
  @height[50%]
20
20
  ]=]
21
- p[More verbose, of course, but definitely more readable. In this way, if you won't want to scale an image, you can safely omit the code[@width] and code[@height] attributes.]
22
- note[Like parameters, attributes can contain other macros, too.]
21
+ p[More verbose, of course, but definitely more readable. In this way, if you won't want to scale an image, you can safely omit the code[@width] and code[@height] attributes.]
22
+ note[Like parameters, attributes can contain other macros, too.]
@@ -1,9 +1,9 @@
1
- txt[
1
+ txt[
2
2
  If you're a programmer, chances are that you're going to include some source code in your articles and books. Glyph offers two ways to format code blocks effortlessly: the %>[codeblock], which simply wraps text into @<pre>@ and @<code>@ tags, or the %>[highlight]. The last one requires either &[coderay] or &[uv], but it provides syntax highlighting for the most common programming languages.
3
3
 
4
4
  Cosider the following piece of ruby code:
5
- ]
6
- highlight[=mediawiki|
5
+ ]
6
+ highlight[=mediawiki|
7
7
  def find_child(&block)
8
8
  children.each do \|c\|
9
9
  c.descend do \|node, level\|
@@ -12,22 +12,22 @@ def find_child(&block)
12
12
  end
13
13
  nil
14
14
  end
15
- =]
16
- p[It can be wrapped in a highlight macro, like so:]
17
- highlight[=mediawiki|
15
+ =]
16
+ p[It can be wrapped in a highlight macro, like so:]
17
+ highlight[=mediawiki|
18
18
  highlight[\=ruby\|
19
19
  def find_child(&block)
20
- children.each do \\\.\|c\\\.\|
21
- c.descend do \\\.\|node, level\\\.\|
20
+ children.each do \\\/\|c\\\/\|
21
+ c.descend do \\\/\|node, level\\\/\|
22
22
  return node if block.call(node)
23
23
  end
24
24
  end
25
25
  nil
26
26
  end
27
27
  \=]
28
- =]
29
- p[...to produce the following, using the $[filters.highlighter] highlighter:]
30
- highlight[=ruby|
28
+ =]
29
+ p[...to produce the following, using the $[filters.highlighter] highlighter:]
30
+ highlight[=ruby|
31
31
  def find_child(&block)
32
32
  children.each do \|c\|
33
33
  c.descend do \|node, level\|
@@ -36,11 +36,11 @@ def find_child(&block)
36
36
  end
37
37
  nil
38
38
  end
39
- =]
40
- box[Some Remarks|
41
- txt[
39
+ =]
40
+ box[Some Remarks|
41
+ txt[
42
42
  * Highlighters require some configuration. For more information on relevant configuration settings, see the =>[#cfg_filters|filters.*] configuration settings.
43
43
  * If you're using the %>[highlight] together within the %>[textile], you must wrap the macro call within @<notextile>@ tags.
44
44
  * You must always escape pipes (@\|@) with the code or the highlight macro.
45
- ]
46
- ]
45
+ ]
46
+ ]
@@ -1,4 +1,4 @@
1
- txt[
1
+ txt[
2
2
  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 the $>[document.draft]), or use a particular stylesheet only if when you generate a PDF document.
3
3
 
4
4
  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.:
@@ -6,16 +6,15 @@ To do so, you can use the %>[condition] (aliased by @?@), and a set of additiona
6
6
  * %>[not]
7
7
  * %>[and]
8
8
  * %>[or]
9
- * %>[match]
10
9
 
11
10
  Consider the following code:
12
- ]
13
- highlight[=html|
11
+ ]
12
+ highlight[=html|
14
13
  ?[$[document.draft]\|
15
14
  This is a first draft of the Glyph Book\|
16
15
  This is the official version of the Glyph Book]
17
- =]
18
- txt[
16
+ =]
17
+ txt[
19
18
  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.
20
19
 
21
20
  The %>[condition] takes up to three parameters:
@@ -24,8 +23,8 @@ The %>[condition] takes up to three parameters:
24
23
  # _(Optional)_ the text to include in the document if the condition is _not_ satisfied.
25
24
 
26
25
  Note that _all_ parameters can contain macros, of course, so you can write things like:
27
- ]
28
- highlight[=html|
26
+ ]
27
+ highlight[=html|
29
28
  ?[and[
30
29
  eq[$[document.output]\|pdf]
31
30
  \|
@@ -33,13 +32,13 @@ Note that _all_ parameters can contain macros, of course, so you can write thing
33
32
  ]
34
33
  \|
35
34
  style[pagination.css]]
36
- =]
37
- p[In this case, the code[pagination.css] stylesheet is included only when you're generating a PDF document using Prince XML.]
35
+ =]
36
+ p[In this case, the code[pagination.css] stylesheet is included only when you're generating a PDF document using Prince XML.]
38
37
  section[
39
- @title[Results of conditional expressions]
40
- txt[
38
+ @title[Results of conditional expressions]
39
+ txt[
41
40
  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:
42
41
  * A conditional expression is satisfied if it evaluates to a non-empty string except "false".
43
42
  * A conditional expression is not satisfied if it evaluates to an empty string or the string "false".
44
- ]
43
+ ]
45
44
  ]
@@ -47,7 +47,7 @@ This is another section.
47
47
  ]
48
48
  tr[
49
49
  td[code[\\\=]]
50
- td[code[\.=]]
50
+ td[code[\/=]]
51
51
  td[Equal signs do not have to be escaped by default, but an escaped equal sign will evaluate to iself.]
52
52
  ]
53
53
  tr[
@@ -56,9 +56,9 @@ This is another section.
56
56
  td[Pipes must be escaped (even within quoting macros) unless they are used to separate macro parameters.]
57
57
  ]
58
58
  tr[
59
- td[code[\\.]]
59
+ td[code[\\/]]
60
60
  td[]
61
- td[An escaped dot evaluates to nothing. Useful to separate macro identifiers from other characters: br[]code[=_\\.=>[#link\|This link is emphasized using Textile]_ =]
61
+ td[An escaped dot evaluates to nothing. Useful to separate macro identifiers from other characters: br[]code[=_\\/=>[#link\|This link is emphasized using Textile]_ =]
62
62
  ]
63
63
  ]
64
64
  ]
@@ -1,5 +1,59 @@
1
- txt[
2
- &[glang] is not a full-blown programming language and it is currently not Turing-complete (it does not provide loops). However, it is possible to evaluate simple ruby code snippets using the @ruby@ macro (aliased to @%@), like this:
1
+ §txt[
2
+ @title[Turing-completeness]
3
+
4
+ As of version 0.5.0, Glyph can be considered _Turing-complete_, as it satisfies the following =>[http://c2.com/cgi/wiki?LanguageRequirementsForTuringCompleteness|requirements for Turing-completeness]:
5
+ * A conditional construct, implemented via the %>[condition].
6
+ * Variable assignment, by setting the value of snippets using the %>[snippet:] and of attributes using the %>[attribute:].
7
+ * (infinite) iteration implemented through the %>[while] or recursion, which is possible thanks to the %>[define:].
8
+ * A memory model which emulates an infinite store: there are no enforced limits on attribute/snippets allocations and number of algorithms or parameters.
9
+ ]
10
+
11
+ §txt[
12
+ @title[Operations on integer values]
13
+
14
+ Glyph can be used to perform operation on integer values (additions, subtractions and multiplications). For example, code[=\/add[2\|3\|7]=] will evaluate to @12@, and code[=\/multiply[add[3\|7]\|subtract[5\|1\|2]]=] will return 20.
15
+
16
+ As a more complex example, consider the following @factorial@ macro, which is able to calculate the factorial of a number recursively:
17
+
18
+ highlight[=html|
19
+ def:[factorial\|
20
+ ?[
21
+ eq[{{0}}\|0]\|1\|
22
+ multiply[
23
+ {{0}} \| factorial[subtract[{{0}}\|1]]
24
+ ]
25
+ ]
26
+ ]
27
+ =]
28
+
29
+ If you try executing code[=factorial[5]=], it will evaluate to @120@.
30
+
31
+ ]
32
+ §txt[
33
+ @title[Lexically-scoped attribute assignment]
34
+
35
+ =>[#snippets] can be used in a similar way as _variables_ are used in programming languages. Or better, they can be used as _global variables_, as they are visible from anywhere in the Glyph document. If you need something more restricted to, say, a section and all its subsections, you can define your own attributes and use them in a very similar way.
36
+
37
+ Consider the following Glyph code:
38
+ ]
39
+ highlight[=html|
40
+ let[
41
+ @:[a\|bits]
42
+ @:[b\|bobs]
43
+ section[
44
+ @title[Something more about attributes]
45
+ Attributes are like lexically scoped variables. You can use them to store @[a] and @[b].
46
+ ]
47
+ ]
48
+ =]
49
+ txt[
50
+ The %>[let] here only acts as a dummy macro (it does nothing really) to bind attributes using the %>[attribute:] (aliased by code[@:]). Attributes can then be used anywhere within the @let@ macro, so the content of the section reads: "Attributes are like lexically-scoped variables. You can use them to store bits and bobs".
51
+
52
+ Note that attributes defined through the %>[attribute:] are... well, attributes! Feel free to use the %>[attribute] to access standard attributes like @title@, etc.
53
+ ]
54
+ §txt[
55
+ @title[Evaluating Ruby code]
56
+ For anything more complex than what described in the previous sections you can also evaluate simple ruby code snippets using the @ruby@ macro (aliased to @%@), like this:
3
57
  * code[=%[2 + 2]=] &rarr; 4
4
58
  * code[=%[Time.now]=] &rarr; %[Time.now]
5
59
  * code[=%[Glyph::VERSION]=] &rarr; %[Glyph::VERSION]
@@ -7,4 +61,4 @@
7
61
  The scope for the code evaluation is the Kernel module, (with all inclusions required by Glyph itself).
8
62
 
9
63
  Although it is possible to retrieve Glyph configuration settings in this way (e.g. code[=%[cfg('document.author')]=]), the %>[config] (aliased to @$@) makes things slightly simpler (e.g. code[=$[document.author]=]).
10
- ]
64
+ ]
@@ -1,4 +1,7 @@
1
- txt[
1
+ §[
2
+ @title[File inclusions]
3
+ @id[file-inclusions]
4
+ txt[
2
5
  If you're authoring a user manual, a long article, or a book, writing everything inside a single @document.glyph@ file may not be optimal. For this reason, Glyph provides an %>[include] that can be used to include the contents of any file within the @text/@ directory:
3
6
 
4
7
  code[=include[general/introduction.textile]=]
@@ -10,31 +13,37 @@ When including a text file, an input filter macro is applied to its contents by
10
13
  * @.markdown@ or @.md@ &rarr; %>[markdown]
11
14
 
12
15
  You can override this behavior by setting the @filters.by_file_extensions@ configuration setting to @false@. If no extension is specified, @.glyph@ is assumed.
13
-
14
- tip[The %>[include] can also be used to include (and evaluate) ruby files (with a @.rb@ extension). In this case, the ruby file must be placed within the @lib/@ directory of the current project.]
15
-
16
+ ]
17
+ §txt[
18
+ @title[Remarks]
19
+ * The %>[include] can also be used to include (and evaluate) ruby files (with a @.rb@ extension). In this case, the ruby file must be placed within the @lib/@ directory of the current project.
20
+ * The %>[load] macro can be used to include the content of any file _without_ performing any evaluation.
21
+ ]
22
+ ]
23
+ §[
24
+ @title[Snippets]
25
+ @id[snippets]
26
+ txt[
16
27
  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 or a single word? In this case, you may want to consider using a _snippet_ instead.
17
28
 
18
- 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 @&@).
29
+ Snippets can be defined using the %>[snippet:] (aliased by @&:@) and called by using the %>[snippet] (aliased by @&@). Consider the following simple example:
30
+ ]
31
+ highlight[=html|
32
+ &:[markups\|Textile or Markdown]
19
33
 
20
- tip[Besides storing snippets in the @snippets.yml@ file, you can also define them right in your document, using the %>[snippet:].]
21
- ]
22
- box[Example|
23
- p[Consider the following code[snippets.yml] file:]
24
- highlight[=yaml|
25
- ---
26
- :glang: Glyph Language
27
- :macros: Glyph Macros
28
- :sq_esc: \\\|-
29
- Square brackets must be escaped
30
- unless used as macro delimiters or within a quoting macro.
31
- :markups: Textile or Markdown
32
- :test: \\\|-
33
- This is a
34
- Test snippet
35
- =]
36
- p[You can use code[=&amp;[markups]=] anywhere in your document instead of having to type "\.&[markups]" every time. Additionally, later on you can change the value of the code[markups] snippet only in the code[snippets.yml] file to change it everywhere else in the document.]
37
- ]
38
- tip[
34
+ Glyph supports &[markups].
35
+ =]
36
+ p[You can use code[=&amp;[markups]=] anywhere in your document instead of having to type "\/&[markups]" every time. Additionally, later on you can change the value of the code[markups] to change it everywhere else in the document.]
37
+ tip[
39
38
  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.
40
- ]
39
+ ]
40
+ ]
41
+ §[
42
+ @title[Fragments]
43
+ @id[fragments]
44
+ txt[As an even simpler alternative to snippets, consider using _fragments_. The %>[fragment] (aliased by @##@) can be used to mark a section of Glyph code as a fragment that can then be _embedded_ using the %>[embed] (aliased by @<=@), like this:]
45
+
46
+ highlight[=html|
47
+ Snippets and fragments ##[good_way\|are a good way to reuse] small chunks of content, while the include and load macros <=[good_way] entire files.
48
+ =]
49
+ ]
@@ -0,0 +1,28 @@
1
+ txt[
2
+ Glyph macros can be _composed_ with other using the @/@ character. Macro composition can be used instead of nesting, provided that macro containers (also called _dispatchers_ in certain situations) take only one parameter and no attributes.
3
+
4
+ For example, the following code:
5
+ ]
6
+ highlight[=html|
7
+ ?[
8
+ not[output?[pdf]]\|
9
+ ...
10
+ ]
11
+ =]
12
+
13
+ p[Can be written like this:]
14
+
15
+ highlight[=html|
16
+ ?[
17
+ not/output?[pdf]\|
18
+ ...
19
+ ]
20
+ =]
21
+
22
+ txt[
23
+ In this case, the %>[not] was composed with the %>[output?], thus removing one level of nesting.
24
+
25
+ Composition can be useful to simplify complex Glyph macro constructs, but also for _macro dispatching_. Currently, Glyph supports two _dispatchers_:
26
+ * The %>[s], used to call almost any method of the Ruby String class.
27
+ * The %>[xml], used to render raw XML tags.
28
+ ]