author | Lars Hjemli <hjemli@gmail.com> | 2007-10-30 09:47:38 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-30 12:38:34 (UTC) |
commit | 0c8e184e9cbf4d3a1e907de9125f6d8210c169d6 (patch) (unidiff) | |
tree | 2e82baf582b7ba0b34f498e1e7494800070067f9 /shared.c | |
parent | 10ac7ad1f30f914dc5ff36ba3651ef6dca11aaf7 (diff) | |
download | cgit-0c8e184e9cbf4d3a1e907de9125f6d8210c169d6.zip cgit-0c8e184e9cbf4d3a1e907de9125f6d8210c169d6.tar.gz cgit-0c8e184e9cbf4d3a1e907de9125f6d8210c169d6.tar.bz2 |
Change the cgit layout
This modifies and hopefully improves the layout of all cgit pages:
* Remove the header from all pages and replace it with a sidebar;
most pages have sufficient width but many needs more height.
* Add a dropdown-box to switch between branches, using a one-liner
javascript to reload the current page in context of the selected branch.
* Include refs found below refs/archives in the sidebar, appearing as a
set of menuitems below a 'download' heading.
* Include the brand new cgit logo
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | shared.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -282,48 +282,79 @@ int hextoint(char c) | |||
282 | } | 282 | } |
283 | 283 | ||
284 | char *trim_end(const char *str, char c) | 284 | char *trim_end(const char *str, char c) |
285 | { | 285 | { |
286 | int len; | 286 | int len; |
287 | char *s, *t; | 287 | char *s, *t; |
288 | 288 | ||
289 | if (str == NULL) | 289 | if (str == NULL) |
290 | return NULL; | 290 | return NULL; |
291 | t = (char *)str; | 291 | t = (char *)str; |
292 | len = strlen(t); | 292 | len = strlen(t); |
293 | while(len > 0 && t[len - 1] == c) | 293 | while(len > 0 && t[len - 1] == c) |
294 | len--; | 294 | len--; |
295 | 295 | ||
296 | if (len == 0) | 296 | if (len == 0) |
297 | return NULL; | 297 | return NULL; |
298 | 298 | ||
299 | c = t[len]; | 299 | c = t[len]; |
300 | t[len] = '\0'; | 300 | t[len] = '\0'; |
301 | s = xstrdup(t); | 301 | s = xstrdup(t); |
302 | t[len] = c; | 302 | t[len] = c; |
303 | return s; | 303 | return s; |
304 | } | 304 | } |
305 | 305 | ||
306 | char *strlpart(char *txt, int maxlen) | ||
307 | { | ||
308 | char *result; | ||
309 | |||
310 | if (!txt) | ||
311 | return txt; | ||
312 | |||
313 | if (strlen(txt) <= maxlen) | ||
314 | return txt; | ||
315 | result = xmalloc(maxlen + 1); | ||
316 | memcpy(result, txt, maxlen - 3); | ||
317 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; | ||
318 | result[maxlen] = '\0'; | ||
319 | return result; | ||
320 | } | ||
321 | |||
322 | char *strrpart(char *txt, int maxlen) | ||
323 | { | ||
324 | char *result; | ||
325 | |||
326 | if (!txt) | ||
327 | return txt; | ||
328 | |||
329 | if (strlen(txt) <= maxlen) | ||
330 | return txt; | ||
331 | result = xmalloc(maxlen + 1); | ||
332 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); | ||
333 | result[0] = result[1] = result[2] = '.'; | ||
334 | return result; | ||
335 | } | ||
336 | |||
306 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) | 337 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
307 | { | 338 | { |
308 | size_t size; | 339 | size_t size; |
309 | 340 | ||
310 | if (list->count >= list->alloc) { | 341 | if (list->count >= list->alloc) { |
311 | list->alloc += (list->alloc ? list->alloc : 4); | 342 | list->alloc += (list->alloc ? list->alloc : 4); |
312 | size = list->alloc * sizeof(struct refinfo *); | 343 | size = list->alloc * sizeof(struct refinfo *); |
313 | list->refs = xrealloc(list->refs, size); | 344 | list->refs = xrealloc(list->refs, size); |
314 | } | 345 | } |
315 | list->refs[list->count++] = ref; | 346 | list->refs[list->count++] = ref; |
316 | } | 347 | } |
317 | 348 | ||
318 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) | 349 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
319 | { | 350 | { |
320 | struct refinfo *ref; | 351 | struct refinfo *ref; |
321 | 352 | ||
322 | ref = xmalloc(sizeof (struct refinfo)); | 353 | ref = xmalloc(sizeof (struct refinfo)); |
323 | ref->refname = xstrdup(refname); | 354 | ref->refname = xstrdup(refname); |
324 | ref->object = parse_object(sha1); | 355 | ref->object = parse_object(sha1); |
325 | switch (ref->object->type) { | 356 | switch (ref->object->type) { |
326 | case OBJ_TAG: | 357 | case OBJ_TAG: |
327 | ref->tag = cgit_parse_tag((struct tag *)ref->object); | 358 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
328 | break; | 359 | break; |
329 | case OBJ_COMMIT: | 360 | case OBJ_COMMIT: |