/
macros_core.glyph
356 lines (321 loc) · 8.21 KB
/
macros_core.glyph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
ref_macro[
@n[add]
@desc[Adds two or more integers together.]
@params[Two or more integer values.]
@example[=add[2\|5\|7]=]
]
ref_macro[
@n[alias]
@desc[Creates a macro alias.]
@params[
-p[0|The name of the alias.]
-p[1|The name of an existing macro.]
]
@example[=alias[s\|section]=]
]
ref_macro[
@n[and]
@desc[Conditional code[and] operator, to be used with the %>[condition].]
@params[&[bin_params]]
@example[=?[and[true\|false]\|This is never displayed.]=]
]
ref_macro[
@n[attribute]
@desc[Returns the value of the specified attribute. ##[see_let|For a more complete example, see the %>[let]].]
@aliases[@]
@example[=@[title]=]
@params[-p[0|The name of the attribute to retrieve.]]
]
ref_macro[
@n[attribute:]
@desc[Sets the value of the specified attribute. <=[see_let].]
@aliases[@:]
@example[=@:[title\|Test Title]=]
@params[
-p[0|The name of the attribute to set.]
-p[1|The value of the attribute.]
]
]
ref_macro[
@n[comment]
@desc[
Evaluates to nothing. Used to add comments in a Glyph document that will not be displayed in output files.
]
@aliases[--]
@params[-p[0|The contents to comment out]]
@example[=--[\/=>[#link\|This link will not be evaluated]]=]
@remarks[Macros are not expanded within comments.]
]
ref_macro[
@n[condition]
@desc[
Tests a conditional expression. For more information, see =>[#cond_macros].
]
@aliases[?]
@params[
-p[0|The condition to test]
-p[1|The contents to expand if the condition is satisfied.]
]
@remarks[
For examples see any of the following:
* %>[and]
* %>[or]
* %>[not]
* %>[match]
* %>[eq]
]
]
ref_macro[
@n[config]
@desc[Returns the value of a configuration setting.]
@aliases[$]
@example[=$[document.author]=]
@params[
-p[0|The full name of a configuration setting.]
]
]
ref_macro[
@n[config:]
@desc[Sets the value of a configuration setting.]
@aliases[$:]
@example[=$:[document.draft\|true]=]
@remarks[&[unsafe]]
@params[
-p[0|The full name of a configuration setting.]
-p[1|The new value of the configuration setting]
]
]
ref_macro[
@n[eq]
@desc[Conditional equality operator, to be used with the %>[condition].]
@example[=?[eq[$[document.draft]\|true]\|This is displayed only in draft documents.]=]
@params[&[bin_params]]
]
ref_macro[
@n[escape]
@desc[Evaluates to its value. Commonly used with the escaping delimiters code[\[\=] and code[\=\]].]
@aliases[.]
@example[=.\[=Macros are escaped here =>[#test].=\]=]
@params[-p[0|The contents to escape.]]
]
ref_macro[
@n[fragment]
@desc[Delimits a fragment of text that can be embedded using the %>[embed].]
@aliases[##]
@example[=##\[test_fragment\|This is an embeddable fragment\]=]
@params[
-p[0|The ID of the fragment.]
-p[1|The contents of the fragment.]
]
]
ref_macro[
@n[embed]
@desc[Embeds text previously-delimited using the %>[fragment].]
@aliases[<=]
@example[=<=\[test_fragment\]=]
@params[-p[0|The ID of the fragment.]]
]
def:[comp_macro|
ref_macro[
@n[{{0}}]
@desc[Returns em[true] if the first parameter is {{0}} the second one.]
@example[={{1}}\[5\|2\]=]
@params[
-p[0|The first integer to compare.]
-p[1|The second integer to compare.]
]
]
]
comp_macro[gt|greater than]
comp_macro[gte|greater than or equal to]
ref_macro[
@n[include]
@desc[
Evaluates to the contents of a text file stored in the @text/@ directory referenced by its relative path. If &[filter_by_ext], filters the contents of the file using the =>[#f_macros|filter macro] corresponding to the file extension.
]
@aliases[@]
@example[=include[frontmatter/introduction]=]
@params[-p[0|The file to include.]]
@remarks[
ul[
li[&[unsafe]]
li[@.glyph@ is assumed if no file extension is specified.]
li[
This macro can also be used to include @.rb@ ruby files within the @lib@ directory. File contents are evaluated in the context of the =>[&[rubydoc]/Glyph|Glyph] module.
]
]
]
]
ref_macro[
@n[let]
@desc[Used to bind one or more attributes via the %>[attribute]. Actually, you can use %>[attribute] inside any other macro, but it looks tidier in this way.]
@block_example[=
let[
@:[a\|2]
@:[b\|3]
section[
@title[Testing]
@[title]: @[a] * @[b] = multiply[@[a]\|@[b]] --[Outputs: Testing: 2 * 3 = 6]
]
]
=]
@params[-p[0|Any content.]]
]
ref_macro[
@n[load]
@desc[Embeds the contents of a file.]
@params[
-p[0|The file to embed, relative to the Glyph project folder.]
]
@example[=load[my_samples.rb]=]
]
comp_macro[lt|less than]
comp_macro[lte|less than or equal to]
ref_macro[
@n[match]
@desc[
Checks a string against a regular expression.
]
@params[
-p[0|The string to check.]
-p[1|The regular expression to match against the string.]
-p[2|The contents to expand if the string matches.]
]
@remarks[This macro must be used with the %>[condition].]
@example[=?[match[Hello!\|/^hell/i]\|This is always displayed]=]
]
ref_macro[
@n[macro:]
@desc[Defines a macro.]
@remarks[
ul[
li[&[unsafe]]
li[The new macro &[only_after_declaration].]
]
]
@aliases[%:]
@example[=%:[test\|"<em>test: #{value}</em>"]=]
@params[
-p[0|The name of the new macro.]
-p[1|The macro definition (Ruby code).]
]
]
ref_macro[
@n[multiply]
@desc[Multiplies two or more integers together.]
@params[Two or more integer values.]
@example[=add[3\|5\|9]=]
]
ref_macro[
@n[not]
@desc[Conditional @not@ operator, to be used with the %>[condition].]
@example[=?[not[false]\|This is always displayed.]=]
@params[-p[0|The expression to negate]]
]
ref_macro[
@n[output?]
@desc[Evaluates to true if Glyph is generating output in the specified format(s).]
@example[=?[output?[web\|web5]\|This text is printed only when generating web or web5 output.]=]
@params[
-p[0, ...|a valid output target.]
]
]
ref_macro[
@n[or]
@desc[Conditional @or@ operator, to be used with the %>[condition].]
@example[=?[or[true\|false]\|This is always displayed.]=]
@params[&[bin_params]]
]
ref_macro[
@n[define:]
@desc[Defines a new macro by rewriting (for more information, see =>[#rewriting])]
@aliases[def:]
@params[
-p[0|The name of the new macro.]
-p[0|The macro definition (Glyph code).]
]
@block_example[=
def:[factorial\|
?[
eq[{{0}}\|0]\|1\|
multiply[
{{0}} \| factorial[subtract[{{0}}\|1]]
]
]
]
factorial[5]
=]
@remarks[
ul[
li[The new macro &[only_after_declaration].]
li[&[unsafe]]
]
]
]
ref_macro[
@n[ruby]
@desc[Evaluates its value as Ruby code within the context of the =>[&[rubydoc]/Glyph|Glyph] module.]
@aliases[%]
@examples[=
%[Time.now]
%[Glyph::VERSION]
=]
@params[-p[0|The Ruby code to evaluate.]]
@remarks[&[unsafe]]
]
ref_macro[
@n[s]
@desc[Can be used to dispatch almost any instance method of the ruby =>[http://rubydoc.info/stdlib/core/1.9.2/String|String] class.]
@examples[=
s/match[This is a test string\|/test/]
s/sub[This is a test string\|/a test/\|another test]
=]
]
ref_macro[
@n[snippet]
@desc[Returns the value of a snippet.]
@aliases[&]
@example[=&[glang]=]
@params[-p[0|The ID of the snippet to retrieve.]]
]
ref_macro[
@n[snippet:]
@desc[Defines a snippet.]
@remarks[The new snippet &[only_after_declaration].]
@aliases[&:]
@example[=&:[test\|This is a test]=]
@params[
-p[0|The ID of the new snippet.]
-p[1|The contents of the new snippet.]
]
]
ref_macro[
@n[subtract]
@desc[Subtracts two or more integers together.]
@params[Two or more integer values.]
@example[=add[10\|5\|2]=]
]
ref_macro[
@n[xml]
@desc[When used composed with another macro, it can be used to render arbitrary raw XML tags.]
@example[=xml/img[@src[test.png]@alt[A Test image]]=]
]
ref_macro[
@n[while]
@desc[Keeps evaluating the second parameter while a condition is satisfied.]
@block_example[=
let[
@count[5]
@text[-]
while[gt[@[count]\|0]\|
@:[text\|s/concat[@[text]\|@[count]-]]
@:[count\|subtract[@[count]\|1]]
]
@[text] --[Outputs: -5-4-3-2-1-]
]
=]
@params[
-p[0|The condition to check.]
-p[1|The code to evaluate while the condition is satisfied.]
]
]