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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
// file : mod/page.hxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#ifndef MOD_PAGE_HXX
#define MOD_PAGE_HXX
#include <libstudxml/forward.hxx>
#include <libbbot/manifest.hxx>
#include <web/xhtml-fragment.hxx>
#include <libbrep/types.hxx>
#include <libbrep/utility.hxx>
#include <libbrep/build.hxx>
#include <libbrep/package.hxx>
#include <mod/diagnostics.hxx>
#include <mod/options-types.hxx> // page_menu
namespace brep
{
// Page common building blocks.
//
// Generate CSS link elements.
//
class CSS_LINKS
{
public:
CSS_LINKS (const path& p, const dir_path& r): path_ (p), root_ (r) {}
void
operator() (xml::serializer&) const;
private:
const path& path_;
const dir_path& root_;
};
// Generate page header element.
//
class DIV_HEADER
{
public:
DIV_HEADER (const web::xhtml::fragment& logo,
const vector<page_menu>& menu,
const dir_path& root,
const string& tenant):
logo_ (logo), menu_ (menu), root_ (root), tenant_ (tenant) {}
void
operator() (xml::serializer&) const;
private:
const web::xhtml::fragment& logo_;
const vector<page_menu>& menu_;
const dir_path& root_;
const string& tenant_;
};
// Generate package search form element with the specified query input
// element name.
//
class FORM_SEARCH
{
public:
FORM_SEARCH (const string& q, const string& n, bool a = true)
: query_ (q), name_ (n), autofocus_ (a)
{
}
void
operator() (xml::serializer&) const;
private:
const string& query_;
const string& name_;
bool autofocus_;
};
// Generate counter element.
//
// It could be redunant to distinguish between singular and plural word forms
// if it wouldn't be so cheap in English, and phrase '1 Packages' wouldn't
// look that ugly.
//
class DIV_COUNTER
{
public:
DIV_COUNTER (size_t c, const char* s, const char* p)
: count_ (c), singular_ (s), plural_ (p) {}
void
operator() (xml::serializer&) const;
private:
size_t count_;
const char* singular_;
const char* plural_;
};
// Generate table row element, that has the 'label: value' layout.
//
class TR_VALUE
{
public:
TR_VALUE (const string& l, const string& v)
: label_ (l), value_ (v) {}
void
operator() (xml::serializer&) const;
private:
const string& label_;
const string& value_;
};
// Generate table row element, that has the 'label: <input type="text"/>'
// layout.
//
class TR_INPUT
{
public:
TR_INPUT (const string& l,
const string& n,
const string& v,
const string& p = string (),
bool a = false)
: label_ (l), name_ (n), value_ (v), placeholder_ (p), autofocus_ (a)
{
}
void
operator() (xml::serializer&) const;
private:
const string& label_;
const string& name_;
const string& value_;
const string& placeholder_;
bool autofocus_;
};
// Generate table row element, that has the 'label: <select></select>'
// layout. Option elements are represented as a list of value/inner-text
// pairs.
//
class TR_SELECT
{
public:
TR_SELECT (const string& l,
const string& n,
const string& v,
const vector<pair<string, string>>& o)
: label_ (l), name_ (n), value_ (v), options_ (o) {}
void
operator() (xml::serializer&) const;
private:
const string& label_;
const string& name_;
const string& value_;
const vector<pair<string, string>>& options_;
};
// Generate tenant id element.
//
// Displays a link to the service page for the specified tenant.
//
class TR_TENANT
{
public:
TR_TENANT (const string& n,
const string& s,
const dir_path& r,
const string& t)
: name_ (n), service_ (s), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const string& name_;
const string& service_;
const dir_path& root_;
const string& tenant_;
};
// Generate package name element with an optional search criteria. The
// search string should be url-encoded, if specified.
//
class TR_NAME
{
public:
TR_NAME (const package_name& n,
const string& q,
const dir_path& r,
const string& t)
: name_ (n), query_ (q), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const package_name& name_;
const string& query_;
const dir_path& root_;
const string& tenant_;
};
// Generate package version element.
//
class TR_VERSION
{
public:
// Display the version as a link to the package version details page.
//
TR_VERSION (const package_name& p,
const version& v,
const dir_path& r,
const string& t)
: package_ (&p),
version_ (v.string ()),
stub_ (v.compare (wildcard_version, true) == 0),
root_ (&r),
tenant_ (&t)
{
}
// Display the version as a regular text.
//
TR_VERSION (const version& v)
: package_ (nullptr),
version_ (v.string ()),
stub_ (v.compare (wildcard_version, true) == 0),
root_ (nullptr),
tenant_ (nullptr)
{
}
void
operator() (xml::serializer&) const;
private:
const package_name* package_;
string version_;
bool stub_;
const dir_path* root_;
const string* tenant_;
};
// Generate package project name element.
//
// Displays a link to the package search page with the project name
// specified as a keyword.
//
class TR_PROJECT
{
public:
TR_PROJECT (const package_name& p, const dir_path& r, const string& t)
: project_ (p), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const package_name& project_;
const dir_path& root_;
const string& tenant_;
};
// Generate package summary element.
//
class TR_SUMMARY
{
public:
TR_SUMMARY (const string& s): summary_ (s) {}
void
operator() (xml::serializer&) const;
private:
const string& summary_;
};
// Generate package license alternatives element.
//
class TR_LICENSE
{
public:
TR_LICENSE (const license_alternatives& l): licenses_ (l) {}
void
operator() (xml::serializer&) const;
private:
const license_alternatives& licenses_;
};
// Generate package license alternatives elements. Differs from TR_LICENSE
// by producing multiple rows instead of a single one.
//
class TR_LICENSES
{
public:
TR_LICENSES (const license_alternatives& l): licenses_ (l) {}
void
operator() (xml::serializer&) const;
private:
const license_alternatives& licenses_;
};
// Generate package tags element.
//
class TR_TAGS
{
public:
// Display the tag link list.
//
TR_TAGS (const strings& ts, const dir_path& r, const string& t)
: project_ (nullptr), tags_ (ts), root_ (r), tenant_ (t) {}
// As above but prepend the list with a tag link produced from the project
// name, if it differs from other tags.
//
TR_TAGS (const package_name& pr,
const strings& ts,
const dir_path& r,
const string& t)
: project_ (&pr), tags_ (ts), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const package_name* project_;
const strings& tags_;
const dir_path& root_;
const string& tenant_;
};
// Generate package dependencies element.
//
class TR_DEPENDS
{
public:
TR_DEPENDS (const dependencies& d, const dir_path& r, const string& t)
: dependencies_ (d), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const dependencies& dependencies_;
const dir_path& root_;
const string& tenant_;
};
// Generate package requirements element.
//
class TR_REQUIRES
{
public:
TR_REQUIRES (const requirements& r): requirements_ (r) {}
void
operator() (xml::serializer&) const;
private:
const requirements& requirements_;
};
// Generate url element.
//
class TR_URL
{
public:
TR_URL (const url& u, const char* l = "url"): url_ (u), label_ (l) {}
void
operator() (xml::serializer&) const;
private:
const url& url_;
const char* label_;
};
// Generate email element.
//
class TR_EMAIL
{
public:
TR_EMAIL (const email& e, const char* l = "email")
: email_ (e), label_ (l) {}
void
operator() (xml::serializer&) const;
private:
const email& email_;
const char* label_;
};
// Generate package version priority element.
//
class TR_PRIORITY
{
public:
TR_PRIORITY (const priority& p): priority_ (p) {}
void
operator() (xml::serializer&) const;
private:
const priority& priority_;
};
// Generate repository name element.
//
class TR_REPOSITORY
{
public:
TR_REPOSITORY (const string& n, const dir_path& r, const string& t)
: name_ (n), root_ (r), tenant_ (t) {}
void
operator() (xml::serializer&) const;
private:
const string& name_;
const dir_path& root_;
const string& tenant_;
};
// Generate repository location element.
//
class TR_LOCATION
{
public:
TR_LOCATION (const repository_location& l): location_ (l) {}
void
operator() (xml::serializer&) const;
private:
const repository_location& location_;
};
// Generate package download URL element.
//
class TR_DOWNLOAD
{
public:
TR_DOWNLOAD (const string& u): url_ (u) {}
void
operator() (xml::serializer&) const;
private:
const string& url_;
};
// Generate sha256sum element.
//
class TR_SHA256SUM
{
public:
TR_SHA256SUM (const string& s): sha256sum_ (s) {}
void
operator() (xml::serializer&) const;
private:
const string& sha256sum_;
};
// Generate build results element.
//
class TR_BUILD_RESULT
{
public:
TR_BUILD_RESULT (const build& b, const string& h, const dir_path& r):
build_ (b), host_ (h), root_ (r) {}
void
operator() (xml::serializer&) const;
private:
const build& build_;
const string& host_;
const dir_path& root_;
};
// Generate comment element.
//
class SPAN_COMMENT
{
public:
SPAN_COMMENT (const string& c): comment_ (c) {}
void
operator() (xml::serializer&) const;
private:
const string& comment_;
};
// Generate package build result status element.
//
class SPAN_BUILD_RESULT_STATUS
{
public:
SPAN_BUILD_RESULT_STATUS (const bbot::result_status& s): status_ (s) {}
void
operator() (xml::serializer&) const;
private:
const bbot::result_status& status_;
};
// Generate paragraph elements converting a plain text into XHTML5 applying
// some heuristics (see implementation for details). Truncate the text if
// requested.
//
// Note that there is no way to specify that some text fragment must stay
// pre-formatted. Thus, don't use this type for text that can contain such
// kind of fragments and consider using PRE_TEXT instead.
//
class P_TEXT
{
public:
// Generate full text elements.
//
P_TEXT (const string& t, const string& id = "")
: text_ (t), length_ (t.size ()), url_ (nullptr), id_ (id) {}
// Generate brief text elements.
//
P_TEXT (const string& t, size_t l, const string& u, const string& id = "")
: text_ (t), length_ (l), url_ (&u), id_ (id) {}
void
operator() (xml::serializer&) const;
private:
const string& text_;
size_t length_;
const string* url_; // Full page url.
string id_;
};
// Generate pre-formatted text element. Truncate the text if requested.
//
class PRE_TEXT
{
public:
// Generate a full text element.
//
PRE_TEXT (const string& t, const string& id = "")
: text_ (t), length_ (t.size ()), url_ (nullptr), id_ (id) {}
// Generate a brief text element.
//
PRE_TEXT (const string& t,
size_t l,
const string& u,
const string& id = "")
: text_ (t), length_ (l), url_ (&u), id_ (id) {}
void
operator() (xml::serializer&) const;
private:
const string& text_;
size_t length_;
const string* url_; // Full page url.
string id_;
};
// Generate a typed text element truncating it if requested. On the
// underlying parsing/rendering error, log it and generate the error
// description element instead. Note that such an error indicates an issue
// with the implementation, rather than with the specified text.
//
// Optionally strip the heuristically detected document "title". Currently,
// this only applies to Markdown where a leading level-one heading is
// assumed to be the title.
//
class DIV_TEXT
{
public:
// Generate a full text element.
//
DIV_TEXT (const string& t,
text_type tp,
bool st,
const string& id,
const string& what,
const basic_mark& diag)
: text_ (t),
type_ (tp),
strip_title_ (st),
length_ (t.size ()),
url_ (nullptr),
id_ (id),
what_ (what),
diag_ (diag)
{
}
// Generate a brief text element.
//
DIV_TEXT (const string& t,
text_type tp,
bool st,
size_t l,
const string& u,
const string& id,
const string& what,
const basic_mark& diag)
: text_ (t),
type_ (tp),
strip_title_ (st),
length_ (l),
url_ (&u),
id_ (id),
what_ (what),
diag_ (diag)
{
}
void
operator() (xml::serializer&) const;
private:
const string& text_;
text_type type_;
bool strip_title_;
size_t length_;
const string* url_; // Full page url.
string id_;
const string& what_;
const basic_mark& diag_;
};
// Generate paging element.
//
class DIV_PAGER
{
public:
DIV_PAGER (size_t current_page,
size_t item_count,
size_t item_per_page,
size_t page_number_count,
const string& url);
void
operator() (xml::serializer&) const;
private:
size_t current_page_;
size_t item_count_;
size_t item_per_page_;
size_t page_number_count_;
const string& url_;
};
// Convert the argument to a string representing the valid HTML 5 'id'
// attribute value.
//
string
html_id (const string&);
}
#endif // MOD_PAGE_HXX
|