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,32 +89,39 @@ void UserController::handle_login_request_default(Request *request) {
b.w("Login"); b.w("Login");
b.br(); b.br();
if (error_str.size() != 0) { {
b.div()->cls("error"); if (error_str.size() != 0) {
b.div()->cls("error");
b.w(error_str); b.w(error_str);
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.br(); b.w("Username");
b.input()->type("text")->name("username")->value(uname_val); b.br();
b.cinput(); b.input()->type("text")->name("username")->value(uname_val);
b.br(); b.cinput();
b.w("Password"); b.br();
b.br();
b.input()->type("password")->name("password");
b.cinput();
b.br();
b.input()->type("submit")->value("Send");
b.cinput();
b.cform();
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(); 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.br(); b.w("Registration successful! You can now log in!");
b.a()->href("/user/login"); b.br();
b.w(">> Login <<"); b.a()->href("/user/login");
b.ca(); b.w(">> Login <<");
b.ca();
}
b.cdiv(); b.cdiv();
request->body += b.result; request->body += b.result;
@ -193,47 +202,50 @@ void UserController::handle_register_request_default(Request *request) {
b.w("Registration"); b.w("Registration");
b.br(); b.br();
if (error_str.size() != 0) { {
b.div()->cls("error"); if (error_str.size() != 0) {
b.div()->cls("error");
b.w(error_str); b.w(error_str);
b.cdiv(); b.cdiv();
}
} }
b.div()->cls("register"); 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);
b.cinput();
b.br();
//todo href path helper b.w("Email");
b.form()->method("POST")->href("/user/register"); b.br();
b.input()->type("email")->name("email")->value(email_val);
b.cinput();
b.br();
b.w("Username"); b.w("Password");
b.br(); b.br();
b.input()->type("text")->name("username")->value(uname_val); b.input()->type("password")->name("password");
b.cinput(); b.cinput();
b.br(); b.br();
b.w("Email");
b.br();
b.input()->type("email")->name("email")->value(email_val);
b.cinput();
b.br();
b.w("Password");
b.br();
b.input()->type("password")->name("password");
b.cinput();
b.br();
b.w("Password again");
b.br();
b.input()->type("password")->name("password_check");
b.cinput();
b.br();
b.input()->type("submit")->value("Register");
b.cinput();
b.cform();
b.w("Password again");
b.br();
b.input()->type("password")->name("password_check");
b.cinput();
b.br();
b.input()->type("submit")->value("Register");
b.cinput();
}
b.cform();
}
b.cdiv(); b.cdiv();
request->body += b.result; request->body += b.result;
@ -352,47 +364,50 @@ 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) { {
b.div()->cls("error"); if (error_str.size() != 0) {
b.div()->cls("error");
b.w(error_str); b.w(error_str);
b.cdiv(); b.cdiv();
}
} }
b.div()->cls("settings"); 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);
b.cinput();
b.br();
//todo href path helper b.w("Email");
b.form()->method("POST")->href("/user/settings"); b.br();
b.input()->type("email")->name("email")->placeholder(user->email_user_input)->value(email_val);
b.cinput();
b.br();
b.w("Username"); b.w("Password");
b.br(); b.br();
b.input()->type("text")->name("username")->placeholder(user->name_user_input)->value(uname_val); b.input()->type("password")->placeholder("*******")->name("password");
b.cinput(); b.cinput();
b.br(); b.br();
b.w("Email"); b.w("Password again");
b.br(); b.br();
b.input()->type("email")->name("email")->placeholder(user->email_user_input)->value(email_val); b.input()->type("password")->placeholder("*******")->name("password_check");
b.cinput(); b.cinput();
b.br(); b.br();
b.w("Password");
b.br();
b.input()->type("password")->placeholder("*******")->name("password");
b.cinput();
b.br();
b.w("Password again");
b.br();
b.input()->type("password")->placeholder("*******")->name("password_check");
b.cinput();
b.br();
b.input()->type("submit")->value("Save");
b.cinput();
b.cform();
b.input()->type("submit")->value("Save");
b.cinput();
}
b.cform();
}
b.cdiv(); b.cdiv();
request->body += b.result; request->body += b.result;