diff options
-rw-r--r-- | ctimeline.c | 30 | ||||
-rw-r--r-- | ui-common.c | 83 | ||||
-rw-r--r-- | ui-common.h | 10 |
3 files changed, 93 insertions, 30 deletions
diff --git a/ctimeline.c b/ctimeline.c index 6259433..c6f99d5 100644 --- a/ctimeline.c +++ b/ctimeline.c @@ -53,35 +53,6 @@ void sort_branches_by_age() } } -void emit_timeline_html() -{ - int i; - struct branch *ptr; - - printf("<ul class=\"timeline\">\n"); - - for(i = 0; i < branches.count; i++) { - ptr = &branches.list[i]; - printf( - "<li>\n" - " <div class=\"direction-%s\">\n" - " <div class=\"flag-wrapper\">\n" - " <span class=\"flag\">%s</span>\n" - " <span class=\"time-wrapper\"><span class=\"time\">%d-%d</span></span>\n" - " </div>\n" - " <div class=\"desc\">%s</div>\n" - " </div>\n" - "</li>\n", - (i % 2) ? "left" : "right", ptr->name->s, - ptr->age_from, ptr->age_to, ptr->desc->s); - string_release(ptr->name); - string_release(ptr->desc); - } - - printf("</ul>\n"); -} - - struct ctimeline_branch *add_branch(const char *name) { struct ctimeline_branch *br; @@ -226,7 +197,6 @@ int main(int argc, char **argv) "" "<body>\n" "<br>\n"); - emit_timeline_html(); printf("<br>\n" "</body>\n" "</html>\n"); diff --git a/ui-common.c b/ui-common.c new file mode 100644 index 0000000..66ad5f7 --- /dev/null +++ b/ui-common.c @@ -0,0 +1,83 @@ +#include <stdio.h> + +#include "ui-common.h" +#include "ctimeline.h" + +void print_http_headers() +{ + printf("Content-type: text/html\n"); + printf("\n"); +} + +void print_document_start() +{ + printf("<html>\n"); + printf("<head>\n"); + printf("<title>%s</title>\n", ctx.head_title); + printf("<link rel='stylesheet' href='%s'>\n", ctx.css); + printf("</head>\n"); + printf("</body>\n"); +} + +void print_document_header() +{ + printf("<div id='ctimeline'>\n"); + printf("<header>\n"); + printf("<table>\n"); + + printf("<tr>\n"); + printf( + "<td><p class='header'>%s</p></td>\n", ctx.header_title); + printf("</tr>\n"); + + printf("<tr class='sub_text'>\n"); + printf( + "<td>%s</td>\n", ctx.header_desc); + printf("</tr>\n"); + + printf("</table>\n"); + printf("</header>\n"); +} + +void print_timelines() +{ + if(ctx.branches.count <= 0) + return; + + int i; + struct ctimeline_branch *br; + + printf("<ul class='timeline'>\n"); + + for(i = 0; i < ctx.branches.count; i++) { + br = &ctx.branches.list[i]; + printf( + "<li>\n" + " <div class='direction-%s'>\n" + " <div class='flag-wrapper'>\n" + " <span class='flag'>%s</span>\n" + " <span class='time-wrapper'><span class='time'>%d-%d</span></span>\n" + " </div>\n" + " <div class='desc'>%s</div>\n" + " </div>\n" + "</li>\n", + (i % 2) ? "left" : "right", br->name->s, + br->age_from, br->age_to, br->desc->s); + string_release(br->name); + string_release(br->desc); + } + + printf("</ul>\n"); +} + +void print_document_end() +{ + printf("<footer class='footer'>\n"); + printf( + "<p>generated by <a href='http://git.joursoir.net/ctimeline'>" + "ctimeline v%s</a></p>\n", CTIMELINE_VERSION); + printf("</footer>\n"); + printf("</div>\n"); // <!-- id='ctimeline' --> + printf("</body>\n"); + printf("</html>\n"); +} diff --git a/ui-common.h b/ui-common.h new file mode 100644 index 0000000..efa509e --- /dev/null +++ b/ui-common.h @@ -0,0 +1,10 @@ +#ifndef CTIMELINE_UI_COMMON_H +#define CTIMELINE_UI_COMMON_H + +void print_http_headers(); +void print_document_start(); +void print_document_header(); +void print_timelines(); +void print_document_end(); + +#endif /* CTIMELINE_UI_COMMON_H */ |