aboutsummaryrefslogtreecommitdiff
path: root/brep/page
blob: 0d0887f9b24acea4e22454116261b01f03c0218e (plain)
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
// file      : brep/page -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BREP_PAGE
#define BREP_PAGE

#include <string>
#include <cstddef>    // size_t

#include <xml/forward>

#include <brep/package>

namespace brep
{
  // Page common building blocks.
  //

  // Generates CSS link elements.
  //
  class CSS_LINKS
  {
  public:
    CSS_LINKS (const path& p, const dir_path& r): path_ (p), root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const path& path_;
    const dir_path& root_;
  };

  // Generates page header element.
  //
  class DIV_HEADER
  {
  public:
    DIV_HEADER (const dir_path& r): root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const dir_path& root_;
  };

  // Generates package search form element.
  //
  class FORM_SEARCH
  {
  public:
    FORM_SEARCH (const std::string& q): query_ (q) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& query_;
  };

  // Generates 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 (std::size_t c, const char* s, const char* p)
        : count_ (c), singular_ (s), plural_ (p) {}

    void
    operator() (xml::serializer& s) const;

  private:
    std::size_t count_;
    const char* singular_;
    const char* plural_;
  };

  // Generates package name element.
  //
  class TR_NAME
  {
  public:
    TR_NAME (const std::string& n, const std::string& q, const dir_path& r)
        : name_ (n), query_param_ (q), root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& name_;
    const std::string& query_param_;
    const dir_path& root_;
  };

  // Generates package version element.
  //
  class TR_VERSION
  {
  public:
    // Display the version as a link to the package version details page.
    //
    TR_VERSION (const std::string& p,
                const std::string& v,
                const dir_path& r)
        : package_ (&p), version_ (v), root_ (&r) {}

    // Display the version as a regular text.
    //
    TR_VERSION (const std::string& v)
        : package_ (nullptr), version_ (v), root_ (nullptr) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string* package_;
    const std::string& version_;
    const dir_path* root_;
  };

  // Generates package summary element.
  //
  class TR_SUMMARY
  {
  public:
    TR_SUMMARY (const std::string& s): summary_ (s) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& summary_;
  };

  // Generates package license alternatives element.
  //
  class TR_LICENSE
  {
  public:
    TR_LICENSE (const license_alternatives& l): licenses_ (l) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const license_alternatives& licenses_;
  };

  // Generates 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& s) const;

  private:
    const license_alternatives& licenses_;
  };

  // Generates package tags element.
  //
  class TR_TAGS
  {
  public:
    TR_TAGS (const strings& ts, const dir_path& r): tags_ (ts), root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const strings& tags_;
    const dir_path& root_;
  };

  // Generates package dependencies element.
  //
  class TR_DEPENDS
  {
  public:
    TR_DEPENDS (const dependencies& d, const dir_path& r)
        : dependencies_ (d), root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const dependencies& dependencies_;
    const dir_path& root_;
  };

  // Generates package requirements element.
  //
  class TR_REQUIRES
  {
  public:
    TR_REQUIRES (const requirements& r): requirements_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const requirements& requirements_;
  };

  // Generates url element.
  //
  class TR_URL
  {
  public:
    TR_URL (const url& u, const char* l = "url"): url_ (u), label_ (l) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const url& url_;
    const char* label_;
  };

  // Generates email element.
  //
  class TR_EMAIL
  {
  public:
    TR_EMAIL (const email& e, const char* l = "email")
        : email_ (e), label_ (l) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const email& email_;
    const char* label_;
  };

  // Generates package version priority element.
  //
  class TR_PRIORITY
  {
  public:
    TR_PRIORITY (const priority& p): priority_ (p) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const priority& priority_;
  };

  // Generates package location element.
  //
  class TR_LOCATION
  {
  public:
    TR_LOCATION (const std::string& n, const dir_path& r)
        : name_ (n), root_ (r) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& name_;
    const dir_path& root_;
  };

  // Generates package download URL element.
  //
  class TR_DOWNLOAD
  {
  public:
    TR_DOWNLOAD (const std::string& u): url_ (u) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& url_;
  };

  // Generates comment element.
  //
  class SPAN_COMMENT
  {
  public:
    SPAN_COMMENT (const std::string& c): comment_ (c) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& comment_;
  };

  // Generates package description element.
  //
  class P_DESCRIPTION
  {
  public:
    // Genereate full description.
    //
    P_DESCRIPTION (const std::string& d, bool u = true)
        : description_ (d), length_ (d.size ()), url_ (nullptr), unique_ (u) {}

    // Genereate brief description.
    //
    P_DESCRIPTION (const std::string& d, size_t l, const std::string& u)
        : description_ (d), length_ (l), url_ (&u), unique_ (false) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& description_;
    std::size_t length_;
    const std::string* url_; // Full page url.
    bool unique_;
  };

  // Generates package description element.
  //
  class PRE_CHANGES
  {
  public:
    // Genereate full changes info.
    //
    PRE_CHANGES (const std::string& c)
        : changes_ (c), length_ (c.size ()), url_ (nullptr) {}

    // Genereate brief changes info.
    //
    PRE_CHANGES (const std::string& c, size_t l, const std::string& u)
        : changes_ (c), length_ (l), url_ (&u) {}

    void
    operator() (xml::serializer& s) const;

  private:
    const std::string& changes_;
    std::size_t length_;
    const std::string* url_; // Full page url.
  };

  // Generates paging element.
  //
  class DIV_PAGER
  {
  public:
    DIV_PAGER (std::size_t current_page,
               std::size_t item_count,
               std::size_t item_per_page,
               std::size_t page_number_count,
               const std::string& url);

    void
    operator() (xml::serializer& s) const;

  private:
    std::size_t current_page_;
    std::size_t item_count_;
    std::size_t item_per_page_;
    std::size_t page_number_count_;
    const std::string& url_;
  };

  // Convert the argument to a string representing the valid HTML 5 'id'
  // attribute value.
  //
  std::string
  id_attribute (const std::string& v);
}

#endif // BREP_PAGE