add odd/even class for table coloring
authorChristian Thaeter <ct@pipapo.org>
Thu, 24 Jan 2008 14:42:52 +0000 (15:42 +0100)
committerChristian Thaeter <ct@pipapo.org>
Thu, 24 Jan 2008 14:42:52 +0000 (15:42 +0100)
src/actions.c
src/branch.c
src/log.c
src/tag.c

index f6790cb..8b45ef6 100644 (file)
@@ -77,6 +77,8 @@ webgit_main_content_action (struct webgit_query* query)
                           )
               );
 
+  int row = 0;
+
   LLIST_FOREACH (&query->repos, node)
     {
       struct webgit_repo_info* n = (struct webgit_repo_info*)node;
@@ -86,12 +88,9 @@ webgit_main_content_action (struct webgit_query* query)
       if (n->age < n->maxage)
         {
           html_list_append (table, html (
-                                         /*
-                                           TODO:
-                                           It would be great to have alternate rows with class="odd" or class="even"
-                                           html_tag ("tr", html_attr ("class", "odd")),
-                                         */
-                                         html_tag ("tr"),
+                                         html_tag ("tr",
+                                                   html_attr ("class", (++row & 1) ? "odd" : "even")
+                                                   ),
                                          html(html_tag ("td"),
                                               webgit_summary_link (query, n, html (n->name))),
                                          html(html_tag ("td"), n->url ?
index 5e403fd..de70617 100644 (file)
@@ -37,6 +37,7 @@ struct branch_context
   Html cont;
   const char* start;
   int count;
+  int row;
 };
 
 Html
@@ -94,7 +95,9 @@ show_branch_ref (const char *refname, const unsigned char *sha1, int flags, void
 
   html_list_append (ctx->table,
                     html (
-                          html_tag ("tr"),
+                          html_tag ("tr",
+                                    html_attr ("class", (++ctx->row & 1) ? "odd" : "even")
+                                    ),
                           html (
                                 html_tag ("td"),
                                 webgit_log_link (repo->query,
@@ -153,6 +156,7 @@ webgit_branch_table (struct webgit_repo_info* repo, const char* head, int count)
   ctx.cont = html_list ();
   ctx.count = count;
   ctx.start = head;
+  ctx.row = 0;
 
   for_each_branch_ref (show_branch_ref, &ctx);
 
index 6588b6d..3d574a3 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -81,6 +81,7 @@ webgit_log_table (struct webgit_query* query, const char* object, int count, int
 
   Html table = html_list ();
   Html cont = html_list ();
+  int row = 0;
 
   struct commit *commit;
   while ((commit = get_revision (&rev)))
@@ -112,10 +113,14 @@ webgit_log_table (struct webgit_query* query, const char* object, int count, int
       char pretty_date[256];
       strftime (pretty_date, 255, "%c", &tm);
 
+      ++row;
+
       html_list_append (table,
                         html (
                               html (
-                                    html_tag ("tr"),
+                                    html_tag ("tr",
+                                              html_attr ("class", (row & 1) ? "odd" : "even")
+                                              ),
                                     html(html_tag ("td"),
                                          html_strndup (pretty_date, 254)
                                          ),
@@ -132,7 +137,9 @@ webgit_log_table (struct webgit_query* query, const char* object, int count, int
                                          )
                                     ),
                               html (
-                                    html_tag ("tr"),
+                                    html_tag ("tr",
+                                              html_attr ("class", (row & 1) ? "odd" : "even")
+                                              ),
                                     html(html_tag ("td"),
                                          webgit_email_link (
                                                             webgit_object_commit_author_name_parse (commit),
@@ -161,7 +168,9 @@ webgit_log_table (struct webgit_query* query, const char* object, int count, int
       if (msg_flag)
         html_list_append (table,
                           html (
-                                html_tag ("tr"),
+                                html_tag ("tr",
+                                          html_attr ("class", (row & 1) ? "odd" : "even")
+                                          ),
                                 html(html_tag ("td", html_attr ("colspan", "2")),
                                      html(html_tag ("pre"),
                                           webgit_object_commit_message_parse (commit)
index c927e5c..9bdfd0e 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -40,6 +40,7 @@ struct tag_context
   Html cont;
   const char* start;
   int count;
+  int row;
 };
 
 
@@ -110,7 +111,9 @@ show_tag_ref (const char *refname, const unsigned char *sha1, int flags, void *d
 
   html_list_append (ctx->table,
                     html (
-                          html_tag ("tr"),
+                          html_tag ("tr",
+                                    html_attr ("class", (++ctx->row & 1) ? "odd" : "even")
+                                    ),
                           html (
                                 html_tag ("td"),
                                 webgit_object_link (repo->query,
@@ -171,6 +174,7 @@ webgit_tag_table (struct webgit_repo_info* repo, const char* head, int count)
   ctx.cont = html_list ();
   ctx.count = count;
   ctx.start = head;
+  ctx.row = 0;
 
   for_each_tag_ref (show_tag_ref, &ctx);