hemplate

Simple XML template engine
git clone git://git.dimitrijedobrota.com/hemplate.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit 2134cbce8d3b470100b503058bd3894b346892f9
parent ee98b9c229f2c28adaa21872a0b72d1b4869b26b
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Tue, 25 Jun 2024 19:51:13 +0200

Add commends and shorthand for boilerplate types

Diffstat:
M CMakeLists.txt | + -
M include/hemplate/classes.hpp | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --
M test/source/hemplate_test.cpp | ++++++

3 files changed, 99 insertions(+), 2 deletions(-)


diff --git a/ CMakeLists.txt b/ CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake) project( hemplate
VERSION 0.1.7
VERSION 0.1.8
DESCRIPTION "Simple HTML template engine" HOMEPAGE_URL "https://git.dimitrijedobrota.com/hemplate.git" LANGUAGES CXX

diff --git a/ include/hemplate/classes.hpp b/ include/hemplate/classes.hpp

@@ -29,8 +29,56 @@ struct tag static char const* get_name() { return Name.data(); } };
class comment : public elementBoolean<tag<"">>
{
public:
comment() = default;
explicit comment(std::string text)
: elementBoolean(std::move(text))
{
}
void render(std::ostream& out) const override
{
if (get_data().empty())
{
tgl_state();
out << (get_state() ? "<!-- " : " -->");
}
else out << "<!-- " << get_data() << " -->";
}
};
class xml : public elementAtomic<tag<"xml">>
{
public:
explicit xml(std::string version = "1.0", std::string encoding = "UTF-8")
: m_version(std::move(version))
, m_encoding(std::move(encoding))
{
}
void render(std::ostream& out) const override
{
out << R"(<?xml version=")" << m_version << '"';
out << R"( encoding=")" << m_encoding << "\"?>";
}
private:
std::string m_version;
std::string m_encoding;
};
namespace html {
class doctype : public elementAtomic<tag<"doctype">>
{
public:
explicit doctype() = default;
void render(std::ostream& out) const override { out << "<!DOCTYPE html>"; }
};
using a = elementBoolean<tag<"a">>; using abbr = elementBoolean<tag<"abbr">>; using address = elementBoolean<tag<"address">>;

@@ -148,8 +196,31 @@ using wbr = elementAtomic<tag<"wbr">>; namespace rss {
class rss : public elementBoolean<tag<"rss">>
{
public:
explicit rss(std::string version = "2.0",
std::string xmlns = "http://www.w3.org/2005/Atom")
: elementBoolean(attributeList(
{{"version", std::move(version)}, {"xmlns:atom", std::move(xmlns)}}))
{
}
};
class atomLink : public elementAtomic<tag<"atom:link">>
{
public:
explicit atomLink(std::string rel = "self",
std::string type = "application/rss+xml")
: elementAtomic(
attributeList({{"rel", std::move(rel)}, {"type", std::move(type)}}))
{
}
};
using author = elementBoolean<tag<"author">>; using category = elementBoolean<tag<"category">>;
using channel = elementBoolean<tag<"channel">>;
using cloud = elementAtomic<tag<"cloud">>; using comments = elementBoolean<tag<"comments">>; using copyright = elementBoolean<tag<"copyright">>;

@@ -160,6 +231,7 @@ using generator = elementBoolean<tag<"generator">>; using guid = elementBoolean<tag<"guid">>; using height = elementBoolean<tag<"height">>; using image = elementBoolean<tag<"image">>;
using item = elementBoolean<tag<"item">>;
using language = elementBoolean<tag<"language">>; using lastBuildDate = elementBoolean<tag<"lastBuildDate">>; using link = elementBoolean<tag<"link">>;

@@ -176,7 +248,6 @@ using ttl = elementBoolean<tag<"ttl">>; using url = elementBoolean<tag<"url">>; using webMaster = elementBoolean<tag<"webMaster">>; using width = elementBoolean<tag<"width">>;
using atomLink = elementAtomic<tag<"atom:link">>;
} // namespace rss

@@ -210,4 +281,24 @@ using usagePoint = elementBoolean<tag<"usagePoint">>; } // namespace atom
namespace sitemap {
class urlset : public elementBoolean<tag<"urlset">>
{
public:
explicit urlset(
std::string xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9")
: elementBoolean(attributeList({"xmlns", std::move(xmlns)}))
{
}
};
using changefreq = elementBoolean<tag<"changefreq">>;
using lastmod = elementBoolean<tag<"lastmod">>;
using loc = elementBoolean<tag<"loc">>;
using url = elementBoolean<tag<"url">>;
using priority = elementBoolean<tag<"priority">>;
} // namespace sitemap
} // namespace hemplate

diff --git a/ test/source/hemplate_test.cpp b/ test/source/hemplate_test.cpp

@@ -11,6 +11,7 @@ int main() {"class", "home_ul"}, {"style", "margin-bottom: 1em"}});
std::cout << comment("Hello this is a commen");
std::cout << html::html() << std::endl; std::cout << html::ul("Won't see", ul_attrs) .set("style", "margin-top: 1em")

@@ -21,5 +22,10 @@ int main() std::cout << html::meta() << std::endl; std::cout << html::html() << std::endl;
std::cout << comment();
std::cout << "split ";
std::cout << "comment ";
std::cout << comment() << std::endl;
return 0; }