]> gitweb.ps.run Git - ps-cgit/blob - ui-summary.c
Fix colspan values
[ps-cgit] / ui-summary.c
1 /* ui-summary.c: functions for generating repo summary page
2  *
3  * Copyright (C) 2006 Lars Hjemli
4  * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
5  *
6  * Licensed under GNU General Public License v2
7  *   (see COPYING for full license text)
8  */
9
10 #include "cgit.h"
11 #include "html.h"
12 #include "ui-log.h"
13 #include "ui-refs.h"
14 #include "ui-blob.h"
15
16 int urls = 0;
17
18 static void print_url(char *base, char *suffix)
19 {
20         int columns = 3;
21
22         if (ctx.repo->enable_log_filecount)
23                 columns++;
24         if (ctx.repo->enable_log_linecount)
25                 columns++;
26
27         if (!base || !*base)
28                 return;
29         if (urls++ == 0) {
30                 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
31                 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns);
32         }
33         if (suffix && *suffix)
34                 base = fmt("%s/%s", base, suffix);
35         htmlf("<tr><td colspan='%d'><a href='", columns);
36         html_url_path(base);
37         html("'>");
38         html_txt(base);
39         html("</a></td></tr>\n");
40 }
41
42 static void print_urls(char *txt, char *suffix)
43 {
44         char *h = txt, *t, c;
45
46         while (h && *h) {
47                 while (h && *h == ' ')
48                         h++;
49                 t = h;
50                 while (t && *t && *t != ' ')
51                         t++;
52                 c = *t;
53                 *t = 0;
54                 print_url(h, suffix);
55                 *t = c;
56                 h = t;
57         }
58 }
59
60 void cgit_print_summary()
61 {
62         int columns = 3;
63
64         if (ctx.repo->enable_log_filecount)
65                 columns++;
66         if (ctx.repo->enable_log_linecount)
67                 columns++;
68
69         html("<table summary='repository info' class='list nowrap'>");
70         cgit_print_branches(ctx.cfg.summary_branches);
71         htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
72         cgit_print_tags(ctx.cfg.summary_tags);
73         if (ctx.cfg.summary_log > 0) {
74                 htmlf("<tr class='nohover'><td colspan='%d'>&nbsp;</td></tr>", columns);
75                 cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL,
76                                NULL, NULL, 0, 0, 0);
77         }
78         if (ctx.repo->clone_url)
79                 print_urls(expand_macros(ctx.repo->clone_url), NULL);
80         else if (ctx.cfg.clone_prefix)
81                 print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
82         html("</table>");
83 }
84
85 void cgit_print_repo_readme(char *path)
86 {
87         char *slash, *tmp, *colon, *ref;
88
89         if (!ctx.repo->readme || !(*ctx.repo->readme))
90                 return;
91
92         ref = NULL;
93
94         /* Check if the readme is tracked in the git repo. */
95         colon = strchr(ctx.repo->readme, ':');
96         if (colon && strlen(colon) > 1) {
97                 *colon = '\0';
98                 ref = ctx.repo->readme;
99                 ctx.repo->readme = colon + 1;
100                 if (!(*ctx.repo->readme))
101                         return;
102         }
103
104         /* Prepend repo path to relative readme path unless tracked. */
105         if (!ref && *ctx.repo->readme != '/')
106                 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
107                                                ctx.repo->readme));
108
109         /* If a subpath is specified for the about page, make it relative
110          * to the directory containing the configured readme.
111          */
112         if (path) {
113                 slash = strrchr(ctx.repo->readme, '/');
114                 if (!slash) {
115                         if (!colon)
116                                 return;
117                         slash = colon;
118                 }
119                 tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1);
120                 strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1);
121                 strcpy(tmp + (slash - ctx.repo->readme + 1), path);
122         } else
123                 tmp = ctx.repo->readme;
124
125         /* Print the calculated readme, either from the git repo or from the
126          * filesystem, while applying the about-filter.
127          */
128         html("<div id='summary'>");
129         if (ctx.repo->about_filter)
130                 cgit_open_filter(ctx.repo->about_filter);
131         if (ref)
132                 cgit_print_file(tmp, ref);
133         else
134                 html_include(tmp);
135         if (ctx.repo->about_filter)
136                 cgit_close_filter(ctx.repo->about_filter);
137         html("</div>");
138 }