Fossil SCM

Created a new TH1 variable $current_feature set by default from the page URL's first component, but which may be overridden by code that knows a better feature name to use for that page. This is then used as the page's "body" class, making this the start of a replacement for the "content div" based feature class stuff done on branch [/timeline?r=default-css-cleanups | default-css-cleanups]. This is a better way to do it because it lets us target things outside the content div, such as the nav bar, the skin header, the skin footer, etc.

wyoung 2020-12-22 11:55 trunk
Commit c671fc5d813fd47d1f384e0f4e74b3eeb57db7aacf2b3a3994c64b6ebff959a3
1 file changed +39 -1
+39 -1
--- src/style.c
+++ src/style.c
@@ -567,19 +567,54 @@
567567
@ <title>$<project_name>: $<title></title>
568568
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
569569
@ href="$home/timeline.rss" />
570570
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
571571
@ </head>
572
-@ <body>
572
+@ <body class="$current_feature">
573573
;
574574
575575
/*
576576
** Returns the default page header.
577577
*/
578578
const char *get_default_header(){
579579
return zDfltHeader;
580580
}
581
+
582
+/*
583
+** Given a URL path, extract the first element as a "feature" name,
584
+** used as the <body class="FEATURE"> value by default, though
585
+** later-running code may override this, typically to group multiple
586
+** Fossil UI URLs into a single "feature" so you can have per-feature
587
+** CSS rules.
588
+**
589
+** For example, "body.forum div.markdown blockquote" targets only
590
+** block quotes made in forum posts, leaving other Markdown quotes
591
+** alone. Because feature class "forum" groups /forummain, /forumpost,
592
+** and /forume2, it works across all renderings of Markdown to HTML
593
+** within the Fossil forum feature.
594
+*/
595
+static const char* feature_from_page_path(const char *zPath)
596
+{
597
+ const char* zSlash = strchr(zPath, '/');
598
+ if (zSlash) {
599
+ return fossil_strndup(zPath, zSlash - zPath);
600
+ } else {
601
+ return zPath;
602
+ }
603
+}
604
+
605
+/*
606
+** Override the value of the TH1 variable current_feature, its default
607
+** set by feature_from_page_path(). We do not call this from
608
+** style_init_th1_vars() because that uses Th_MaybeStore() instead to
609
+** allow webpage implementations to call this before style_header()
610
+** to override that "maybe" default with something better.
611
+*/
612
+void style_set_current_feature(const char* zFeature)
613
+{
614
+ Th_Store("current_feature", zFeature);
615
+}
581616
582617
/*
583618
** Initialize all the default TH1 variables
584619
*/
585620
static void style_init_th1_vars(const char *zTitle){
@@ -613,10 +648,11 @@
613648
image_url_var("logo");
614649
image_url_var("background");
615650
if( !login_is_nobody() ){
616651
Th_Store("login", g.zLogin);
617652
}
653
+ Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
618654
}
619655
620656
/*
621657
** Draw the header.
622658
*/
@@ -1151,10 +1187,11 @@
11511187
login_check_credentials();
11521188
if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
11531189
isAuth = 1;
11541190
}
11551191
cgi_load_environment();
1192
+ style_set_current_feature("error");
11561193
if( zFormat[0] ){
11571194
va_list ap;
11581195
va_start(ap, zFormat);
11591196
zErr = vmprintf(zFormat, ap);
11601197
va_end(ap);
@@ -1243,10 +1280,11 @@
12431280
zMsg = vmprintf(zFormat, ap);
12441281
va_end(ap);
12451282
}else{
12461283
zMsg = "Not Found";
12471284
}
1285
+ style_set_current_feature("enotfound");
12481286
style_header("Not Found");
12491287
@ <p>%h(zMsg)</p>
12501288
cgi_set_status(404, "Not Found");
12511289
style_finish_page("enotfound");
12521290
}
12531291
--- src/style.c
+++ src/style.c
@@ -567,19 +567,54 @@
567 @ <title>$<project_name>: $<title></title>
568 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
569 @ href="$home/timeline.rss" />
570 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
571 @ </head>
572 @ <body>
573 ;
574
575 /*
576 ** Returns the default page header.
577 */
578 const char *get_default_header(){
579 return zDfltHeader;
580 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
582 /*
583 ** Initialize all the default TH1 variables
584 */
585 static void style_init_th1_vars(const char *zTitle){
@@ -613,10 +648,11 @@
613 image_url_var("logo");
614 image_url_var("background");
615 if( !login_is_nobody() ){
616 Th_Store("login", g.zLogin);
617 }
 
618 }
619
620 /*
621 ** Draw the header.
622 */
@@ -1151,10 +1187,11 @@
1151 login_check_credentials();
1152 if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
1153 isAuth = 1;
1154 }
1155 cgi_load_environment();
 
