Fossil SCM
Refactor the routines used to generate TH1 variables that hold resource URLs. Functionality should be unchanged. The purpose is to make the code simplier, easier to read, and easier to maintain.
Commit
6acd87f2c16724f9fcbea6541d53f3b917b51c6d4c9091e02ac2764876fdc9ee
Parent
10dfd9e51bebc8f…
1 file changed
+63
-44
+63
-44
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -366,60 +366,79 @@ | ||
| 366 | 366 | va_end(ap); |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /* |
| 371 | -** Create a TH1 variable containing the URL for the specified config | |
| 372 | -** resource. The resulting variable name will be of the form | |
| 373 | -** $[zVarPrefix]_url. | |
| 371 | +** Create a TH1 variable containing the URL for the stylesheet. | |
| 372 | +** | |
| 373 | +** The name of the new variable will be "stylesheet_url". | |
| 374 | +** | |
| 375 | +** The value will be a URL for accessing the appropriate stylesheet. | |
| 376 | +** This URL will include query parameters such as "id=" and "once&skin=" | |
| 377 | +** to cause the correct stylesheet to be loaded after a skin change | |
| 378 | +** or after a change to the stylesheet. | |
| 374 | 379 | */ |
| 375 | -static void url_var( | |
| 376 | - const char *zVarPrefix, | |
| 377 | - const char *zConfigName, | |
| 378 | - const char *zPageName | |
| 379 | -){ | |
| 380 | - char *zVarName = mprintf("%s_url", zVarPrefix); | |
| 381 | - char *zUrl = 0; /* stylesheet URL */ | |
| 382 | - int hasBuiltin = 0; /* true for built-in page-specific CSS */ | |
| 383 | - char const * zSkinName = P("once") ? skin_in_use() : 0 | |
| 384 | - /* In order to avoid a delayed-load issue which results in the | |
| 385 | - page and CSS having different skin definitions, we need to | |
| 386 | - pass the skin name along to the CSS-load URL. */; | |
| 387 | - char * zExtra = 0; | |
| 388 | - if(0==strcmp("css",zConfigName)){ | |
| 389 | - /* Account for page-specific CSS, appending a /{{g.zPath}} to the | |
| 390 | - ** url only if we have a corresponding built-in page-specific CSS | |
| 391 | - ** file. Do not append it to all pages because we would | |
| 392 | - ** effectively cache-bust all pages which do not have | |
| 393 | - ** page-specific CSS. */ | |
| 394 | - char * zBuiltin = mprintf("style.%s.css", g.zPath); | |
| 395 | - hasBuiltin = builtin_file(zBuiltin,0)!=0; | |
| 396 | - fossil_free(zBuiltin); | |
| 397 | - } | |
| 398 | - if(zSkinName && *zSkinName){ | |
| 399 | - zExtra = mprintf("&skin=%T&once", zSkinName); | |
| 400 | - } | |
| 401 | - zUrl = mprintf("%R/%s%s%s?id=%x%s", zPageName, | |
| 402 | - hasBuiltin ? "/" : "", hasBuiltin ? g.zPath : "", | |
| 403 | - skin_id(zConfigName), | |
| 404 | - zExtra ? zExtra : ""); | |
| 405 | - Th_Store(zVarName, zUrl); | |
| 406 | - fossil_free(zExtra); | |
| 407 | - fossil_free(zUrl); | |
| 408 | - fossil_free(zVarName); | |
| 380 | +static void stylesheet_url_var(void){ | |
| 381 | + char *zBuiltin; /* Auxiliary page-specific CSS page */ | |
| 382 | + Blob url; /* The URL */ | |
| 383 | + | |
| 384 | + /* Initialize the URL to its baseline */ | |
| 385 | + url = empty_blob; | |
| 386 | + blob_appendf(&url, "%R/style.css"); | |
| 387 | + | |
| 388 | + /* If page-specific CSS exists for the current page, then append | |
| 389 | + ** the pathname for the page-specific CSS. The default CSS is | |
| 390 | + ** | |
| 391 | + ** /style.css | |
| 392 | + ** | |
| 393 | + ** But for the "/wikiedit" page (to name but one example), we | |
| 394 | + ** append a path as follows: | |
| 395 | + ** | |
| 396 | + ** /style.css/wikiedit | |
| 397 | + ** | |
| 398 | + ** The /style.css page (implemented below) will detect this extra "wikiedit" | |
| 399 | + ** path information and include the page-specific CSS along with the | |
| 400 | + ** default CSS when it delivers the page. | |
| 401 | + */ | |
| 402 | + zBuiltin = mprintf("style.%s.css", g.zPath); | |
| 403 | + if( builtin_file(zBuiltin,0)!=0 ){ | |
| 404 | + blob_appendf(&url, "/%s", g.zPath); | |
| 405 | + } | |
| 406 | + fossil_free(zBuiltin); | |
| 407 | + | |
| 408 | + /* Add query parameters that will change whenever the skin changes | |
| 409 | + ** or after any updates to the CSS files | |
| 410 | + */ | |
| 411 | + blob_appendf(&url, "?id=%x", skin_id("css")); | |
| 412 | + if( P("once")!=0 && P("skin")!=0 ){ | |
| 413 | + blob_appendf(&url, "&skin=%s&once", skin_in_use()); | |
| 414 | + } | |
| 415 | + | |
| 416 | + /* Generate the CSS URL variable */ | |
| 417 | + Th_Store("stylesheet_url", blob_str(&url)); | |
| 418 | + blob_reset(&url); | |
| 409 | 419 | } |
| 410 | 420 | |
| 411 | 421 | /* |
| 412 | -** Create a TH1 variable containing the URL for the specified config image. | |
| 422 | +** Create a TH1 variable containing the URL for the specified image. | |
| 413 | 423 | ** The resulting variable name will be of the form $[zImageName]_image_url. |
| 424 | +** The value will be a URL that includes an id= query parameter that | |
| 425 | +** changes if the underlying resource changes or if a different skin | |
| 426 | +** is selected. | |
| 414 | 427 | */ |
| 415 | 428 | static void image_url_var(const char *zImageName){ |
| 416 | - char *zVarPrefix = mprintf("%s_image", zImageName); | |
| 417 | - char *zConfigName = mprintf("%s-image", zImageName); | |
| 418 | - url_var(zVarPrefix, zConfigName, zImageName); | |
| 419 | - free(zVarPrefix); | |
| 420 | - free(zConfigName); | |
| 429 | + char *zVarName; /* Name of the new TH1 variable */ | |
| 430 | + char *zResource; /* Name of CONFIG entry holding content */ | |
| 431 | + char *zUrl; /* The URL */ | |
| 432 | + | |
| 433 | + zResource = mprintf("%s-image", zImageName); | |
| 434 | + zUrl = mprintf("%R/%s?id=%x", zImageName, skin_id(zResource)); | |
| 435 | + free(zResource); | |
| 436 | + zVarName = mprintf("%s_image_url", zImageName); | |
| 437 | + Th_Store(zVarName, zUrl); | |
| 438 | + free(zVarName); | |
| 439 | + free(zUrl); | |
| 421 | 440 | } |
| 422 | 441 | |
| 423 | 442 | /* |
| 424 | 443 | ** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js |
| 425 | 444 | ** Javascript module, and generates HTML elements with the following IDs: |
| @@ -714,11 +733,11 @@ | ||
| 714 | 733 | Th_Store("release_version", RELEASE_VERSION); |
| 715 | 734 | Th_Store("manifest_version", MANIFEST_VERSION); |
| 716 | 735 | Th_Store("manifest_date", MANIFEST_DATE); |
| 717 | 736 | Th_Store("compiler_name", COMPILER_NAME); |
| 718 | 737 | Th_Store("mainmenu", style_get_mainmenu()); |
| 719 | - url_var("stylesheet", "css", "style.css"); | |
| 738 | + stylesheet_url_var(); | |
| 720 | 739 | image_url_var("logo"); |
| 721 | 740 | image_url_var("background"); |
| 722 | 741 | if( !login_is_nobody() ){ |
| 723 | 742 | Th_Store("login", g.zLogin); |
| 724 | 743 | } |
| 725 | 744 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -366,60 +366,79 @@ | |
| 366 | va_end(ap); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | ** Create a TH1 variable containing the URL for the specified config |
| 372 | ** resource. The resulting variable name will be of the form |
| 373 | ** $[zVarPrefix]_url. |
| 374 | */ |
| 375 | static void url_var( |
| 376 | const char *zVarPrefix, |
| 377 | const char *zConfigName, |
| 378 | const char *zPageName |
| 379 | ){ |
| 380 | char *zVarName = mprintf("%s_url", zVarPrefix); |
| 381 | char *zUrl = 0; /* stylesheet URL */ |
| 382 | int hasBuiltin = 0; /* true for built-in page-specific CSS */ |
| 383 | char const * zSkinName = P("once") ? skin_in_use() : 0 |
| 384 | /* In order to avoid a delayed-load issue which results in the |
| 385 | page and CSS having different skin definitions, we need to |
| 386 | pass the skin name along to the CSS-load URL. */; |
| 387 | char * zExtra = 0; |
| 388 | if(0==strcmp("css",zConfigName)){ |
| 389 | /* Account for page-specific CSS, appending a /{{g.zPath}} to the |
| 390 | ** url only if we have a corresponding built-in page-specific CSS |
| 391 | ** file. Do not append it to all pages because we would |
| 392 | ** effectively cache-bust all pages which do not have |
| 393 | ** page-specific CSS. */ |
| 394 | char * zBuiltin = mprintf("style.%s.css", g.zPath); |
| 395 | hasBuiltin = builtin_file(zBuiltin,0)!=0; |
| 396 | fossil_free(zBuiltin); |
| 397 | } |
| 398 | if(zSkinName && *zSkinName){ |
| 399 | zExtra = mprintf("&skin=%T&once", zSkinName); |
| 400 | } |
| 401 | zUrl = mprintf("%R/%s%s%s?id=%x%s", zPageName, |
| 402 | hasBuiltin ? "/" : "", hasBuiltin ? g.zPath : "", |
| 403 | skin_id(zConfigName), |
| 404 | zExtra ? zExtra : ""); |
| 405 | Th_Store(zVarName, zUrl); |
| 406 | fossil_free(zExtra); |
| 407 | fossil_free(zUrl); |
| 408 | fossil_free(zVarName); |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | ** Create a TH1 variable containing the URL for the specified config image. |
| 413 | ** The resulting variable name will be of the form $[zImageName]_image_url. |
| 414 | */ |
| 415 | static void image_url_var(const char *zImageName){ |
| 416 | char *zVarPrefix = mprintf("%s_image", zImageName); |
| 417 | char *zConfigName = mprintf("%s-image", zImageName); |
| 418 | url_var(zVarPrefix, zConfigName, zImageName); |
| 419 | free(zVarPrefix); |
| 420 | free(zConfigName); |
| 421 | } |
| 422 | |
| 423 | /* |
| 424 | ** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js |
| 425 | ** Javascript module, and generates HTML elements with the following IDs: |
| @@ -714,11 +733,11 @@ | |
| 714 | Th_Store("release_version", RELEASE_VERSION); |
| 715 | Th_Store("manifest_version", MANIFEST_VERSION); |
| 716 | Th_Store("manifest_date", MANIFEST_DATE); |
| 717 | Th_Store("compiler_name", COMPILER_NAME); |
| 718 | Th_Store("mainmenu", style_get_mainmenu()); |
| 719 | url_var("stylesheet", "css", "style.css"); |
| 720 | image_url_var("logo"); |
| 721 | image_url_var("background"); |
| 722 | if( !login_is_nobody() ){ |
| 723 | Th_Store("login", g.zLogin); |
| 724 | } |
| 725 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -366,60 +366,79 @@ | |
| 366 | va_end(ap); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | ** Create a TH1 variable containing the URL for the stylesheet. |
| 372 | ** |
| 373 | ** The name of the new variable will be "stylesheet_url". |
| 374 | ** |
| 375 | ** The value will be a URL for accessing the appropriate stylesheet. |
| 376 | ** This URL will include query parameters such as "id=" and "once&skin=" |
| 377 | ** to cause the correct stylesheet to be loaded after a skin change |
| 378 | ** or after a change to the stylesheet. |
| 379 | */ |
| 380 | static void stylesheet_url_var(void){ |
| 381 | char *zBuiltin; /* Auxiliary page-specific CSS page */ |
| 382 | Blob url; /* The URL */ |
| 383 | |
| 384 | /* Initialize the URL to its baseline */ |
| 385 | url = empty_blob; |
| 386 | blob_appendf(&url, "%R/style.css"); |
| 387 | |
| 388 | /* If page-specific CSS exists for the current page, then append |
| 389 | ** the pathname for the page-specific CSS. The default CSS is |
| 390 | ** |
| 391 | ** /style.css |
| 392 | ** |
| 393 | ** But for the "/wikiedit" page (to name but one example), we |
| 394 | ** append a path as follows: |
| 395 | ** |
| 396 | ** /style.css/wikiedit |
| 397 | ** |
| 398 | ** The /style.css page (implemented below) will detect this extra "wikiedit" |
| 399 | ** path information and include the page-specific CSS along with the |
| 400 | ** default CSS when it delivers the page. |
| 401 | */ |
| 402 | zBuiltin = mprintf("style.%s.css", g.zPath); |
| 403 | if( builtin_file(zBuiltin,0)!=0 ){ |
| 404 | blob_appendf(&url, "/%s", g.zPath); |
| 405 | } |
| 406 | fossil_free(zBuiltin); |
| 407 | |
| 408 | /* Add query parameters that will change whenever the skin changes |
| 409 | ** or after any updates to the CSS files |
| 410 | */ |
| 411 | blob_appendf(&url, "?id=%x", skin_id("css")); |
| 412 | if( P("once")!=0 && P("skin")!=0 ){ |
| 413 | blob_appendf(&url, "&skin=%s&once", skin_in_use()); |
| 414 | } |
| 415 | |
| 416 | /* Generate the CSS URL variable */ |
| 417 | Th_Store("stylesheet_url", blob_str(&url)); |
| 418 | blob_reset(&url); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | ** Create a TH1 variable containing the URL for the specified image. |
| 423 | ** The resulting variable name will be of the form $[zImageName]_image_url. |
| 424 | ** The value will be a URL that includes an id= query parameter that |
| 425 | ** changes if the underlying resource changes or if a different skin |
| 426 | ** is selected. |
| 427 | */ |
| 428 | static void image_url_var(const char *zImageName){ |
| 429 | char *zVarName; /* Name of the new TH1 variable */ |
| 430 | char *zResource; /* Name of CONFIG entry holding content */ |
| 431 | char *zUrl; /* The URL */ |
| 432 | |
| 433 | zResource = mprintf("%s-image", zImageName); |
| 434 | zUrl = mprintf("%R/%s?id=%x", zImageName, skin_id(zResource)); |
| 435 | free(zResource); |
| 436 | zVarName = mprintf("%s_image_url", zImageName); |
| 437 | Th_Store(zVarName, zUrl); |
| 438 | free(zVarName); |
| 439 | free(zUrl); |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | ** Output TEXT with a click-to-copy button next to it. Loads the copybtn.js |
| 444 | ** Javascript module, and generates HTML elements with the following IDs: |
| @@ -714,11 +733,11 @@ | |
| 733 | Th_Store("release_version", RELEASE_VERSION); |
| 734 | Th_Store("manifest_version", MANIFEST_VERSION); |
| 735 | Th_Store("manifest_date", MANIFEST_DATE); |
| 736 | Th_Store("compiler_name", COMPILER_NAME); |
| 737 | Th_Store("mainmenu", style_get_mainmenu()); |
| 738 | stylesheet_url_var(); |
| 739 | image_url_var("logo"); |
| 740 | image_url_var("background"); |
| 741 | if( !login_is_nobody() ){ |
| 742 | Th_Store("login", g.zLogin); |
| 743 | } |
| 744 |