From d8656ec149d7e8de0c58017cb7e88cf3c04207e4 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Fri, 3 Mar 2023 00:40:04 +0530 Subject: [PATCH] Introduce HTMLDumper HTMLDumper class will be used to dump library in HTML format. It inherits from LibraryDumper --- include/html_dumper.h | 50 ++++++++++++++++++++++++ src/html_dumper.cpp | 37 ++++++++++++++++++ src/meson.build | 1 + src/server/internalServer.cpp | 1 + static/resources_list.txt | 1 + static/templates/no_js_library_page.html | 40 +++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 include/html_dumper.h create mode 100644 src/html_dumper.cpp create mode 100644 static/templates/no_js_library_page.html diff --git a/include/html_dumper.h b/include/html_dumper.h new file mode 100644 index 000000000..fd09659db --- /dev/null +++ b/include/html_dumper.h @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Nikhil Tanwar <2002nikhiltanwar@gmail.com> + * + * This program 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 3 of the License, or + * any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_HTML_DUMPER_H +#define KIWIX_HTML_DUMPER_H + +#include + +#include "library_dumper.h" + +namespace kiwix +{ + +/** + * A class to dump Library in HTML format. + */ +class HTMLDumper : public LibraryDumper +{ + public: + HTMLDumper(const Library* library, const NameMapper* NameMapper); + ~HTMLDumper(); + + + /** + * Dump library in HTML + * + * @return HTML content + */ + std::string dumpPlainHTML() const; +}; + +} + +#endif // KIWIX_HTML_DUMPER_H diff --git a/src/html_dumper.cpp b/src/html_dumper.cpp new file mode 100644 index 000000000..919e4bcea --- /dev/null +++ b/src/html_dumper.cpp @@ -0,0 +1,37 @@ +#include "html_dumper.h" +#include "libkiwix-resources.h" +#include "tools/otherTools.h" + +namespace kiwix +{ + +/* Constructor */ +HTMLDumper::HTMLDumper(const Library* library, const NameMapper* nameMapper) + : LibraryDumper(library, nameMapper) +{ +} +/* Destructor */ +HTMLDumper::~HTMLDumper() +{ +} + +std::string HTMLDumper::dumpPlainHTML() const +{ + kainjow::mustache::list booksData; + for ( const auto& bookId : library->getBooksIds() ) { + const auto bookEx = library->getBookById(bookId); + const auto bookName = bookEx.getName(); + booksData.push_back(kainjow::mustache::object{ + {"name", bookName} + }); + } + + return render_template( + RESOURCE::templates::no_js_library_page_html, + kainjow::mustache::object{ + {"books", booksData } + } + ); +} + +} // namespace kiwix diff --git a/src/meson.build b/src/meson.build index 3bbb24f98..21486bc4e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,6 +5,7 @@ kiwix_sources = [ 'manager.cpp', 'libxml_dumper.cpp', 'opds_dumper.cpp', + 'html_dumper.cpp', 'library_dumper.cpp', 'downloader.cpp', 'server.cpp', diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 8db0f81f3..b787cb03f 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -53,6 +53,7 @@ extern "C" { #include "name_mapper.h" #include "search_renderer.h" #include "opds_dumper.h" +#include "html_dumper.h" #include "i18n.h" #include diff --git a/static/resources_list.txt b/static/resources_list.txt index 69f8bf961..516c8bfc6 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -37,6 +37,7 @@ templates/catalog_v2_categories.xml templates/catalog_v2_languages.xml templates/url_of_search_results_css templates/viewer_settings.js +templates/no_js_library_page.html opensearchdescription.xml ft_opensearchdescription.xml catalog_v2_searchdescription.xml diff --git a/static/templates/no_js_library_page.html b/static/templates/no_js_library_page.html new file mode 100644 index 000000000..0281d85ba --- /dev/null +++ b/static/templates/no_js_library_page.html @@ -0,0 +1,40 @@ + + + + + + + Welcome to Kiwix Server + + + + + + + + + + + + + + VERY REAL TEST :)))))))) + {{#books}} +
{{name}}
+ {{/books}} + + \ No newline at end of file