-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.addon.hierarchy_navigation_links.fs
452 lines (396 loc) · 13.5 KB
/
fendo.addon.hierarchy_navigation_links.fs
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
.( fendo.addon.hierarchy_navigation_links.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file is the hierarchy navigation links addon.
\ Last modified 20211023T1637+0200.
\ See change log at the end of the file.
\ Copyright (C) 2017,2018,2020,2021 Marcos Cruz (programandala.net)
\ Fendo is free software; you can redistribute it and/or modify it
\ under the terms of the GNU General Public License as published by
\ the Free Software Foundation; either version 2 of the License, or
\ (at your option) any later version.
\ Fendo is distributed in the hope that it will be useful, but WITHOUT
\ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
\ License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program; if not, see <http://gnu.org/licenses>.
\ Fendo is written in Forth (http://forth-standard.org)
\ with Gforth (http://gnu.org/software/gforth).
\ ==============================================================
require fendo.addon.hierarchy_meta_links.fs
defer first$ ( -- ca len )
defer previous$ ( -- ca len )
defer next$ ( -- ca len )
defer up$ ( -- ca len )
defer last$ ( -- ca len )
\ doc{
\
\ first$ ( -- ca len )
\
\ A word defined by ``defer``. It must be configured by the
\ application in order to return a string _ca len_ containing
\ "First" in the language of the current page.
\
\ Usage example in a monolingual, English-only website:
\ ----
\ :noname s" First" ; is first$
\ ----
\ Usage example in a multilingual website:
\ ----
\ s" Primera" \ Spanish
\ s" Unua" \ Esperanto
\ s" First" \ English
\ noname-l10n-string is first$
\ ----
\ See also: `previous$`, `next$`, `up$`, `last$`, `noname-l10n-string`.
\
\ }doc
\ doc{
\
\ previous$ ( -- ca len )
\
\ A word defined by ``defer``. It must be configured by the
\ application in order to return a string _ca len_ containing
\ "Previous" in the language of the current page.
\
\ See `first$` for a usage example.
\
\ See also: `next$`, `up$`, `last$`.
\
\ }doc
\ doc{
\
\ next$ ( -- ca len )
\
\ A word defined by ``defer``. It must be configured by the
\ application in order to return a string _ca len_ containing "Next"
\ in the language of the current page.
\
\ See `first$` for a usage example and related words.
\
\ See also: `previous$`, `up$`, `last$`.
\
\ }doc
\ doc{
\
\ up$ ( -- ca len )
\
\ A word defined by ``defer``. It must be configured by the
\ application in order to return a string _ca len_ containing
\ "Up" in the language of the current page.
\
\ See `first$` for a usage example and related words.
\
\ See also: `previous$`, `next$`, `last$`.
\
\ }doc
\ doc{
\
\ last$ ( -- ca len )
\
\ A word defined by ``defer``. It must be configured by the
\ application in order to return a string _ca len_ containing
\ "Last" in the language of the current page.
\
\ See `first$` for a usage example and related words.
\
\ See also: `previous$`, `next$`, `up$`.
\
\ }doc
: hierarchy_navigation_link ( ca1 len1 ca2 len2 -- )
2swap s" <span class='br'>" 2swap s+
s" :</span> " s+
2over pid$>pid# title s+
link ;
\ XXX TODO deactivate the <br/> for text browsers
\
\ NOTE: a trailing space is needed after `</span>` because the title
\ could start with markups.
\ doc{
\
\ hierarchy_navigation_link ( ca1 len1 ca2 len2 -- )
\
\ Create a hierarchy navigation link with link text _ca1 len1_ and
\ target page ID _ca2 len2_.
\
\ ``hierarchy_navigation_link`` is a factor of
\ `?hierarchy_navigation_link`.
\
\ See `hierarchy_previous_navigation_link?` for a usage example.
\
\ See also: `hierarchy_first_navigation_link?`,
\ `hierarchy_previous_navigation_link?`,
\ `hierarchy_next_navigation_link?`,
\ `hierarchy_upper_navigation_link?`.
\
\ }doc
\ `hierarchy_last_navigation_link?`, \ XXX TODO --
: ?hierarchy_navigation_link ( ca1 len1 ca2 len2 -- )
proper_hierarchical_link?
if hierarchy_navigation_link else 2drop 2drop then ;
\ doc{
\
\ ?hierarchy_navigation_link ( ca1 len1 ca2 len2 -- )
\
\ String _ca1 len1_ is the link text of a hierarchy navigation link.
\ String _ca2 len2_ is the target page ID of the link. If _ca2
\ len2_ is a proper hierarchical link, create the link. Otherwise
\ discard the parameters and do nothing.
\
\ See also: `proper_hierarchical_link?`, `hierarchy_navigation_link`.
\
\ }doc
: hierarchy_first_navigation_link ( -- )
first$ current_page first_page ?hierarchy_navigation_link ;
\ doc{
\
\ hierarchy_first_navigation_link ( -- )
\
\ Prepare the the link text and the target page ID of the hierarchy
\ "first" navigation link, and execute `?hierarchy_navigation_link`.
\
\ See `hierarchy_previous_navigation_link` for a usage example.
\
\ See also: `hierarchy_first_navigation_link?`,
\ `first$`, `current_page`, `first_page`,
\ `hierarchy_previous_navigation_link`,
\ `hierarchy_next_navigation_link`,
\ `hierarchy_last_navigation_link`,
\ `hierarchy_upper_navigation_link`.
\
\ }doc
: hierarchy_first_navigation_link? ( -- ca1 len1 ca2 len2 f )
first$ current_page ?first_page proper_hierarchical_link? ;
\ doc{
\
\ hierarchy_first_navigation_link? ( -- ca1 len1 ca2 len2 f )
\
\ If the current page has a first page in the hierarchy, _f_ is
\ _true_, _ca1 len1_ is the link text returned by `first$` and _ca2
\ len2_ is the target page ID, as needed by
\ `hierarchy_navigation_link`. Otherwise _f_ is _false_, and _ca1
\ len1_ and _ca2 len2_ are unimportant.
\
\ See also: `hierarchy_first_navigation_link`,
\ `hierarchy_previous_navigation_link?`,
\ `hierarchy_next_navigation_link?`,
\ `hierarchy_upper_navigation_link?`.
\
\ }doc
\ `hierarchy_last_navigation_link?`, \ XXX TODO --
: hierarchy_upper_navigation_link ( -- )
up$ current_page ?upper_page ?hierarchy_navigation_link ;
\ doc{
\
\ hierarchy_upper_navigation_link ( -- )
\
\ Prepare the the link text and the target page ID of the hierarchy
\ "upper" navigation link, and execute `?hierarchy_navigation_link`.
\
\ See `hierarchy_previous_navigation_link` for a usage example.
\
\ See also: `hierarchy_upper_navigation_link?`,
\ `up$`, `current_page`, `?upper_page`,
\ `hierarchy_first_navigation_link`,
\ `hierarchy_previous_navigation_link`,
\ `hierarchy_next_navigation_link`,
\ `hierarchy_last_navigation_link`.
\
\ }doc
: hierarchy_upper_navigation_link? ( -- ca1 len1 ca2 len2 f )
up$ current_page ?upper_page proper_hierarchical_link? ;
\ doc{
\
\ hierarchy_upper_navigation_link? ( -- ca1 len1 ca2 len2 f )
\
\ If the current page has an upper page in the hierarchy, _f_ is
\ _true_, _ca1 len1_ is the link text returned by `up$` and _ca2
\ len2_ is the target page ID, as needed by
\ `hierarchy_navigation_link`. Otherwise _f_ is _false_, and _ca1
\ len1_ and _ca2 len2_ are unimportant.
\
\ See also: `hierarchy_upper_navigation_link`,
\ `hierarchy_first_navigation_link?`,
\ `hierarchy_previous_navigation_link?`,
\ `hierarchy_next_navigation_link?`,
\
\ }doc
\ `hierarchy_last_navigation_link?`. \ XXX TODO --
: hierarchy_previous_navigation_link ( -- )
previous$ current_page ?previous_page ?hierarchy_navigation_link ;
\ doc{
\
\ hierarchy_previous_navigation_link ( -- )
\
\ Prepare the link text and the target page ID of the hierarchy
\ "previous" navigation link, and execute `?hierarchy_navigation_link`.
\
\ Usage example in the code:
\ ----
\ : (hierarchy_navigation_links) ( -- )
\ s" hierarchy" class=! [<ul>]
\ [<li>] hierarchy_previous_navigation_link [</li>]
\ [<li>] hierarchy_upper_navigation_link [</li>]
\ [<li>] hierarchy_next_navigation_link [</li>]
\ [</ul>] ;
\
\ : hierarchy_navigation_links ( -- )
\ current_page pid#>hierarchy if (hierarchy_navigation_links) then ;
\ ----
\ Usage example in the HTML template:
\ ----
\ <footer>
\ <nav> <[ hierarchy_navigation_links ]> </nav>
\ </footer>
\ ----
\ See also: `hierarchy_previous_navigation_link?`,
\ `previous$`, `current_page`, `?previous_page`,
\ `hierarchy_first_navigation_link`,
\ `hierarchy_next_navigation_link`,
\ `hierarchy_last_navigation_link`,
\ `hierarchy_upper_navigation_link`.
\
\ }doc
: hierarchy_previous_navigation_link? ( -- ca1 len1 ca2 len2 f )
previous$ current_page ?previous_page proper_hierarchical_link? ;
\ doc{
\
\ hierarchy_previous_navigation_link? ( -- ca1 len1 ca2 len2 f )
\
\ If the current page has a previous page in the hierarchy, _f_ is
\ _true_, _ca1 len1_ is the link text returned by `previous$` and
\ _ca2 len2_ is the target page ID, as needed by
\ `hierarchy_navigation_link`. Otherwise _f_ is _false_, and _ca1
\ len1_ and _ca2 len2_ are unimportant.
\
\ Usage example in the code:
\ ----
\ : (hierarchy_navigation_links) ( -- )
\ s" hierarchy" class=! [<ul>]
\ hierarchy_previous_navigation_link?
\ if [<li>] hierarchy_navigation_link [</li>] then
\ hierarchy_upper_navigation_link?
\ if [<li>] hierarchy_navigation_link [</li>] then
\ hierarchy_next_navigation_link?
\ if [<li>] hierarchy_navigation_link [</li>] then
\ [</ul>] ;
\
\ : hierarchy_navigation_links ( -- )
\ current_page pid#>hierarchy if (hierarchy_navigation_links) then ;
\ ----
\ Usage example in the HTML template:
\ ----
\ <footer>
\ <nav> <[ hierarchy_navigation_links ]> </nav>
\ </footer>
\ ----
\ See also: `hierarchy_previous_navigation_link`,
\ `hierarchy_first_navigation_link?`,
\ `hierarchy_next_navigation_link?`,
\ `hierarchy_upper_navigation_link?`.
\
\ }doc
\ `hierarchy_last_navigation_link?`, \ XXX TODO --
: hierarchy_next_navigation_link ( -- )
next$ current_page ?next_page ?hierarchy_navigation_link ;
\ doc{
\
\ hierarchy_next_navigation_link ( -- )
\
\ Prepare the the link text and the target page ID of the hierarchy
\ "next" navigation link, and execute `?hierarchy_navigation_link`.
\
\ See `hierarchy_previous_navigation_link` for a usage example.
\
\ See also: `hierarchy_next_navigation_link?`,
\ `next$`, `current_page`, `?next_page`,
\ `hierarchy_first_navigation_link`,
\ `hierarchy_previous_navigation_link`,
\ `hierarchy_last_navigation_link`,
\ `hierarchy_upper_navigation_link`.
\
\ }doc
: hierarchy_next_navigation_link? ( -- ca1 len1 ca2 len2 f )
next$ current_page ?next_page proper_hierarchical_link? ;
\ doc{
\
\ hierarchy_next_navigation_link? ( -- ca1 len1 ca2 len2 f )
\
\ If the current page has a next page in the hierarchy, _f_ is
\ _true_, _ca1 len1_ is the link text returned by `next$` and _ca2
\ len2_ is the target page ID, as needed by
\ `hierarchy_navigation_link`. Otherwise _f_ is _false_, and _ca1
\ len1_ and _ca2 len2_ are unimportant.
\
\ See also: `hierarchy_next_navigation_link`,
\ `hierarchy_first_navigation_link?`,
\ `hierarchy_previous_navigation_link?`,
\ `hierarchy_upper_navigation_link?`.
\
\ }doc
\ `hierarchy_last_navigation_link?`, \ XXX TODO --
: hierarchy_last_navigation_link ( -- )
last$ current_page last_page ?hierarchy_navigation_link ;
\ doc{
\
\ hierarchy_last_navigation_link ( -- )
\
\ Prepare the the link text and the target page ID of the hierarchy
\ "last" navigation link, and execute `?hierarchy_navigation_link`.
\
\ See `hierarchy_previous_navigation_link` for a usage example.
\
\ See also:
\ `last$`, `current_page`, `last_page`,
\ `hierarchy_first_navigation_link`,
\ `hierarchy_previous_navigation_link`,
\ `hierarchy_next_navigation_link`,
\ `hierarchy_upper_navigation_link`.
\
\ }doc
\ See also: `hierarchy_last_navigation_link?`, \ XXX TODO --
\ XXX TODO -- 2018-12-24: `?last_page` is not written yet.
\ : hierarchy_last_navigation_link? ( -- ca1 len1 ca2 len2 f )
\ last$ current_page ?last_page proper_hierarchical_link? ;
\
\ hierarchy_last_navigation_link? ( -- ca1 len1 ca2 len2 f )
\
\ If the current page has a last page in the hierarchy, _f_ is
\ _true_, _ca1 len1_ is the link text returned by `last$` and _ca2
\ len2_ is the target page ID, as needed by
\ `hierarchy_navigation_link`. Otherwise _f_ is _false_, and _ca1
\ len1_ and _ca2 len2_ are unimportant.
\
\ See also: `hierarchy_last_navigation_link`,
\ `hierarchy_first_navigation_link?`,
\ `hierarchy_previous_navigation_link?`,
\ `hierarchy_next_navigation_link?`,
\ `hierarchy_upper_navigation_link?`.
\
.( fendo.addon.hierarchy_navigation_links.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2017-06-25: Start. Moved from Fendo-programandala, in order to share
\ it with Fendo-VEB.
\
\ 2018-09-28: Replace `previous_page` with `?previous_page`. Replace
\ `next_page` with `?next_page`. Replace `upper_page` with
\ `?upper_page`.
\
\ 2018-12-08: Update notation of Forth words in comments and strings.
\
\ 2018-12-20: Improve documentation. Remove the list item markups from
\ `hierarchy_navigation_link`; create only the link.
\
\ 2018-12-23: Rename `hierarchy_navigation_link` to
\ `?hierarchy_navigation_link`; rename `(hierarchy_navigation_link)`
\ to `hierarchy_navigation_link`.
\
\ 2018-12-24: Finish improving and documenting the hierarchy
\ navigation links.
\
\ 2021-06-23: Fix typo in documentation.
\
\ 2021-10-23: Replace "See:" with "See also:" in the documentation.
\ vim: filetype=gforth