1156 if( zFormat[0] ){
1157 va_list ap;
1158 va_start(ap, zFormat);
1159 zErr = vmprintf(zFormat, ap);
1160 va_end(ap);
@@ -1243,10 +1280,11 @@
1243 zMsg = vmprintf(zFormat, ap);
1244 va_end(ap);
1245 }else{
1246 zMsg = "Not Found";
1247 }
 
1248 style_header("Not Found");
1249 @ <p>%h(zMsg)</p>
1250 cgi_set_status(404, "Not Found");
1251 style_finish_page("enotfound");
1252 }
1253
--- src/style.c
+++ src/style.c
@@ -567,19 +567,54 @@
567 @ <title>$<project_name>: $<title></title>
568 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
569 @ href="$home/timeline.rss" />
570 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
571 @ </head>
572 @ <body class="$current_feature">
573 ;
574
575 /*
576 ** Returns the default page header.
577 */
578 const char *get_default_header(){
579 return zDfltHeader;
580 }
581
582 /*
583 ** Given a URL path, extract the first element as a "feature" name,
584 ** used as the <body class="FEATURE"> value by default, though
585 ** later-running code may override this, typically to group multiple
586 ** Fossil UI URLs into a single "feature" so you can have per-feature
587 ** CSS rules.
588 **
589 ** For example, "body.forum div.markdown blockquote" targets only
590 ** block quotes made in forum posts, leaving other Markdown quotes
591 ** alone. Because feature class "forum" groups /forummain, /forumpost,
592 ** and /forume2, it works across all renderings of Markdown to HTML
593 ** within the Fossil forum feature.
594 */
595 static const char* feature_from_page_path(const char *zPath)
596 {
597 const char* zSlash = strchr(zPath, '/');
598 if (zSlash) {
599 return fossil_strndup(zPath, zSlash - zPath);
600 } else {
601 return zPath;
602 }
603 }
604
605 /*
606 ** Override the value of the TH1 variable current_feature, its default
607 ** set by feature_from_page_path(). We do not call this from
608 ** style_init_th1_vars() because that uses Th_MaybeStore() instead to
609 ** allow webpage implementations to call this before style_header()
610 ** to override that "maybe" default with something better.
611 */
612 void style_set_current_feature(const char* zFeature)
613 {
614 Th_Store("current_feature", zFeature);
615 }
616
617 /*
618 ** Initialize all the default TH1 variables
619 */
620 static void style_init_th1_vars(const char *zTitle){
@@ -613,10 +648,11 @@
648 image_url_var("logo");
649 image_url_var("background");
650 if( !login_is_nobody() ){
651 Th_Store("login", g.zLogin);
652 }
653 Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
654 }
655
656 /*
657 ** Draw the header.
658 */
@@ -1151,10 +1187,11 @@
1187 login_check_credentials();
1188 if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
1189 isAuth = 1;
1190 }
1191 cgi_load_environment();
1192 style_set_current_feature("error");
1193 if( zFormat[0] ){
1194 va_list ap;
1195 va_start(ap, zFormat);
1196 zErr = vmprintf(zFormat, ap);
1197 va_end(ap);
@@ -1243,10 +1280,11 @@
1280 zMsg = vmprintf(zFormat, ap);
1281 va_end(ap);
1282 }else{
1283 zMsg = "Not Found";
1284 }
1285 style_set_current_feature("enotfound");
1286 style_header("Not Found");
1287 @ <p>%h(zMsg)</p>
1288 cgi_set_status(404, "Not Found");
1289 style_finish_page("enotfound");
1290 }
1291

Keyboard Shortcuts

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