]> gitweb.ps.run Git - chirp/blobdiff - src/main.zig
add ability to specify tag type to html_form
[chirp] / src / main.zig
index 9411261cd4c4f1abe2f012bcb411decee04ee42c..164606f245754a94d5998a779833f42b3d715783 100644 (file)
@@ -509,10 +509,16 @@ fn html_form(res: *http.Response, action: []const u8, inputs: anytype) !void {
 
     inline for (inputs) |input| {
         switch (@typeInfo(@TypeOf(input))) {
-            .Struct => {
-                try res.write("<input ", .{});
-                try res.write(input[0], input[1]);
-                try res.write(" />", .{});
+            .Struct => |s| {
+                if (s.fields.len == 3) {
+                    try res.write("<{s} ", .{input[0]});
+                    try res.write(input[1], input[2]);
+                    try res.write("></{s}>", .{input[0]});
+                } else {
+                    try res.write("<input ", .{});
+                    try res.write(input[0], input[1]);
+                    try res.write(" />", .{});
+                }
             },
             else => {
                 try res.write("<input ", .{});
@@ -699,8 +705,8 @@ fn write_post(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_id: Po
             try res.write("<option value=\"{x}\">{s}{s}</option>", .{ id, name.constSlice(), if (list_view.has(post_id) catch false) " *" else "" });
         }
         try res.write("</select>", .{});
-        try res.write("<input type=\"hidden\" name=\"post_id\" value=\"{x}\"></input>", .{@intFromEnum(post_id)});
-        try res.write("<input type=\"submit\" value=\"Save\"></input>", .{});
+        try res.write("<input type=\"hidden\" name=\"post_id\" value=\"{x}\" />", .{@intFromEnum(post_id)});
+        try res.write("<input type=\"submit\" value=\"Save\" />", .{});
         try res.write("</form>", .{});
     }
 
@@ -780,8 +786,8 @@ fn write_profile(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user: Us
             try res.write("<option value=\"{x}\">{s}{s}</option>", .{ id, name.constSlice(), if (list_view.has(user.id) catch false) " *" else "" });
         }
         try res.write("</select>", .{});
-        try res.write("<input type=\"hidden\" name=\"user_id\" value=\"{x}\"></input>", .{@intFromEnum(user.id)});
-        try res.write("<input type=\"submit\" value=\"Add to feed\"></input>", .{});
+        try res.write("<input type=\"hidden\" name=\"user_id\" value=\"{x}\" />", .{@intFromEnum(user.id)});
+        try res.write("<input type=\"submit\" value=\"Add to feed\" />", .{});
         try res.write("</form>", .{});
     }
     try res.write(
@@ -1265,7 +1271,7 @@ const GET = struct {
             });
             try self.res.write("<br />Description: ", .{});
             try html_form(self.res, "/set_description", .{
-                .{ "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
+                .{ "textarea", "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
                 "type=\"submit\" value=\"Change\"",
             });
             try self.res.write("<br />Password: ", .{});