rumal (রুমাল)¶
rumal (রুমাল) is a tiny header only single file HTML/CSS generator C++ library.
Composing HTML/CSS fragments do not involve any heap memory allocation. Both HTML and CSS blocks can be nested. An HTML block refers to an HTML tag whereas a CSS block refers to a CSS declarations block. Nesting a CSS block inside another results into nested CSS declaration.
Basic Example¶
#include <iostream>
#include <rumal/rumal.hpp>
int main(int argc, char **argv){
using namespace rumal::html::attrs;
using namespace rumal::html::tags;
using namespace rumal::css;
using namespace rumal::css::props;
std::cout << div(_id(42) / _class("test"),
span(_id(43) / _class("test"), "Hello"),
span("World")
) << std::endl;
std::cout << select(".heading",
position("relative") /
display("block"),
) << std::endl;
return 0;
}
Nested CSS¶
using namespace rumal::css;
using namespace rumal::css::props;
select(".main",
display("block")
/ position("relative"),
select(".heading",
display("block")
/ position("relative")
)
) / select(".container",
display("block")
/ position("relative")
);
The above example produces the following CSS.
.container{
position: relative;
display: block;
}
.main{
position: relative;
display: block;
}
.main > .heading{
position: relative;
display: block;
}
HTML Tag¶
To declare HTML tags use the macro DEFINE_HTML_TAG
namespace rumal{
namespace html{
namespace tags{
DEFINE_HTML_TAG(div)
}
}
}
The above example will declare a tag named div. The macro results into two function overloads named div
HTML Attributes¶
HTML attributes are declared through two macros DEFINE_HTML_ATTRIBUTE and DEFINE_LABELED_HTML_ATTRIBUTE
namespace rumal{
namespace html{
namespace attrs{
DEFINE_HTML_ATTRIBUTE(id)
DEFINE_LABELED_HTML_ATTRIBUTE(klass, "class")
}
}
}
The above results into the following functions
Use DEFINE_HTML_ATTRIBUTE to define attributes that do not conflict with C++ keywords or existing functions. Use DEFINE_LABELED_HTML_ATTRIBUTE when there is a conflict (e.g. class). Or use html::attr(“attribute_name”, value); directly