Use scopes to make HTML builder code indented for better visibility. I wanted to create a simple templating engine, but I think this makes that idea obsolete, and unnecessary.

This commit is contained in:
Relintai 2021-10-25 09:58:00 +02:00
parent 74389bb71c
commit e61bc79af5

View File

@ -89,6 +89,7 @@ void UserController::handle_login_request_default(Request *request) {
b.w("Login");
b.br();
{
if (error_str.size() != 0) {
b.div()->cls("error");
@ -96,25 +97,31 @@ void UserController::handle_login_request_default(Request *request) {
b.cdiv();
}
}
b.div()->cls("login");
{
//todo href path helper
b.form()->method("POST")->href("/user/login");
{
b.w("Username");
b.br();
b.input()->type("text")->name("username")->value(uname_val);
b.cinput();
b.br();
b.w("Password");
b.br();
b.input()->type("password")->name("password");
b.cinput();
b.br();
b.input()->type("submit")->value("Send");
b.cinput();
}
b.cform();
}
b.cdiv();
request->body += b.result;
@ -174,11 +181,13 @@ void UserController::handle_register_request_default(Request *request) {
HTMLBuilder b;
b.div()->cls("success");
{
b.w("Registration successful! You can now log in!");
b.br();
b.a()->href("/user/login");
b.w(">> Login <<");
b.ca();
}
b.cdiv();
request->body += b.result;
@ -193,6 +202,7 @@ void UserController::handle_register_request_default(Request *request) {
b.w("Registration");
b.br();
{
if (error_str.size() != 0) {
b.div()->cls("error");
@ -200,12 +210,13 @@ void UserController::handle_register_request_default(Request *request) {
b.cdiv();
}
}
b.div()->cls("register");
{
//todo href path helper
b.form()->method("POST")->href("/user/register");
{
b.w("Username");
b.br();
b.input()->type("text")->name("username")->value(uname_val);
@ -232,8 +243,9 @@ void UserController::handle_register_request_default(Request *request) {
b.input()->type("submit")->value("Register");
b.cinput();
}
b.cform();
}
b.cdiv();
request->body += b.result;
@ -352,6 +364,7 @@ void UserController::handle_settings_request(Ref<User> &user, Request *request)
b.w("Settings");
b.br();
{
if (error_str.size() != 0) {
b.div()->cls("error");
@ -359,12 +372,13 @@ void UserController::handle_settings_request(Ref<User> &user, Request *request)
b.cdiv();
}
}
b.div()->cls("settings");
{
//todo href path helper
b.form()->method("POST")->href("/user/settings");
{
b.w("Username");
b.br();
b.input()->type("text")->name("username")->placeholder(user->name_user_input)->value(uname_val);
@ -391,8 +405,9 @@ void UserController::handle_settings_request(Ref<User> &user, Request *request)
b.input()->type("submit")->value("Save");
b.cinput();
}
b.cform();
}
b.cdiv();
request->body += b.result;