docpp/examples/biteme.lol.cpp
Jacob 14cd8c4122 Remove/replace some "C with classes" junk. The C++ core guidelines state
that you must not use ALL_CAPS for enum members. enum class is now used
as well, to further reinforce the idea that this is a C++ library. While
neither of these changes are necessary, it leads to a better and more
intuitive API design.

More operator overloading has also been added for many of the classes,
particularly the [] index operator, which can now be used in place of
the at() method. More methods have also been added, particularly for
Section and Document.

Some methods have also been fixed, or have had their behavior altered
slightly, but this should now be covered under the new tests, which have
also been (for the most part) rewritten, both because they were
previously both primitive and rather ugly and because new functionality
was added.

Examples have also been updated to reflect the changes made in this
commit, so that they build successfully.

Of course, these changes mean that the new API is incompatible with any
applications written with the 0.0.1 version. Hopefully most of these
changes are dealt with before the 1.0 release, because I would prefer
not making API-breaking changes by that point.
2024-05-20 01:32:49 +02:00

65 lines
2.3 KiB
C++

/**
* @file biteme.lol.cpp
* @brief A simple program that replicates biteme.lol using docpp.
* @details This program creates a simple HTML document that replicates the biteme.lol website.
* @see https://biteme.lol
* @license LGPL-3.0
*
* g++ -std=c++11 biteme.lol.cpp -o biteme.lol -ldocpp
*/
#include <fstream>
#include <docpp/docpp.hpp>
int main() {
docpp::HTML::Section html(docpp::HTML::Tag::Html, {});
html.push_back({"title", {}, "Google"});
docpp::CSS::Stylesheet sheet{{
{".center", {
{"display", "flex"},
{"flex-wrap", "wrap"},
{"justify-content", "center"},
{"align-items", "center"},
{"font-size", "10vw"},
{"height", "10vw"},
{"padding", "10vw"},
}},
{"input[type=text], select", {
{"width", "50vw"},
}},
}};
html.push_back({"style", {}, sheet.get(docpp::CSS::Formatting::Pretty)});
docpp::HTML::Section div{docpp::HTML::Tag::Div, {docpp::HTML::Property("class", "center")}};
div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "G"});
div.push_back({"font", {docpp::HTML::Property("color", "red")}, "o"});
div.push_back({"font", {docpp::HTML::Property("color", "yellow")}, "o"});
div.push_back({"font", {docpp::HTML::Property("color", "blue")}, "g"});
div.push_back({"font", {docpp::HTML::Property("color", "green")}, "l"});
div.push_back({"font", {docpp::HTML::Property("color", "red")}, "e"});
html.push_back(div);
docpp::HTML::Section div2{docpp::HTML::Tag::Div, {docpp::HTML::Property("align", "center")}};
docpp::HTML::Section form{"form", {{docpp::HTML::Property("action", "https://google.com/search"), docpp::HTML::Property("method", "get")}}};
form.push_back({"input", docpp::HTML::Properties({docpp::HTML::Property("type", "text"), docpp::HTML::Property("name", "q")}), "", docpp::HTML::Type::Self_Closing});
form.push_back({"input", docpp::HTML::Properties({docpp::HTML::Property("type", "submit"), docpp::HTML::Property("value", "Search!")}), "", docpp::HTML::Type::Self_Closing});
div2.push_back(form);
html.push_back(div2);
docpp::HTML::Document doc{html};
std::ofstream file("biteme.lol.html");
file << doc.get(docpp::HTML::Formatting::Pretty);
file.close();
return 0;
}