Fossil SCM

Add class hooks to "/dir" pages to allow for filetype-specific styling.

joel 2013-04-22 01:33 trunk
Commit 7ccbf6ee6698b8f636c4a95d50788a8f55449264
1 file changed +28 -6
+28 -6
--- src/browse.c
+++ src/browse.c
@@ -288,24 +288,46 @@
288288
}
289289
i++;
290290
zFN = db_column_text(&q, 0);
291291
if( zFN[0]=='/' ){
292292
zFN++;
293
- @ <li>%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
294
- }else if( zCI ){
295
- const char *zUuid = db_column_text(&q, 1);
296
- @ <li>%z(href("%R/artifact/%s",zUuid))%h(zFN)</a></li>
293
+ @ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
297294
}else{
298
- @ <li>%z(href("%R/finfo?name=%T%T",zPrefix,zFN))%h(zFN)
299
- @ </a></li>
295
+ const char *zLink;
296
+ if( zCI ){
297
+ const char *zUuid = db_column_text(&q, 1);
298
+ zLink = href("%R/artifact/%s",zUuid);
299
+ }else{
300
+ zLink = href("%R/finfo?name=%T%T",zPrefix,zFN);
301
+ }
302
+ @ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li>
300303
}
301304
}
302305
db_finalize(&q);
303306
manifest_destroy(pM);
304307
@ </ul></td></tr></table>
305308
style_footer();
306309
}
310
+
311
+/*
312
+** Return a CSS class name based on the given filename's extension.
313
+** Result must be freed by the caller.
314
+**/
315
+const char *fileext_class(const char *zFilename){
316
+ char *zClass;
317
+ const char *zExt = strrchr(zFilename, '.');
318
+ int isExt = zExt && zExt!=zFilename && zExt[1];
319
+ int i;
320
+ for( i=1; isExt && zExt[i]; i++ ) isExt &= fossil_isalnum(zExt[i]);
321
+ if( isExt ){
322
+ zClass = mprintf("file-%s", zExt+1);
323
+ for ( i=5; zClass[i]; i++ ) zClass[i] = fossil_tolower(zClass[i]);
324
+ }else{
325
+ zClass = mprintf("file");
326
+ }
327
+ return zClass;
328
+}
307329
308330
/*
309331
** Look at all file containing in the version "vid". Construct a
310332
** temporary table named "fileage" that contains the file-id for each
311333
** files, the pathname, the check-in where the file was added, and the
312334
--- src/browse.c
+++ src/browse.c
@@ -288,24 +288,46 @@
288 }
289 i++;
290 zFN = db_column_text(&q, 0);
291 if( zFN[0]=='/' ){
292 zFN++;
293 @ <li>%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
294 }else if( zCI ){
295 const char *zUuid = db_column_text(&q, 1);
296 @ <li>%z(href("%R/artifact/%s",zUuid))%h(zFN)</a></li>
297 }else{
298 @ <li>%z(href("%R/finfo?name=%T%T",zPrefix,zFN))%h(zFN)
299 @ </a></li>
 
 
 
 
 
 
300 }
301 }
302 db_finalize(&q);
303 manifest_destroy(pM);
304 @ </ul></td></tr></table>
305 style_footer();
306 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
308 /*
309 ** Look at all file containing in the version "vid". Construct a
310 ** temporary table named "fileage" that contains the file-id for each
311 ** files, the pathname, the check-in where the file was added, and the
312
--- src/browse.c
+++ src/browse.c
@@ -288,24 +288,46 @@
288 }
289 i++;
290 zFN = db_column_text(&q, 0);
291 if( zFN[0]=='/' ){
292 zFN++;
293 @ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
 
 
 
294 }else{
295 const char *zLink;
296 if( zCI ){
297 const char *zUuid = db_column_text(&q, 1);
298 zLink = href("%R/artifact/%s",zUuid);
299 }else{
300 zLink = href("%R/finfo?name=%T%T",zPrefix,zFN);
301 }
302 @ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li>
303 }
304 }
305 db_finalize(&q);
306 manifest_destroy(pM);
307 @ </ul></td></tr></table>
308 style_footer();
309 }
310
311 /*
312 ** Return a CSS class name based on the given filename's extension.
313 ** Result must be freed by the caller.
314 **/
315 const char *fileext_class(const char *zFilename){
316 char *zClass;
317 const char *zExt = strrchr(zFilename, '.');
318 int isExt = zExt && zExt!=zFilename && zExt[1];
319 int i;
320 for( i=1; isExt && zExt[i]; i++ ) isExt &= fossil_isalnum(zExt[i]);
321 if( isExt ){
322 zClass = mprintf("file-%s", zExt+1);
323 for ( i=5; zClass[i]; i++ ) zClass[i] = fossil_tolower(zClass[i]);
324 }else{
325 zClass = mprintf("file");
326 }
327 return zClass;
328 }
329
330 /*
331 ** Look at all file containing in the version "vid". Construct a
332 ** temporary table named "fileage" that contains the file-id for each
333 ** files, the pathname, the check-in where the file was added, and the
334

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button