From 4ea3702768e45f1d408737ebfcf74a6335bbf7d8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 11 Dec 2020 19:55:19 +0100 Subject: [PATCH] Added and implemented a HTML builder. --- core/html_builder.cpp | 1456 +++++++++++++++++++++++++++++++++++++++++ core/html_builder.h | 315 +++++++++ rdn_application.cpp | 29 +- 3 files changed, 1799 insertions(+), 1 deletion(-) create mode 100644 core/html_builder.cpp create mode 100644 core/html_builder.h diff --git a/core/html_builder.cpp b/core/html_builder.cpp new file mode 100644 index 0000000..884cc56 --- /dev/null +++ b/core/html_builder.cpp @@ -0,0 +1,1456 @@ +#include "html_builder.h" + +HTMLTag *HTMLTag::str(const std::string &str) { + result += " " + str; + + return this; +} + +HTMLTag *HTMLTag::style(const std::string &val) { + attrib("style", val); + + return this; +} + +HTMLTag *HTMLTag::href(const std::string &val) { + attrib("href", val); + + return this; +} + +HTMLTag *HTMLTag::cls(const std::string &val) { + attrib("class", val); + + return this; +} +HTMLTag *HTMLTag::id(const std::string &val) { + attrib("id", val); + + return this; +} +HTMLTag *HTMLTag::name(const std::string &val) { + attrib("name", val); + + return this; +} + +HTMLTag *HTMLTag::method(const std::string &val) { + attrib("method", val); + + return this; +} + +HTMLTag *HTMLTag::type(const std::string &val) { + attrib("type", val); + + return this; +} + +HTMLTag *HTMLTag::attrib(const std::string &attr, const std::string &val) { + result += " " + attr + "=\"" + val + "\""; + + return this; +} + +HTMLTag *HTMLTag::start(const std::string &p_tag, const bool p_simple) { + simple = p_simple; + + result = "<" + p_tag; + + return this; +} + +HTMLTag *HTMLTag::reset() { + result.clear(); + + return this; +} + +HTMLTag *HTMLTag::close() { + if (simple) + result += "/>"; + else + result += ">"; + + return this; +} + +bool HTMLTag::has_data() { + return result.size() > 0; +} + +HTMLTag::HTMLTag() { + simple = true; +} + +void HTMLBuilder::comment(const std::string &val) { + write_tag(); + + result += ""; +} + +HTMLTag *HTMLBuilder::doctype() { + write_tag(); + + return tag.start("!DOCTYPE"); +} + +void HTMLBuilder::doctype(const std::string &val) { + write_tag(); + + result += ""; +} + +HTMLTag *HTMLBuilder::a() { + write_tag(); + + return tag.start("a"); +} +HTMLTag *HTMLBuilder::abbr() { + write_tag(); + + return tag.start("abbr"); +} + +HTMLTag *HTMLBuilder::acronym() { //Not supported in HTML5. Use instead. Defines an acronym + write_tag(); + + return tag.start("acronym"); +} + +HTMLTag *HTMLBuilder::address() { + write_tag(); + + return tag.start("address"); +} + +HTMLTag *HTMLBuilder::applet() { //Not supported in HTML5. Use or instead. Defines an embedded applet + write_tag(); + + return tag.start("applet"); +} + +HTMLTag *HTMLBuilder::area() { + write_tag(); + + return tag.start("area"); +} + +HTMLTag *HTMLBuilder::article() { + write_tag(); + + return tag.start("article"); +} + +HTMLTag *HTMLBuilder::aside() { + write_tag(); + + return tag.start("aside"); +} + +HTMLTag *HTMLBuilder::audio() { + write_tag(); + + return tag.start("audio"); +} + +HTMLTag *HTMLBuilder::b() { + write_tag(); + + return tag.start("b"); +} + +HTMLTag *HTMLBuilder::basefont() { //Not supported in HTML5. Use CSS instead. Specifies a default color, size, and font for all text in a document + write_tag(); + + return tag.start("basefont"); +} + +HTMLTag *HTMLBuilder::bdi() { + write_tag(); + + return tag.start("bdi"); +} + +HTMLTag *HTMLBuilder::bdo() { + write_tag(); + + return tag.start("bdo"); +} + +HTMLTag *HTMLBuilder::big() { //Not supported in HTML5. Use CSS instead. Defines big text + write_tag(); + + return tag.start("big"); +} + +HTMLTag *HTMLBuilder::blockquote() { + write_tag(); + + return tag.start("blockquote"); +} + +HTMLTag *HTMLBuilder::body() { + write_tag(); + + return tag.start("body"); +} + +HTMLTag *HTMLBuilder::br() { + write_tag(); + + return tag.start("br", true); +} + +HTMLTag *HTMLBuilder::button() { + write_tag(); + + return tag.start("button"); +} + +HTMLTag *HTMLBuilder::canvas() { + write_tag(); + + return tag.start("canvas"); +} + +HTMLTag *HTMLBuilder::caption() { + write_tag(); + + return tag.start("caption"); +} + +HTMLTag *HTMLBuilder::center() { //Not supported in HTML5. Use CSS instead. Defines centered text + write_tag(); + + return tag.start("center"); +} + +HTMLTag *HTMLBuilder::cite() { + write_tag(); + + return tag.start("cite"); +} + +HTMLTag *HTMLBuilder::code() { + write_tag(); + + return tag.start("code"); +} + +HTMLTag *HTMLBuilder::col() { + write_tag(); + + return tag.start("col"); +} + +HTMLTag *HTMLBuilder::colgroup() { + write_tag(); + + return tag.start("colgroup"); +} + +HTMLTag *HTMLBuilder::data() { + write_tag(); + + return tag.start("cite"); +} + +HTMLTag *HTMLBuilder::datalist() { + write_tag(); + + return tag.start("datalist"); +} + +HTMLTag *HTMLBuilder::dd() { + write_tag(); + + return tag.start("dd"); +} + +HTMLTag *HTMLBuilder::del() { + write_tag(); + + return tag.start("del"); +} + +HTMLTag *HTMLBuilder::details() { + write_tag(); + + return tag.start("details"); +} + +HTMLTag *HTMLBuilder::dfn() { + write_tag(); + + return tag.start("dfn"); +} + +HTMLTag *HTMLBuilder::dialog() { + write_tag(); + + return tag.start("dialog"); +} + +HTMLTag *HTMLBuilder::dir() { // Not supported in HTML5. Use
    instead. + write_tag(); + + return tag.start("dir"); +} + +HTMLTag *HTMLBuilder::div() { + write_tag(); + + return tag.start("div"); +} + +HTMLTag *HTMLBuilder::dl() { + write_tag(); + + return tag.start("dl"); +} + +HTMLTag *HTMLBuilder::dt() { + write_tag(); + + return tag.start("dt"); +} + +HTMLTag *HTMLBuilder::em() { + write_tag(); + + return tag.start("em"); +} + +HTMLTag *HTMLBuilder::embed() { + write_tag(); + + return tag.start("embed"); +} + +HTMLTag *HTMLBuilder::fieldset() { + write_tag(); + + return tag.start("fieldset"); +} +HTMLTag *HTMLBuilder::figcaption() { + write_tag(); + + return tag.start("figcaption"); +} + +HTMLTag *HTMLBuilder::figure() { + write_tag(); + + return tag.start("figure"); +} + +HTMLTag *HTMLBuilder::font() { //Not supported in HTML5. + write_tag(); + + return tag.start("font"); +} + +HTMLTag *HTMLBuilder::footer() { + write_tag(); + + return tag.start("footer"); +} + +HTMLTag *HTMLBuilder::form() { + write_tag(); + + return tag.start("form"); +} + +HTMLTag *HTMLBuilder::frame() { //Not supported in HTML5. + write_tag(); + + return tag.start("frame"); +} + +HTMLTag *HTMLBuilder::frameset() { //Not supported in HTML5. + write_tag(); + + return tag.start("frameset"); +} + +HTMLTag *HTMLBuilder::h1() { + write_tag(); + + return tag.start("h1"); +} + +HTMLTag *HTMLBuilder::h2() { + write_tag(); + + return tag.start("h2"); +} + +HTMLTag *HTMLBuilder::h3() { + write_tag(); + + return tag.start("h3"); +} + +HTMLTag *HTMLBuilder::h4() { + write_tag(); + + return tag.start("h4"); +} + +HTMLTag *HTMLBuilder::h5() { + write_tag(); + + return tag.start("h5"); +} + +HTMLTag *HTMLBuilder::h6() { + write_tag(); + + return tag.start("h6"); +} + +HTMLTag *HTMLBuilder::head() { + write_tag(); + + return tag.start("head"); +} + +HTMLTag *HTMLBuilder::header() { + write_tag(); + + return tag.start("header"); +} + +HTMLTag *HTMLBuilder::hr() { + write_tag(); + + return tag.start("hr"); +} + +HTMLTag *HTMLBuilder::html() { + write_tag(); + + return tag.start("html"); +} + +HTMLTag *HTMLBuilder::i() { + write_tag(); + + return tag.start("i"); +} + +HTMLTag *HTMLBuilder::iframe() { + write_tag(); + + return tag.start("iframe"); +} + +HTMLTag *HTMLBuilder::img() { + write_tag(); + + return tag.start("img"); +} + +HTMLTag *HTMLBuilder::input() { + write_tag(); + + return tag.start("input"); +} + +HTMLTag *HTMLBuilder::ins() { + write_tag(); + + return tag.start("ins"); +} + +HTMLTag *HTMLBuilder::kbd() { + write_tag(); + + return tag.start("kbd"); +} + +HTMLTag *HTMLBuilder::label() { + write_tag(); + + return tag.start("label"); +} + +HTMLTag *HTMLBuilder::legend() { + write_tag(); + + return tag.start("legend"); +} + +HTMLTag *HTMLBuilder::li() { + write_tag(); + + return tag.start("li"); +} + +HTMLTag *HTMLBuilder::link() { + write_tag(); + + return tag.start("link"); +} + +HTMLTag *HTMLBuilder::main() { + write_tag(); + + return tag.start("main"); +} + +HTMLTag *HTMLBuilder::map() { + write_tag(); + + return tag.start("map"); +} +HTMLTag *HTMLBuilder::mark() { + write_tag(); + + return tag.start("mark"); +} + +HTMLTag *HTMLBuilder::meta() { + write_tag(); + + return tag.start("meta"); +} + +HTMLTag *HTMLBuilder::meter() { + write_tag(); + + return tag.start("meter"); +} + +HTMLTag *HTMLBuilder::nav() { + write_tag(); + + return tag.start("nav"); +} + +HTMLTag *HTMLBuilder::noframes() { //Not supported in HTML5. + write_tag(); + + return tag.start("noframes"); +} + +HTMLTag *HTMLBuilder::noscript() { + write_tag(); + + return tag.start("noscript"); +} + +HTMLTag *HTMLBuilder::object() { + write_tag(); + + return tag.start("object"); +} + +HTMLTag *HTMLBuilder::ol() { + write_tag(); + + return tag.start("ol"); +} + +HTMLTag *HTMLBuilder::optgroup() { + write_tag(); + + return tag.start("optgroup"); +} + +HTMLTag *HTMLBuilder::option() { + write_tag(); + + return tag.start("option"); +} + +HTMLTag *HTMLBuilder::output() { + write_tag(); + + return tag.start("output"); +} + +HTMLTag *HTMLBuilder::p() { + write_tag(); + + return tag.start("p"); +} + +HTMLTag *HTMLBuilder::param() { + write_tag(); + + return tag.start("param"); +} + +HTMLTag *HTMLBuilder::picture() { + write_tag(); + + return tag.start("picture"); +} + +HTMLTag *HTMLBuilder::pre() { + write_tag(); + + return tag.start("pre"); +} + +HTMLTag *HTMLBuilder::progress() { + write_tag(); + + return tag.start("progress"); +} + +HTMLTag *HTMLBuilder::q() { + write_tag(); + + return tag.start("q"); +} + +HTMLTag *HTMLBuilder::rp() { + write_tag(); + + return tag.start("rp"); +} + +HTMLTag *HTMLBuilder::rt() { + write_tag(); + + return tag.start("rt"); +} + +HTMLTag *HTMLBuilder::ruby() { + write_tag(); + + return tag.start("ruby"); +} + +HTMLTag *HTMLBuilder::s() { + write_tag(); + + return tag.start("s"); +} + +HTMLTag *HTMLBuilder::samp() { + write_tag(); + + return tag.start("samp"); +} + +HTMLTag *HTMLBuilder::script() { + write_tag(); + + return tag.start("script"); +} + +HTMLTag *HTMLBuilder::section() { + write_tag(); + + return tag.start("section"); +} + +HTMLTag *HTMLBuilder::select() { + write_tag(); + + return tag.start("select"); +} + +HTMLTag *HTMLBuilder::small() { + write_tag(); + + return tag.start("small"); +} + +HTMLTag *HTMLBuilder::source() { + write_tag(); + + return tag.start("source"); +} + +HTMLTag *HTMLBuilder::span() { + write_tag(); + + return tag.start("span"); +} + +HTMLTag *HTMLBuilder::strike() { //Not supported in HTML5 + write_tag(); + + return tag.start("strike"); +} + +HTMLTag *HTMLBuilder::strong() { + write_tag(); + + return tag.start("strong"); +} + +HTMLTag *HTMLBuilder::style() { + write_tag(); + + return tag.start("style"); +} + +HTMLTag *HTMLBuilder::sub() { + write_tag(); + + return tag.start("sub"); +} + +HTMLTag *HTMLBuilder::summary() { + write_tag(); + + return tag.start("summary"); +} + +HTMLTag *HTMLBuilder::sup() { + write_tag(); + + return tag.start("sup"); +} + +HTMLTag *HTMLBuilder::svg() { + write_tag(); + + return tag.start("svg"); +} + +HTMLTag *HTMLBuilder::table() { + write_tag(); + + return tag.start("table"); +} + +HTMLTag *HTMLBuilder::tbody() { + write_tag(); + + return tag.start("tbody"); +} + +HTMLTag *HTMLBuilder::td() { + write_tag(); + + return tag.start("td"); +} + +HTMLTag *HTMLBuilder::templateh() { + write_tag(); + + return tag.start("template"); +} + +HTMLTag *HTMLBuilder::textarea() { + write_tag(); + + return tag.start("textarea"); +} + +HTMLTag *HTMLBuilder::tfoot() { + write_tag(); + + return tag.start("tfoot"); +} + +HTMLTag *HTMLBuilder::th() { + write_tag(); + + return tag.start("th"); +} + +HTMLTag *HTMLBuilder::thead() { + write_tag(); + + return tag.start("thead"); +} + +HTMLTag *HTMLBuilder::time() { + write_tag(); + + return tag.start("time"); +} + +HTMLTag *HTMLBuilder::title() { + write_tag(); + + return tag.start("title"); +} + +HTMLTag *HTMLBuilder::tr() { + write_tag(); + + return tag.start("tr"); +} + +HTMLTag *HTMLBuilder::track() { + write_tag(); + + return tag.start("track"); +} + +HTMLTag *HTMLBuilder::tt() { //Not supported in HTML5. + write_tag(); + + return tag.start("tt"); +} + +HTMLTag *HTMLBuilder::u() { + write_tag(); + + return tag.start("u"); +} + +HTMLTag *HTMLBuilder::ul() { + write_tag(); + + return tag.start("ul"); +} + +HTMLTag *HTMLBuilder::var() { + write_tag(); + + return tag.start("var"); +} + +HTMLTag *HTMLBuilder::video() { + write_tag(); + + return tag.start("video"); +} + +HTMLTag *HTMLBuilder::wbr() { + write_tag(); + + return tag.start("wbr"); +} + +//Closing tags + +void HTMLBuilder::ca() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cabbr() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cacronym() { + write_tag(); + result += ""; +} + +void HTMLBuilder::caddress() { + write_tag(); + result += ""; +} + +void HTMLBuilder::capplet() { + write_tag(); + result += ""; +} + +void HTMLBuilder::carea() { + write_tag(); + result += ""; +} + +void HTMLBuilder::carticle() { + write_tag(); + result += ""; +} + +void HTMLBuilder::caside() { + write_tag(); + result += ""; +} + +void HTMLBuilder::caudio() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cb() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbasefont() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbdi() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbdo() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbig() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cblockquote() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbody() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cbutton() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccanvas() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccaption() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccenter() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccite() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccode() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccol() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ccolgroup() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdata() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdatalist() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdd() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdel() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdetails() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdfn() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdialog() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdir() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdiv() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdl() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cdt() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cem() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cembed() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cfieldset() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cfigcaption() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cfigure() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cfont() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cfooter() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cform() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cframe() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cframeset() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch1() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch2() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch3() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch4() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch5() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ch6() { + write_tag(); + result += ""; +} + +void HTMLBuilder::chead() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cheader() { + write_tag(); + result += ""; +} + +void HTMLBuilder::chr() { + write_tag(); + result += ""; +} + +void HTMLBuilder::chtml() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ci() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ciframe() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cimg() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cinput() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cins() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ckbd() { + write_tag(); + result += ""; +} + +void HTMLBuilder::clabel() { + write_tag(); + result += ""; +} + +void HTMLBuilder::clegend() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cli() { + write_tag(); + result += ""; +} + +void HTMLBuilder::clink() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cmain() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cmap() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cmark() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cmeta() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cmeter() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cnav() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cnoframes() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cnoscript() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cobject() { + write_tag(); + result += "
"; +} + +void HTMLBuilder::c_ol() { + write_tag(); + result += ""; +} + +void HTMLBuilder::coptgroup() { + write_tag(); + result += ""; +} + +void HTMLBuilder::coption() { + write_tag(); + result += ""; +} + +void HTMLBuilder::coutput() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cp() { + write_tag(); + result += "

"; +} + +void HTMLBuilder::cparam() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cpicture() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cpre() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cprogress() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cq() { + write_tag(); + result += ""; +} + +void HTMLBuilder::crp() { + write_tag(); + result += ""; +} + +void HTMLBuilder::crt() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cruby() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cs() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csamp() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cscript() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csection() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cselect() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csmall() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csource() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cspan() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cstrike() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cstrong() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cstyle() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csub() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csummary() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csup() { + write_tag(); + result += ""; +} + +void HTMLBuilder::csvg() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctable() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctbody() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctd() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctemplateh() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctextarea() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctfoot() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cth() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cthead() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctime() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctitle() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctr() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctrack() { + write_tag(); + result += ""; +} + +void HTMLBuilder::ctt() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cu() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cul() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cvar() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cvideo() { + write_tag(); + result += ""; +} + +void HTMLBuilder::cwbr() { + write_tag(); + result += ""; +} + +void HTMLBuilder::w(const std::string &val) { + write_tag(); + + result += val; +} + +//TODO! +void HTMLBuilder::we(const std::string &val) { + printf("HTMLBuilder::write_excaped NYI!"); + + write_tag(); + + result += val; +} + +void HTMLBuilder::write_tag() { + if (tag.has_data()) { + tag.close(); + result += tag.result; + tag.reset(); + } +} + +HTMLBuilder::HTMLBuilder() { +} + +HTMLBuilder::~HTMLBuilder() { +} \ No newline at end of file diff --git a/core/html_builder.h b/core/html_builder.h new file mode 100644 index 0000000..c24cd06 --- /dev/null +++ b/core/html_builder.h @@ -0,0 +1,315 @@ +#ifndef HTML_BUILDER_H +#define HTML_BUILDER_H + +#include +#include +#include + +class Request; + +//This might be converted to a form validator + +class HTMLTag { +public: + bool simple; + std::string result; + + HTMLTag *str(const std::string &str); + HTMLTag *style(const std::string &val); + HTMLTag *href(const std::string &val); + HTMLTag *cls(const std::string &val); + HTMLTag *id(const std::string &val); + HTMLTag *name(const std::string &val); + HTMLTag *method(const std::string &val); + HTMLTag *type(const std::string &val); + + HTMLTag *attrib(const std::string &attr, const std::string &val); + + HTMLTag *start(const std::string &p_new_tag, const bool p_simple = false); + HTMLTag *reset(); + HTMLTag *close(); + + bool has_data(); + + HTMLTag(); +}; + +class HTMLBuilder { +public: + std::string result; + + void comment(const std::string &val); + HTMLTag *doctype(); + void doctype(const std::string &val); + + HTMLTag *a(); + HTMLTag *abbr(); + HTMLTag *acronym(); //Not supported in HTML5. + HTMLTag *address(); + HTMLTag *applet(); //Not supported in HTML5. + HTMLTag *area(); + HTMLTag *article(); + HTMLTag *aside(); + HTMLTag *audio(); + HTMLTag *b(); + HTMLTag *basefont(); //Not supported in HTML5. + HTMLTag *bdi(); + HTMLTag *bdo(); + HTMLTag *big(); //Not supported in HTML5. + HTMLTag *blockquote(); + HTMLTag *body(); + HTMLTag *br(); + HTMLTag *button(); + HTMLTag *canvas(); + HTMLTag *caption(); + HTMLTag *center(); //Not supported in HTML5. + HTMLTag *cite(); + HTMLTag *code(); + HTMLTag *col(); + HTMLTag *colgroup(); + HTMLTag *data(); + HTMLTag *datalist(); + HTMLTag *dd(); + HTMLTag *del(); + HTMLTag *details(); + HTMLTag *dfn(); + HTMLTag *dialog(); + HTMLTag *dir(); // Not supported in HTML5. + HTMLTag *div(); + HTMLTag *dl(); + HTMLTag *dt(); + HTMLTag *em(); + HTMLTag *embed(); + HTMLTag *fieldset(); + HTMLTag *figcaption(); + HTMLTag *figure(); + HTMLTag *font(); //Not supported in HTML5. + HTMLTag *footer(); + HTMLTag *form(); + HTMLTag *frame(); //Not supported in HTML5. + HTMLTag *frameset(); //Not supported in HTML5. + HTMLTag *h1(); + HTMLTag *h2(); + HTMLTag *h3(); + HTMLTag *h4(); + HTMLTag *h5(); + HTMLTag *h6(); + HTMLTag *head(); + HTMLTag *header(); + HTMLTag *hr(); + HTMLTag *html(); + + HTMLTag *i(); + HTMLTag *iframe(); + HTMLTag *img(); + HTMLTag *input(); + HTMLTag *ins(); + HTMLTag *kbd(); + HTMLTag *label(); + HTMLTag *legend(); + HTMLTag *li(); + HTMLTag *link(); + HTMLTag *main(); + HTMLTag *map(); + HTMLTag *mark(); + HTMLTag *meta(); + HTMLTag *meter(); + + HTMLTag *nav(); + HTMLTag *noframes(); //Not supported in HTML5. + HTMLTag *noscript(); + HTMLTag *object(); + HTMLTag *ol(); + HTMLTag *optgroup(); + HTMLTag *option(); + HTMLTag *output(); + HTMLTag *p(); + HTMLTag *param(); + HTMLTag *picture(); + HTMLTag *pre(); + HTMLTag *progress(); + HTMLTag *q(); + HTMLTag *rp(); + + HTMLTag *rt(); + HTMLTag *ruby(); + HTMLTag *s(); + HTMLTag *samp(); + HTMLTag *script(); + HTMLTag *section(); + HTMLTag *select(); + HTMLTag *small(); + HTMLTag *source(); + HTMLTag *span(); + HTMLTag *strike(); //Not supported in HTML5 + HTMLTag *strong(); + HTMLTag *style(); + HTMLTag *sub(); + HTMLTag *summary(); + HTMLTag *sup(); + + HTMLTag *svg(); + HTMLTag *table(); + HTMLTag *tbody(); + HTMLTag *td(); + HTMLTag *templateh(); + HTMLTag *textarea(); + HTMLTag *tfoot(); + HTMLTag *th(); + HTMLTag *thead(); + HTMLTag *time(); + HTMLTag *title(); + HTMLTag *tr(); + HTMLTag *track(); + HTMLTag *tt(); //Not supported in HTML5. + HTMLTag *u(); + HTMLTag *ul(); + HTMLTag *var(); + HTMLTag *video(); + HTMLTag *wbr(); + + //closing tags c prefix means close + //Note simple tags should not have these like
+ //Note that I might have a few that shouldn't be here, those will be removed as I find them + void ca(); + void cabbr(); + void cacronym(); + void caddress(); + void capplet(); + void carea(); + void carticle(); + void caside(); + void caudio(); + void cb(); + void cbasefont(); + void cbdi(); + void cbdo(); + void cbig(); + void cblockquote(); + void cbody(); + void cbutton(); + void ccanvas(); + + void ccaption(); + void ccenter(); + void ccite(); + void ccode(); + void ccol(); + void ccolgroup(); + void cdata(); + void cdatalist(); + void cdd(); + void cdel(); + void cdetails(); + void cdfn(); + void cdialog(); + void cdir(); + void cdiv(); + void cdl(); + void cdt(); + + void cem(); + void cembed(); + void cfieldset(); + void cfigcaption(); + void cfigure(); + void cfont(); + void cfooter(); + void cform(); + void cframe(); + void cframeset(); + void ch1(); + void ch2(); + void ch3(); + void ch4(); + void ch5(); + void ch6(); + void chead(); + void cheader(); + void chr(); + void chtml(); + + void ci(); + void ciframe(); + void cimg(); + void cinput(); + void cins(); + void ckbd(); + void clabel(); + void clegend(); + void cli(); + void clink(); + void cmain(); + void cmap(); + void cmark(); + void cmeta(); + void cmeter(); + + void cnav(); + void cnoframes(); + void cnoscript(); + void cobject(); + void c_ol(); + void coptgroup(); + void coption(); + void coutput(); + void cp(); + void cparam(); + void cpicture(); + void cpre(); + void cprogress(); + void cq(); + void crp(); + + void crt(); + void cruby(); + void cs(); + void csamp(); + void cscript(); + void csection(); + void cselect(); + void csmall(); + void csource(); + void cspan(); + void cstrike(); + void cstrong(); + void cstyle(); + void csub(); + void csummary(); + void csup(); + + void csvg(); + void ctable(); + void ctbody(); + void ctd(); + void ctemplateh(); + void ctextarea(); + void ctfoot(); + void cth(); + void cthead(); + void ctime(); + void ctitle(); + void ctr(); + void ctrack(); + void ctt(); + void cu(); + void cul(); + void cvar(); + void cvideo(); + void cwbr(); + + //write + void w(const std::string &val); + //write_escaped + void we(const std::string &val); + + void write_tag(); + + HTMLBuilder(); + virtual ~HTMLBuilder(); + +protected: + HTMLTag tag; +}; + +#endif \ No newline at end of file diff --git a/rdn_application.cpp b/rdn_application.cpp index d402a0f..9fcf05a 100644 --- a/rdn_application.cpp +++ b/rdn_application.cpp @@ -10,6 +10,8 @@ #include "core/database_manager.h" +#include "core/html_builder.h" + void RDNApplication::index(Object *instance, Request *request) { std::string body; @@ -19,7 +21,32 @@ void RDNApplication::index(Object *instance, Request *request) { return; } - request->body.append("

Test HTML Body

"); + HTMLBuilder b; + + b.h1(); + b.w("Testh1"); + b.ch1(); + + b.h2()->cls("tcls")->id("tid"); + b.w("Testh2"); + b.ch2(); + + b.br(); + + b.p(); + b.w("Test HTML Body HTMLBuilder"); + b.cp(); + + b.form()->method("post")->href("/"); + + //->str("/") is a temp hack + b.input()->type("text")->str("/"); + b.input()->type("submit")->str("/"); + b.cform(); + + request->body = b.result; + + //request->body.append("

Test HTML Body

"); request->compile_body(); FileCache::get_singleton()->set_cached_body("index", request->compiled_body);