hemplate

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

commit 41d951b84e20292564864a236ce056874123adf7
parent d25af86820fd01efb12416de44c93554d8a15321
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 22 Jun 2024 23:02:35 +0200

Add initializer_list constructor to attributeList

Diffstat:
MCMakeLists.txt | 2+-
Minclude/hemplate/attribute.hpp | 11+++++++++++
Mtest/source/hemplate_test.cpp | 8++++----
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -4,7 +4,7 @@ include(cmake/prelude.cmake) project( hemplate - VERSION 0.1.3 + VERSION 0.1.4 DESCRIPTION "Simple HTML template engine" HOMEPAGE_URL "https://git.dimitrijedobrota.com/hemplate.git" LANGUAGES CXX diff --git a/include/hemplate/attribute.hpp b/include/hemplate/attribute.hpp @@ -1,6 +1,7 @@ #pragma once #include <string> +#include <utility> #include <vector> #include "hemplate/hemplate_export.hpp" @@ -56,6 +57,16 @@ public: attributeList& operator=(attributeList&&) = default; ~attributeList() override = default; + attributeList(std::initializer_list<attribute> list) + : m_attributes(list) + { + } + + attributeList(attribute attr) // NOLINT + : m_attributes({std::move(attr)}) + { + } + attributeList& set(const std::string& name); attributeList& set(const std::string& name, const std::string& value); diff --git a/test/source/hemplate_test.cpp b/test/source/hemplate_test.cpp @@ -6,12 +6,12 @@ int main() { using namespace hemplate; // NOLINT - attributeList li_attrs; - li_attrs.set("class", "main_li"); + const attributeList ul_attrs({{"id", "main_ul"}, {"class", "home_ul"}}); + const attributeList li_attrs({"class", "home_li"}); std::cout << html() << std::endl; - std::cout << ul("Won't see") - .set("id", "main_ul") + std::cout << ul("Won't see", ul_attrs) + .set("style", "margin-top: 1em;") .add(li("Item 1", li_attrs)) .add(li("Item 2", li_attrs)) << std::endl;