diff options
Diffstat (limited to 'mod')
-rw-r--r-- | mod/mod-package-details.cxx | 15 | ||||
-rw-r--r-- | mod/mod-package-version-details.cxx | 31 | ||||
-rw-r--r-- | mod/mod-repository-details.cxx | 2 | ||||
-rw-r--r-- | mod/page.cxx | 41 | ||||
-rw-r--r-- | mod/page.hxx | 46 |
5 files changed, 83 insertions, 52 deletions
diff --git a/mod/mod-package-details.cxx b/mod/mod-package-details.cxx index 68e6530..df69614 100644 --- a/mod/mod-package-details.cxx +++ b/mod/mod-package-details.cxx @@ -183,12 +183,17 @@ handle (request& rq, response& rs) // s << H2 << pkg->summary << ~H2; - static const string id ("description"); - if (const auto& d = pkg->description) + if (const optional<string>& d = pkg->description) + { + const string id ("description"); + s << (full - ? P_DESCRIPTION (*d, id) - : P_DESCRIPTION (*d, options_->package_description (), - url (!full, squery, page, id))); + ? PRE_TEXT (*d, id) + : PRE_TEXT (*d, + options_->package_description (), + url (!full, squery, page, id), + id)); + } s << TABLE(CLASS="proplist", ID="package") << TBODY diff --git a/mod/mod-package-version-details.cxx b/mod/mod-package-version-details.cxx index bd06d76..b548b32 100644 --- a/mod/mod-package-version-details.cxx +++ b/mod/mod-package-version-details.cxx @@ -178,12 +178,17 @@ handle (request& rq, response& rs) s << H2 << pkg->summary << ~H2; - static const string id ("description"); - if (const auto& d = pkg->description) + if (const optional<string>& d = pkg->description) + { + const string id ("description"); + s << (full - ? P_DESCRIPTION (*d, id) - : P_DESCRIPTION (*d, options_->package_description (), - url (!full, id))); + ? PRE_TEXT (*d, id) + : PRE_TEXT (*d, + options_->package_description (), + url (!full, id), + id)); + } const repository_location& rl (pkg->internal_repository.load ()->location); @@ -483,14 +488,20 @@ handle (request& rq, response& rs) s << ~DIV; } - const auto& ch (pkg->changes); + const string& ch (pkg->changes); + if (!ch.empty ()) + { + const string id ("changes"); + s << H3 << "Changes" << ~H3 << (full - ? PRE_CHANGES (ch) - : PRE_CHANGES (ch, - options_->package_changes (), - url (!full, "changes"))); + ? PRE_TEXT (ch, id) + : PRE_TEXT (ch, + options_->package_changes (), + url (!full, "changes"), + id)); + } s << ~DIV << ~BODY diff --git a/mod/mod-repository-details.cxx b/mod/mod-repository-details.cxx index 6d3b8c1..d68a16e 100644 --- a/mod/mod-repository-details.cxx +++ b/mod/mod-repository-details.cxx @@ -130,7 +130,7 @@ handle (request& rq, response& rs) << ~P; if (r.description) - s << P_DESCRIPTION (*r.description); + s << P_TEXT (*r.description); if (r.certificate) { diff --git a/mod/page.cxx b/mod/page.cxx index 1b2faae..eab28c6 100644 --- a/mod/page.cxx +++ b/mod/page.cxx @@ -746,23 +746,23 @@ namespace brep s << SPAN(CLASS=to_string (status_)) << status_ << ~SPAN; } - // P_DESCRIPTION + // P_TEXT // - void P_DESCRIPTION:: + void P_TEXT:: operator() (serializer& s) const { - if (description_.empty ()) + if (text_.empty ()) return; - auto n (description_.find_first_of (" \t\n", length_)); - bool full (n == string::npos); // Description length is below the limit. + size_t n (text_.find_first_of (" \t\n", length_)); + bool full (n == string::npos); // Text length is below the limit. - // Truncate description if length exceed the limit. + // Truncate the text if length exceeds the limit. // - const string& d (full ? description_ : string (description_, 0, n)); + const string& t (full ? text_ : string (text_, 0, n)); - // Format the description into paragraphs, recognizing a blank line as - // paragraph separator, and replacing single newlines with a space. + // Format the text into paragraphs, recognizing a blank line as paragraph + // separator, and replacing single newlines with a space. // s << P; @@ -770,7 +770,7 @@ namespace brep s << ID(id_); bool nl (false); // The previous character is '\n'. - for (const auto& c: d) + for (const char& c: t) { if (c == '\n') { @@ -803,21 +803,26 @@ namespace brep s << ~P; } - // PRE_CHANGES + // PRE_TEXT // - void PRE_CHANGES:: + void PRE_TEXT:: operator() (serializer& s) const { - if (changes_.empty ()) + if (text_.empty ()) return; - auto n (changes_.find_first_of (" \t\n", length_)); - bool full (n == string::npos); // Changes length is below the limit. + size_t n (text_.find_first_of (" \t\n", length_)); + bool full (n == string::npos); // Text length is below the limit. - // Truncate changes if length exceed the limit. + // Truncate the text if length exceeds the limit. // - const string& c (full ? changes_ : string (changes_, 0, n)); - s << PRE(ID="changes") << c; + const string& t (full ? text_ : string (text_, 0, n)); + s << PRE; + + if (!id_.empty ()) + s << ID(id_); + + s << t; if (!full) { diff --git a/mod/page.hxx b/mod/page.hxx index 4b59e7d..f8d2830 100644 --- a/mod/page.hxx +++ b/mod/page.hxx @@ -520,53 +520,63 @@ namespace brep const bbot::result_status& status_; }; - // Generates package description element. + // Generates paragraph elements converting a plain text into XHTML5 applying + // some heuristics (see implementation for details). Truncate the text if + // requested. // - class P_DESCRIPTION + // 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: - // Genereate full description. + // Generate full text elements. // - P_DESCRIPTION (const string& d, const string& id = "") - : description_ (d), length_ (d.size ()), url_ (nullptr), id_ (id) {} + P_TEXT (const string& t, const string& id = "") + : text_ (t), length_ (t.size ()), url_ (nullptr), id_ (id) {} - // Genereate brief description. + // Generate brief text elements. // - P_DESCRIPTION (const string& d, size_t l, const string& u) - : description_ (d), length_ (l), url_ (&u) {} + 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& description_; + const string& text_; size_t length_; const string* url_; // Full page url. string id_; }; - // Generates package description element. + // Generates pre-formatted text element. Truncate the text if requested. // - class PRE_CHANGES + class PRE_TEXT { public: - // Genereate full changes info. + // Generate a full text element. // - PRE_CHANGES (const string& c) - : changes_ (c), length_ (c.size ()), url_ (nullptr) {} + PRE_TEXT (const string& t, const string& id = "") + : text_ (t), length_ (t.size ()), url_ (nullptr), id_ (id) {} - // Genereate brief changes info. + // Generate a brief text element. // - PRE_CHANGES (const string& c, size_t l, const string& u) - : changes_ (c), length_ (l), url_ (&u) {} + 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& changes_; + const string& text_; size_t length_; const string* url_; // Full page url. + string id_; }; // Generates paging element. |