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.
Commit
c671fc5d813fd47d1f384e0f4e74b3eeb57db7aacf2b3a3994c64b6ebff959a3
Parent
e6e8ea8ffbec421…
1 file changed
+39
-1
+39
-1
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -567,19 +567,54 @@ | ||
| 567 | 567 | @ <title>$<project_name>: $<title></title> |
| 568 | 568 | @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \ |
| 569 | 569 | @ href="$home/timeline.rss" /> |
| 570 | 570 | @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" /> |
| 571 | 571 | @ </head> |
| 572 | -@ <body> | |
| 572 | +@ <body class="$current_feature"> | |
| 573 | 573 | ; |
| 574 | 574 | |
| 575 | 575 | /* |
| 576 | 576 | ** Returns the default page header. |
| 577 | 577 | */ |
| 578 | 578 | const char *get_default_header(){ |
| 579 | 579 | return zDfltHeader; |
| 580 | 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 | +} | |
| 581 | 616 | |
| 582 | 617 | /* |
| 583 | 618 | ** Initialize all the default TH1 variables |
| 584 | 619 | */ |
| 585 | 620 | static void style_init_th1_vars(const char *zTitle){ |
| @@ -613,10 +648,11 @@ | ||
| 613 | 648 | image_url_var("logo"); |
| 614 | 649 | image_url_var("background"); |
| 615 | 650 | if( !login_is_nobody() ){ |
| 616 | 651 | Th_Store("login", g.zLogin); |
| 617 | 652 | } |
| 653 | + Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) ); | |
| 618 | 654 | } |
| 619 | 655 | |
| 620 | 656 | /* |
| 621 | 657 | ** Draw the header. |
| 622 | 658 | */ |
| @@ -1151,10 +1187,11 @@ | ||
| 1151 | 1187 | login_check_credentials(); |
| 1152 | 1188 | if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){ |
| 1153 | 1189 | isAuth = 1; |
| 1154 | 1190 | } |
| 1155 | 1191 | cgi_load_environment(); |
| 1192 | + style_set_current_feature("error"); | |
| 1156 | 1193 | if( zFormat[0] ){ |
| 1157 | 1194 | va_list ap; |
| 1158 | 1195 | va_start(ap, zFormat); |
| 1159 | 1196 | zErr = vmprintf(zFormat, ap); |
| 1160 | 1197 | va_end(ap); |
| @@ -1243,10 +1280,11 @@ | ||
| 1243 | 1280 | zMsg = vmprintf(zFormat, ap); |
| 1244 | 1281 | va_end(ap); |
| 1245 | 1282 | }else{ |
| 1246 | 1283 | zMsg = "Not Found"; |
| 1247 | 1284 | } |
| 1285 | + style_set_current_feature("enotfound"); | |
| 1248 | 1286 | style_header("Not Found"); |
| 1249 | 1287 | @ <p>%h(zMsg)</p> |
| 1250 | 1288 | cgi_set_status(404, "Not Found"); |
| 1251 | 1289 | style_finish_page("enotfound"); |
| 1252 | 1290 | } |
| 1253 | 1291 |
| --- 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 |