From 6eca8a647c79e9a5b100672b55f5d02273a28772 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Nov 2015 12:08:41 +0200 Subject: Implement 'about' web page --- brep/repository-details.cxx | 96 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 brep/repository-details.cxx (limited to 'brep/repository-details.cxx') diff --git a/brep/repository-details.cxx b/brep/repository-details.cxx new file mode 100644 index 0000000..4302c15 --- /dev/null +++ b/brep/repository-details.cxx @@ -0,0 +1,96 @@ +// file : brep/repository-details.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include // make_shared() + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace odb::core; + +namespace brep +{ + using namespace cli; + + void repository_details:: + init (scanner& s) + { + MODULE_DIAG; + + options_ = make_shared ( + s, unknown_mode::fail, unknown_mode::fail); + + db_ = shared_database (options_->db_host (), options_->db_port ()); + } + + void repository_details:: + handle (request&, response& rs) + { + using namespace web::xhtml; + + MODULE_DIAG; + + // The module options object is not changed after being created once per + // server process. + // + static const dir_path& rt (options_->root ()); + + xml::serializer s (rs.content (), "About"); + const string& title (s.output_name ()); + static const path sp ("repository-details.css"); + + s << HTML + << HEAD + << TITLE << title << ~TITLE + << CSS_LINKS (sp, rt) + << ~HEAD + << BODY + << DIV_HEADER (rt) + << DIV(ID="content"); + + transaction t (db_->begin ()); + + using query = query; + auto rp (db_->query (query::internal + "ORDER BY name")); + + for (const auto& r: rp) + { + string id (id_attribute (r.name)); + s << H1(ID=id) + << A(HREF="#" + web::mime_url_encode (id)) << r.name << ~A + << ~H1; + + if (r.email) + s << A << HREF << "mailto:" << *r.email << ~HREF << *r.email << ~A; + + if (r.summary) + s << H2 << *r.summary << ~H2; + + if (r.description) + s << P_DESCRIPTION (*r.description, false); + } + + t.commit (); + + s << ~DIV + << ~BODY + << ~HTML; + } +} -- cgit v1.1