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 b4542f4193872af8947e244cd166d5e11dc441bb
parent c3b07dea92d12ab3b39a94e84e2505e83311c3a8
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Fri, 2 May 2025 15:36:35 +0200

Consistency improvements

Diffstat:
M example/html.cpp | +++++++ --
M include/hemplate/atom.hpp | ++ --
M include/hemplate/attribute.hpp | ++ --
M include/hemplate/classes.hpp | ++ -
M include/hemplate/element.hpp | ++++++++++++++++++ -------------------
M include/hemplate/html.hpp | ++ --
M include/hemplate/rss.hpp | +++ ---
M include/hemplate/sitemap.hpp | +++ ---
M test/source/attribute_list.cpp | ++ --

9 files changed, 41 insertions(+), 36 deletions(-)


diff --git a/ example/html.cpp b/ example/html.cpp

@@ -21,7 +21,6 @@ int main()

std::cout << html::html {
comment {"Hello this is a comment"},
html::ul {
ul_attrs,
html::li {
{li_attrs, {{"class", "item1"}}},
"Item 1",

@@ -32,7 +31,13 @@ int main()

"Item 2",
"some text",
},
transform(vec, [](const auto& e) { return e; }),
transform(
vec,
[](const auto& e)
{
return e;
}
),
},
html::hr {},
};

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

@@ -40,7 +40,7 @@ using hemplate::transform;

using hemplate::xml;

// clang-format off
// NOLINTBEGIN *-identifier-naming
// NOLINTBEGIN(*naming*)
using author = element_boolean<"author">;
using category = element_boolean<"category">;
using content = element_boolean<"content">;

@@ -66,7 +66,7 @@ using title = element_boolean<"title">;

using updated = element_boolean<"updated">;
using uri = element_boolean<"uri">;
using usagePoint = element_boolean<"usagePoint">;
// NOLINTEND *-identifier-naming
// NOLINTEND(*naming*)
// clang-format on

} // namespace hemplate::atom

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

@@ -15,7 +15,7 @@ class HEMPLATE_EXPORT attribute

std::string m_value;

public:
attribute(std::string_view name) // NOLINT *-explicit-constructor
attribute(std::string_view name) // NOLINT(*explicit*)
: m_name(name)
{
}

@@ -50,7 +50,7 @@ public:

attribute_list() = default;

attribute_list(std::initializer_list<attribute> list);
attribute_list(attribute attr); // NOLINT *-explicit-constructor
attribute_list(attribute attr); // NOLINT(*explicit*)
attribute_list(attribute_list attrs, std::initializer_list<attribute> list);

void set(const attribute_list& list);

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

@@ -37,7 +37,8 @@ public:


