hemplate

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

attribute.cpp (1124B)


0 #include "hemplate/attribute.hpp"
2 namespace hemplate
3 {
5 attribute& attribute::append(std::string_view delim, const std::string& val)
6 {
7 if (!val.empty()) {
8 if (!empty()) {
9 m_value += std::string(delim);
10 }
11 m_value += val;
12 }
13 return *this;
14 }
16 attribute_list::attribute_list(std::initializer_list<attribute> list)
17 {
18 for (const auto& attr : list) {
19 set(attr);
20 }
21 }
23 attribute_list::attribute_list(attribute attr)
24 {
25 set(std::move(attr));
26 }
28 attribute_list::attribute_list(
29 attribute_list attrs, std::initializer_list<attribute> list
30 )
31 : attribute_list(std::move(attrs))
32 {
33 for (const auto& attr : list) {
34 set(attr);
35 }
36 }
38 void attribute_list::set(const attribute_list& list)
39 {
40 for (const auto& attr : list.m_attributes) {
41 set(attr);
42 }
44 set(list.m_class);
45 set(list.m_style);
46 }
48 void attribute_list::set(attribute attr)
49 {
50 if (attr.name() == "class") {
51 m_class.append(" ", attr.value());
52 return;
53 }
55 if (attr.name() == "style") {
56 m_style.append("; ", attr.value());
57 return;
58 }
60 m_attributes.emplace_back(std::move(attr));
61 }
63 } // namespace hemplate