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