Fossil

Check-in [c671fc5d81]
Login

Check-in [c671fc5d81]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | body-feature-class
Files: files | file ages | folders
SHA3-256: c671fc5d813fd47d1f384e0f4e74b3eeb57db7aacf2b3a3994c64b6ebff959a3
User & Date: wyoung 2020-12-22 11:55:40.385
Context
2020-12-22
11:56
Using the new $current_feature variable in the Bootstrap skin's Header, it being the only stock skin to still provide its own <body>. Without this change, the prior commit won't take effect when using Bootstrap. ... (check-in: 556923fab5 user: wyoung tags: body-feature-class)
11:55
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. ... (check-in: c671fc5d81 user: wyoung tags: body-feature-class)
10:31
Comment fix to track a code change made in commit [3d6444fc]. ... (check-in: e6e8ea8ffb user: wyoung tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/style.c.
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580



































581
582
583
584
585
586
587
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ <title>$<project_name>: $<title></title>
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
@  href="$home/timeline.rss" />
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
@ </head>
@ <body>
;

/*
** Returns the default page header.
*/
const char *get_default_header(){
  return zDfltHeader;
}




































/*
** Initialize all the default TH1 variables
*/
static void style_init_th1_vars(const char *zTitle){
  const char *zNonce = style_nonce();
  char *zDfltCsp;







|








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ <title>$<project_name>: $<title></title>
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
@  href="$home/timeline.rss" />
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
@ </head>
@ <body class="$current_feature">
;

/*
** Returns the default page header.
*/
const char *get_default_header(){
  return zDfltHeader;
}

/*
** Given a URL path, extract the first element as a "feature" name,
** used as the <body class="FEATURE"> value by default, though
** later-running code may override this, typically to group multiple
** Fossil UI URLs into a single "feature" so you can have per-feature
** CSS rules.
**
** For example, "body.forum div.markdown blockquote" targets only
** block quotes made in forum posts, leaving other Markdown quotes
** alone.  Because feature class "forum" groups /forummain, /forumpost,
** and /forume2, it works across all renderings of Markdown to HTML
** within the Fossil forum feature.
*/
static const char* feature_from_page_path(const char *zPath)
{
  const char* zSlash = strchr(zPath, '/');
  if (zSlash) {
    return fossil_strndup(zPath, zSlash - zPath);
  } else {
    return zPath;
  }
}

/*
** Override the value of the TH1 variable current_feature, its default
** set by feature_from_page_path().  We do not call this from
** style_init_th1_vars() because that uses Th_MaybeStore() instead to
** allow webpage implementations to call this before style_header()
** to override that "maybe" default with something better.
*/
void style_set_current_feature(const char* zFeature)
{
  Th_Store("current_feature", zFeature);
}

/*
** Initialize all the default TH1 variables
*/
static void style_init_th1_vars(const char *zTitle){
  const char *zNonce = style_nonce();
  char *zDfltCsp;
611
612
613
614
615
616
617

618
619
620
621
622
623
624
  Th_Store("compiler_name", COMPILER_NAME);
  url_var("stylesheet", "css", "style.css");
  image_url_var("logo");
  image_url_var("background");
  if( !login_is_nobody() ){
    Th_Store("login", g.zLogin);
  }

}

/*
** Draw the header.
*/
void style_header(const char *zTitleFormat, ...){
  va_list ap;







>







646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
  Th_Store("compiler_name", COMPILER_NAME);
  url_var("stylesheet", "css", "style.css");
  image_url_var("logo");
  image_url_var("background");
  if( !login_is_nobody() ){
    Th_Store("login", g.zLogin);
  }
  Th_MaybeStore("current_feature", feature_from_page_path(local_zCurrentPage) );
}

/*
** Draw the header.
*/
void style_header(const char *zTitleFormat, ...){
  va_list ap;
1149
1150
1151
1152
1153
1154
1155

1156
1157
1158
1159
1160
1161
1162
  char zCap[100];

  login_check_credentials();
  if( g.perm.Admin || g.perm.Setup  || db_get_boolean("test_env_enable",0) ){
    isAuth = 1;
  }
  cgi_load_environment();

  if( zFormat[0] ){
    va_list ap;
    va_start(ap, zFormat);
    zErr = vmprintf(zFormat, ap);
    va_end(ap);
    style_header("Bad Request");
    @ <h1>/%h(g.zPath): %h(zErr)</h1>







>







1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
  char zCap[100];

  login_check_credentials();
  if( g.perm.Admin || g.perm.Setup  || db_get_boolean("test_env_enable",0) ){
    isAuth = 1;
  }
  cgi_load_environment();
  style_set_current_feature("error");
  if( zFormat[0] ){
    va_list ap;
    va_start(ap, zFormat);
    zErr = vmprintf(zFormat, ap);
    va_end(ap);
    style_header("Bad Request");
    @ <h1>/%h(g.zPath): %h(zErr)</h1>
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
  if( zFormat ){
    va_start(ap, zFormat);
    zMsg = vmprintf(zFormat, ap);
    va_end(ap);
  }else{
    zMsg = "Not Found";
  }

  style_header("Not Found");
  @ <p>%h(zMsg)</p>
  cgi_set_status(404, "Not Found");
  style_finish_page("enotfound");
}

#if INTERFACE







>







1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
  if( zFormat ){
    va_start(ap, zFormat);
    zMsg = vmprintf(zFormat, ap);
    va_end(ap);
  }else{
    zMsg = "Not Found";
  }
  style_set_current_feature("enotfound");
  style_header("Not Found");
  @ <p>%h(zMsg)</p>
  cgi_set_status(404, "Not Found");
  style_finish_page("enotfound");
}

#if INTERFACE