template<std::ranges::forward_range R>
element transform(
const R& range, based::Procedure<std::ranges::range_value_t<R>> auto proc
const R& range,
based::Procedure<element, std::ranges::range_value_t<R>> auto proc
)
{
std::vector<element> res;

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

@@ -35,6 +35,20 @@ class HEMPLATE_EXPORT element_base

using child_t = std::variant<element_base, std::string>;
std::vector<child_t> m_cdn;

void add(const std::ranges::forward_range auto& range)
requires(!std::constructible_from<std::string_view, decltype(range)>)
{
m_cdn.reserve(std::size(m_cdn) + std::size(range));
m_cdn.insert(std::end(m_cdn), std::begin(range), std::end(range));
}

void add(const std::string_view data)
{
m_cdn.emplace_back(std::string(data));
}

void add(const element_base& elem) { m_cdn.emplace_back(elem); }

template<typename... Args>
explicit element_base(
std::string_view open_tag, std::string_view close_tag, Args&&... args

@@ -42,23 +56,6 @@ class HEMPLATE_EXPORT element_base

: m_otag(open_tag)
, m_ctag(close_tag)
{
const auto add = based::overload {
[this](const std::ranges::forward_range auto& range)
requires(!std::constructible_from<std::string_view, decltype(range)>)
{
m_cdn.reserve(std::size(m_cdn) + std::size(range));
m_cdn.insert(std::end(m_cdn), std::begin(range), std::end(range));
},
[this](const std::string_view data)
{
m_cdn.emplace_back(std::string(data));
},
[this](const element_base& elem)
{
m_cdn.emplace_back(elem);
},
};

m_cdn.reserve(sizeof...(args));
(add(std::forward<Args>(args)), ...);
}

@@ -105,7 +102,9 @@ public:

return ss.str();
}

friend std::ostream& operator<<(std::ostream& out, const element_base& element)
friend std::ostream& operator<<(
std::ostream& out, const element_base& element
)
{
element.render(out, 0);
return out;

@@ -117,7 +116,7 @@ class HEMPLATE_EXPORT element : public element_base

public:
template<typename... Args>
requires(!std::same_as<attribute_list, std::remove_cvref_t<Args>> && ...)
element(Args&&... args) // NOLINT *-explicit
element(Args&&... args) // NOLINT(*explicit*)
: element_base("", "", std::forward<Args>(args)...)
{
}

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

@@ -20,7 +20,7 @@ public:

};

// clang-format off
// NOLINTBEGIN *-identifier-naming
// NOLINTBEGIN(*naming*)
using abbr = element_boolean<"abbr">;
using address = element_boolean<"address">;
using a = element_boolean<"a">;

@@ -134,7 +134,7 @@ using param = element_atomic<"param">;

using source = element_atomic<"source">;
using track = element_atomic<"track">;
using wbr = element_atomic<"wbr">;
// NOLINTEND *-identifier-naming
// NOLINTEND(*naming*)
// clang-format on

} // namespace hemplate::html

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

@@ -38,7 +38,7 @@ public:

}
};

class HEMPLATE_EXPORT atomLink // NOLINT *-identifier-naming
class HEMPLATE_EXPORT atomLink // NOLINT(*naming*)
: public element_boolean<"atom:link">
{
static auto attributes(

@@ -94,7 +94,7 @@ using hemplate::transform;

using hemplate::xml;

// clang-format off
// NOLINTBEGIN *-identifier-naming
// NOLINTBEGIN(*naming*)
using author = element_boolean<"author">;
using category = element_boolean<"category">;
using channel = element_boolean<"channel">;

@@ -126,7 +126,7 @@ using width = element_boolean<"width">;


using cloud = element_atomic<"cloud">;
using enclosure = element_atomic<"enclosure">;
// NOLINTEND *-identifier-naming
// NOLINTEND(*naming*)
// clang-format on

} // namespace hemplate::rss

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

@@ -27,7 +27,7 @@ public:


template<typename... Args>
explicit urlset(Args&&... args)
: element_boolean(attribute(def_xmlns), std::forward<Args>(args)...)
: element_boolean(attributes(def_xmlns), std::forward<Args>(args)...)
{
}
};

@@ -38,13 +38,13 @@ using hemplate::transform;

using hemplate::xml;

// clang-format off
// NOLINTBEGIN *-identifier-naming
// NOLINTBEGIN(*naming*)
using changefreq = element_boolean<"changefreq">;
using lastmod = element_boolean<"lastmod">;
using loc = element_boolean<"loc">;
using url = element_boolean<"url">;
using priority = element_boolean<"priority">;
// NOLINTEND *-identifier-naming
// NOLINTEND(*naming*)
// clang-format on

} // namespace hemplate::sitemap

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

@@ -2,7 +2,7 @@


#include <catch2/catch_test_macros.hpp>

// NOLINTBEGIN readability-container-size-empty
// NOLINTBEGIN(*readability-container-size-empty*)

TEST_CASE("set class", "[attribute_list]")
{

@@ -89,4 +89,4 @@ TEST_CASE("add", "[attribute_list]")

REQUIRE(std::string(attrs) == R"(class="first second third")");
}

// NOLINTEND readability-container-size-empty
// NOLINTEND(*readability-container-size-empty*)