author | Lars Hjemli <hjemli@gmail.com> | 2007-06-16 23:23:08 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-16 23:39:05 (UTC) |
commit | 44947bfcdc0d6e8c7d673bea0538cbf2a182f289 (patch) (unidiff) | |
tree | 3f65d6842738a8314ed72d5575a0b523061556b7 /ui-shared.c | |
parent | f91b9696a36008c245a3195800ba0c5fa3e890f9 (diff) | |
download | cgit-44947bfcdc0d6e8c7d673bea0538cbf2a182f289.zip cgit-44947bfcdc0d6e8c7d673bea0538cbf2a182f289.tar.gz cgit-44947bfcdc0d6e8c7d673bea0538cbf2a182f289.tar.bz2 |
Add and use cgit_tree_link()
This creates a new function used to generate links to 'tree' page and uses
the function everywhere a link to the 'tree' page is generated.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index aba93e8..9ab6409 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -66,48 +66,112 @@ char *cgit_pageurl(const char *reponame, const char *pagename, | |||
66 | pagename, query); | 66 | pagename, query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_currurl() | 78 | char *cgit_currurl() |
79 | { | 79 | { |
80 | if (!cgit_virtual_root) | 80 | if (!cgit_virtual_root) |
81 | return cgit_script_name; | 81 | return cgit_script_name; |
82 | else if (cgit_query_page) | 82 | else if (cgit_query_page) |
83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 83 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
84 | else if (cgit_query_repo) | 84 | else if (cgit_query_repo) |
85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 85 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
86 | else | 86 | else |
87 | return fmt("%s/", cgit_virtual_root); | 87 | return fmt("%s/", cgit_virtual_root); |
88 | } | 88 | } |
89 | 89 | ||
90 | static char *repolink(char *title, char *class, char *page, char *head, | ||
91 | char *path) | ||
92 | { | ||
93 | char *delim = "?"; | ||
94 | |||
95 | html("<a"); | ||
96 | if (title) { | ||
97 | html(" title='"); | ||
98 | html_attr(title); | ||
99 | html("'"); | ||
100 | } | ||
101 | if (class) { | ||
102 | html(" class='"); | ||
103 | html_attr(class); | ||
104 | html("'"); | ||
105 | } | ||
106 | html(" href='"); | ||
107 | if (cgit_virtual_root) { | ||
108 | html_attr(cgit_virtual_root); | ||
109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | ||
110 | html("/"); | ||
111 | html_attr(cgit_repo->url); | ||
112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | ||
113 | html("/"); | ||
114 | html(page); | ||
115 | html("/"); | ||
116 | if (path) | ||
117 | html_attr(path); | ||
118 | } else { | ||
119 | html(cgit_script_name); | ||
120 | html("?url="); | ||
121 | html_attr(cgit_repo->url); | ||
122 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | ||
123 | html("/"); | ||
124 | html(page); | ||
125 | html("/"); | ||
126 | if (path) | ||
127 | html_attr(path); | ||
128 | delim = "&"; | ||
129 | } | ||
130 | if (head && head != cgit_query_head) { | ||
131 | html(delim); | ||
132 | html("h="); | ||
133 | html_attr(head); | ||
134 | delim = "&"; | ||
135 | } | ||
136 | return fmt("%s", delim); | ||
137 | } | ||
138 | |||
139 | void cgit_tree_link(char *name, char *title, char *class, char *head, | ||
140 | char *rev, char *path) | ||
141 | { | ||
142 | char *delim; | ||
143 | |||
144 | delim = repolink(title, class, "tree", head, path); | ||
145 | if (rev && rev != cgit_query_head) { | ||
146 | html(delim); | ||
147 | html("id="); | ||
148 | html_attr(rev); | ||
149 | } | ||
150 | html("'>"); | ||
151 | html_txt(name); | ||
152 | html("</a>"); | ||
153 | } | ||
90 | 154 | ||
91 | void cgit_print_date(time_t secs, char *format) | 155 | void cgit_print_date(time_t secs, char *format) |
92 | { | 156 | { |
93 | char buf[64]; | 157 | char buf[64]; |
94 | struct tm *time; | 158 | struct tm *time; |
95 | 159 | ||
96 | time = gmtime(&secs); | 160 | time = gmtime(&secs); |
97 | strftime(buf, sizeof(buf)-1, format, time); | 161 | strftime(buf, sizeof(buf)-1, format, time); |
98 | html_txt(buf); | 162 | html_txt(buf); |
99 | } | 163 | } |
100 | 164 | ||
101 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 165 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
102 | { | 166 | { |
103 | time_t now, secs; | 167 | time_t now, secs; |
104 | 168 | ||
105 | time(&now); | 169 | time(&now); |
106 | secs = now - t; | 170 | secs = now - t; |
107 | 171 | ||
108 | if (secs > max_relative && max_relative >= 0) { | 172 | if (secs > max_relative && max_relative >= 0) { |
109 | cgit_print_date(t, format); | 173 | cgit_print_date(t, format); |
110 | return; | 174 | return; |
111 | } | 175 | } |
112 | 176 | ||
113 | if (secs < TM_HOUR * 2) { | 177 | if (secs < TM_HOUR * 2) { |