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 dd6874a63aebeef93332146a2c42f183b414d0ab
parent 1bdb83d9ebb9f366de8e52bcede50f91b0104324
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Mon, 21 Apr 2025 18:15:38 +0200

Flesh out some functionality

Diffstat:
M include/hemplate/attribute.hpp | ++
M include/hemplate/classes.hpp | ++++++++++++++++++++++++++++++++++++++ ----
M source/attribute.cpp | ++++++++++++++++++++

3 files changed, 60 insertions(+), 4 deletions(-)


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

@@ -52,9 +52,11 @@ public: attributeList(std::initializer_list<attribute> list); attributeList(attribute attr); // NOLINT
attributeList& set(const attributeList& list);
attributeList& set(const std::string& name); attributeList& set(const std::string& name, const std::string& value);
attributeList add(const attributeList& list) const;
attributeList add(const std::string& name) const; attributeList add(const std::string& name, const std::string& value) const;

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

@@ -68,6 +68,12 @@ transparent transform(const R& range, namespace html {
using hemplate::comment;
using hemplate::element;
using hemplate::transform;
using hemplate::transparent;
using hemplate::xml;
// clang-format off using abbr = elementBuilder<tag<"abbr">, element::Type::Boolean>; using address = elementBuilder<tag<"address">, element::Type::Boolean>;

@@ -236,31 +242,53 @@ public: explicit atomLink(std::string rel, std::string type,
const attributeList& attributes,
const std::derived_from<element> auto&... children)
: elementBuilder({{"rel", std::move(rel)}, {"type", std::move(type)}},
: elementBuilder(attributes.add({{"rel", std::move(rel)},
{"type", std::move(type)}}),
children...) { } explicit atomLink(std::string rel, std::string type,
const attributeList& attributes,
std::span<const element> children)
: elementBuilder({{"rel", std::move(rel)}, {"type", std::move(type)}},
: elementBuilder(attributes.add({{"rel", std::move(rel)},
{"type", std::move(type)}}),
children) { } explicit atomLink(const std::derived_from<element> auto&... children)
: atomLink(default_rel, default_type, children...)
: atomLink(default_rel, default_type, {}, children...)
{ } explicit atomLink(std::span<const element> children)
: atomLink(default_rel, default_type, children)
: atomLink(default_rel, default_type, {}, children)
{
}
explicit atomLink(const attributeList& attributes,
const std::derived_from<element> auto&... children)
: atomLink(default_rel, default_type, attributes, children...)
{
}
explicit atomLink(const attributeList& attributes,
std::span<const element> children)
: atomLink(default_rel, default_type, attributes, children)
{ } };
using hemplate::comment;
using hemplate::element;
using hemplate::transform;
using hemplate::transparent;
using hemplate::xml;
// clang-format off using author = elementBuilder<tag<"author">, element::Type::Boolean>; using category = elementBuilder<tag<"category">, element::Type::Boolean>;

@@ -329,6 +357,12 @@ public: } };
using hemplate::comment;
using hemplate::element;
using hemplate::transform;
using hemplate::transparent;
using hemplate::xml;
// clang-format off using author = elementBuilder<tag<"author">, element::Type::Boolean>; using category = elementBuilder<tag<"category">, element::Type::Boolean>;

diff --git a/ source/attribute.cpp b/ source/attribute.cpp

@@ -18,11 +18,24 @@ bool attributeList::empty() const && m_style.get_value().empty(); }
attributeList& attributeList::set(const attributeList& list)
{
for (const auto& attr : list.m_attributes)
{
set(attr.get_name(), attr.get_value());
}
set("class", list.m_class);
set("style", list.m_style);
return (*this);
}
attributeList& attributeList::set(const std::string& name) { if (name != "class" && name != "style") m_attributes.emplace_back(name); return *this; }
attributeList& attributeList::set(const std::string& name, const std::string& value) {

@@ -41,6 +54,13 @@ attributeList& attributeList::set(const std::string& name, return *this; }
attributeList attributeList::add(const attributeList& list) const
{
attributeList res = *this;
res.set(list);
return res;
}
attributeList attributeList::add(const std::string& name) const { attributeList res = *this;