migrate minor elements from gotweb_ui.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 775715a..e4641cc 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -530,7 +530,8 @@ gw_index(struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
struct gw_dir *gw_dir = NULL;
- char *html, *navs, *next, *prev;
+ char *html, *navs;
+ char *href_next = NULL, *href_prev = NULL;
unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
enum kcgi_err kerr;
@@ -597,14 +598,24 @@ gw_index(struct gw_trans *gw_trans)
continue;
if (next_disp == gw_trans->gw_conf->got_max_repos_display) {
- kerr = khttp_puts(gw_trans->gw_req, np_wrapper_start);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+ KATTR_ID, "np_wrapper", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+ KATTR_ID, "nav_prev", KATTR__MAX);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
} else if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
(gw_trans->page > 0) &&
(next_disp == gw_trans->gw_conf->got_max_repos_display ||
prev_disp == gw_trans->repos_total)) {
- kerr = khttp_puts(gw_trans->gw_req, np_wrapper_start);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+ KATTR_ID, "np_wrapper", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+ KATTR_ID, "nav_prev", KATTR__MAX);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
}
@@ -613,15 +624,23 @@ gw_index(struct gw_trans *gw_trans)
(gw_trans->page > 0) &&
(next_disp == gw_trans->gw_conf->got_max_repos_display ||
prev_disp == gw_trans->repos_total)) {
- if (asprintf(&prev, nav_prev, gw_trans->page - 1) == -1)
+ if (asprintf(&href_prev, "?page=%d",
+ gw_trans->page - 1) == -1)
return got_error_from_errno("asprintf");
- kerr = khttp_puts(gw_trans->gw_req, prev);
- free(prev);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
+ KATTR_HREF, href_prev, KATTR__MAX);
+ free(href_prev);
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
+ kerr = khtml_puts(gw_trans->gw_html_req, "Previous");
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
+ kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
}
- kerr = khttp_puts(gw_trans->gw_req, div_end);
+ kerr = khtml_closeelem(gw_trans->gw_html_req, 1);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
@@ -629,15 +648,24 @@ gw_index(struct gw_trans *gw_trans)
next_disp == gw_trans->gw_conf->got_max_repos_display &&
dir_c != (gw_trans->page + 1) *
gw_trans->gw_conf->got_max_repos_display) {
- if (asprintf(&next, nav_next, gw_trans->page + 1) == -1)
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
+ KATTR_ID, "nav_next", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
+ if (asprintf(&href_next, "?page=%d",
+ gw_trans->page + 1) == -1)
return got_error_from_errno("calloc");
- kerr = khttp_puts(gw_trans->gw_req, next);
- free(next);
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_A,
+ KATTR_HREF, href_next, KATTR__MAX);
+ free(href_next);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
- kerr = khttp_puts(gw_trans->gw_req, div_end);
+ kerr = khtml_puts(gw_trans->gw_html_req, "Next");
if (kerr != KCGI_OK)
- error = gw_kcgi_error(kerr);
+ return gw_kcgi_error(kerr);
+ kerr = khtml_closeelem(gw_trans->gw_html_req, 3);
+ if (kerr != KCGI_OK)
+ return gw_kcgi_error(kerr);
next_disp = 0;
break;
}
@@ -646,7 +674,7 @@ gw_index(struct gw_trans *gw_trans)
(gw_trans->page > 0) &&
(next_disp == gw_trans->gw_conf->got_max_repos_display ||
prev_disp == gw_trans->repos_total)) {
- kerr = khttp_puts(gw_trans->gw_req, div_end);
+ kerr = khtml_closeelem(gw_trans->gw_html_req, 2);
if (kerr != KCGI_OK)
return gw_kcgi_error(kerr);
}
@@ -1711,7 +1739,28 @@ gw_template(size_t key, void *arg)
}
break;
case (TEMPL_SEARCH):
- kerr = khttp_puts(gw_trans->gw_req, search);
+ break;
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV, KATTR_ID,
+ "search", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return 0;
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_FORM,
+ KATTR_METHOD, "POST", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return 0;
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_INPUT, KATTR_ID,
+ "got-search", KATTR_NAME, "got-search", KATTR_SIZE, "15",
+ KATTR_MAXLENGTH, "50", KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return 0;
+ kerr = khtml_attr(gw_trans->gw_html_req, KELEM_BUTTON,
+ KATTR__MAX);
+ if (kerr != KCGI_OK)
+ return 0;
+ kerr = khtml_puts(gw_trans->gw_html_req, "Search");
+ if (kerr != KCGI_OK)
+ return 0;
+ kerr = khtml_closeelem(gw_trans->gw_html_req, 4);
if (kerr != KCGI_OK)
return 0;
break;
diff --git a/gotweb/gotweb_ui.h b/gotweb/gotweb_ui.h
index 65fb5fc..6847a56 100644
--- a/gotweb/gotweb_ui.h
+++ b/gotweb/gotweb_ui.h
@@ -17,37 +17,6 @@
#ifndef GOTWEB_UI_H
#define GOTWEB_UI_H
-/* general html */
-
-char *site_link =
- "<div id='site_link'>" \
- "<a href='%s'>%s</a> %s %s" \
- "</div>";
-
-char *search =
- "<!--/* <div id='search'>" \
- "<form method='POST'>" \
- "<input type='search' id='got-search' name='got-search' size='15'" \
- " maxlength='50' />" \
- "<button>Search</button>" \
- "</form>" \
- "</div> */-->";
-
-char *np_wrapper_start =
- "<div id='np_wrapper'>" \
- "<div id='nav_prev'>";
-
-char *div_end =
- "</div>";
-
-char *nav_next =
- "<div id='nav_next'>" \
- "<a href='?page=%d'>Next<a/>" \
- "</div>";
-
-char *nav_prev =
- "<a href='?page=%d'>Previous<a/>";
-
/* index.tmpl */
char *index_projects_header =