Fossil SCM

Proof of concept for my proposal of reworking how style.css emits CSS, as discussed in [https://fossil-scm.org/forum/forumpost/d63ff33063|forumpost/d63ff33063].

stephan 2020-05-17 17:52 trunk
Commit ae10ddf330160225d5d1e295730e93a65be1faeb44ed9a9c8989b777cad541f4
--- src/main.mk
+++ src/main.mk
@@ -243,10 +243,11 @@
243243
$(SRCDIR)/sounds/b.wav \
244244
$(SRCDIR)/sounds/c.wav \
245245
$(SRCDIR)/sounds/d.wav \
246246
$(SRCDIR)/sounds/e.wav \
247247
$(SRCDIR)/sounds/f.wav \
248
+ $(SRCDIR)/style.admin_log.css \
248249
$(SRCDIR)/tree.js \
249250
$(SRCDIR)/useredit.js \
250251
$(SRCDIR)/wiki.wiki
251252
252253
TRANS_SRC = \
253254
--- src/main.mk
+++ src/main.mk
@@ -243,10 +243,11 @@
243 $(SRCDIR)/sounds/b.wav \
244 $(SRCDIR)/sounds/c.wav \
245 $(SRCDIR)/sounds/d.wav \
246 $(SRCDIR)/sounds/e.wav \
247 $(SRCDIR)/sounds/f.wav \
 
248 $(SRCDIR)/tree.js \
249 $(SRCDIR)/useredit.js \
250 $(SRCDIR)/wiki.wiki
251
252 TRANS_SRC = \
253
--- src/main.mk
+++ src/main.mk
@@ -243,10 +243,11 @@
243 $(SRCDIR)/sounds/b.wav \
244 $(SRCDIR)/sounds/c.wav \
245 $(SRCDIR)/sounds/d.wav \
246 $(SRCDIR)/sounds/e.wav \
247 $(SRCDIR)/sounds/f.wav \
248 $(SRCDIR)/style.admin_log.css \
249 $(SRCDIR)/tree.js \
250 $(SRCDIR)/useredit.js \
251 $(SRCDIR)/wiki.wiki
252
253 TRANS_SRC = \
254
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -175,10 +175,11 @@
175175
set extra_files {
176176
diff.tcl
177177
markdown.md
178178
wiki.wiki
179179
*.js
180
+ style.*.css
180181
../skins/*/*.txt
181182
sounds/*.wav
182183
}
183184
184185
# Options used to compile the included SQLite library.
185186
186187
ADDED src/style.admin_log.css
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -175,10 +175,11 @@
175 set extra_files {
176 diff.tcl
177 markdown.md
178 wiki.wiki
179 *.js
 
180 ../skins/*/*.txt
181 sounds/*.wav
182 }
183
184 # Options used to compile the included SQLite library.
185
186 DDED src/style.admin_log.css
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -175,10 +175,11 @@
175 set extra_files {
176 diff.tcl
177 markdown.md
178 wiki.wiki
179 *.js
180 style.*.css
181 ../skins/*/*.txt
182 sounds/*.wav
183 }
184
185 # Options used to compile the included SQLite library.
186
187 DDED src/style.admin_log.css
--- a/src/style.admin_log.css
+++ b/src/style.admin_log.css
@@ -0,0 +1,7 @@
1
+/* This file is just to demonstra*/
2
+a:hover::before {
3
+ content: "[";
4
+}
5
+a:hover::after {
6
+ content: "]";
7
+}
--- a/src/style.admin_log.css
+++ b/src/style.admin_log.css
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
--- a/src/style.admin_log.css
+++ b/src/style.admin_log.css
@@ -0,0 +1,7 @@
1 /* This file is just to demonstra*/
2 a:hover::before {
3 content: "[";
4 }
5 a:hover::after {
6 content: "]";
7 }
+55 -19
--- src/style.c
+++ src/style.c
@@ -370,15 +370,31 @@
370370
const char *zVarPrefix,
371371
const char *zConfigName,
372372
const char *zPageName
373373
){
374374
char *zVarName = mprintf("%s_url", zVarPrefix);
375
- char *zUrl = mprintf("%R/%s?id=%x", zPageName,
376
- skin_id(zConfigName));
375
+ char *zExtra = 0;
376
+ char *zUrl = 0;
377
+ if(0==strcmp("css",zConfigName)){
378
+ /* Account for page-specific CSS, appending a /{{g.zPath}} to the
379
+ ** url only if we have a corresponding built-in page-specific CSS
380
+ ** file. Do not append it to all pages because we would
381
+ ** effectively cache-bust all pages which do not have
382
+ ** page-specific CSS. */
383
+ char * zBuiltin = mprintf("style.%s.css", g.zPath);
384
+ if(builtin_file(zBuiltin,0)!=0){
385
+ zExtra = mprintf("/%s", g.zPath);
386
+ }
387
+ fossil_free(zBuiltin);
388
+ }
389
+ zUrl = mprintf("%R/%s%s?id=%x", zPageName,
390
+ zExtra ? zExtra : "",
391
+ skin_id(zConfigName));
377392
Th_Store(zVarName, zUrl);
378
- free(zUrl);
379
- free(zVarName);
393
+ fossil_free(zExtra);
394
+ fossil_free(zUrl);
395
+ fossil_free(zVarName);
380396
}
381397
382398
/*
383399
** Create a TH1 variable containing the URL for the specified config image.
384400
** The resulting variable name will be of the form $[zImageName]_image_url.
@@ -1063,37 +1079,57 @@
10631079
** WEBPAGE: style.css
10641080
**
10651081
** Return the style sheet.
10661082
*/
10671083
void page_style_css(void){
1068
- Blob css;
1084
+ Blob css = empty_blob;
10691085
int i;
1070
- int isInit = 0;
1086
+ const char *zPage = P("name");
10711087
10721088
cgi_set_content_type("text/css");
1073
- blob_init(&css,skin_get("css"),-1);
1074
-
10751089
/* add special missing definitions */
10761090
for(i=1; cssDefaultList[i].elementClass; i++){
10771091
char *z = blob_str(&css);
10781092
if( !containsSelector(z, cssDefaultList[i].elementClass) ){
1079
- if( !isInit ){
1080
- isInit = 1;
1081
- blob_append(&css,
1082
- "\n/***********************************************************\n"
1083
- "** All CSS above is supplied by the repository \"skin\".\n"
1084
- "** That which follows is generated automatically by Fossil\n"
1085
- "** to fill in needed selectors that are missing from the\n"
1086
- "** \"skin\" CSS.\n"
1087
- "***********************************************************/\n",
1088
- -1);
1089
- }
10901093
blob_appendf(&css, "%s {\n%s}\n",
10911094
cssDefaultList[i].elementClass,
10921095
cssDefaultList[i].value);
10931096
}
10941097
}
1098
+ blob_append(&css,
1099
+ "\n/***********************************************************\n"
1100
+ "** All CSS above is generated automatically by Fossil to\n"
1101
+ "** provide default rule implementations which the \"skin\"\n"
1102
+ "** may cascade.\n"
1103
+ "***********************************************************/\n",
1104
+ -1);
1105
+ blob_append(&css,skin_get("css"),-1);
1106
+ if(zPage!=0 && zPage[0]!=0){
1107
+ char * zFile = mprintf("style.%s.css", zPage);
1108
+ int nFile = 0;
1109
+ const char *zBuiltin = (const char *)builtin_file(zFile, &nFile);
1110
+ if(nFile>0){
1111
+ blob_appendf(&css,
1112
+ "\n/***********************************************************\n"
1113
+ "** Start of page-specific CSS for page %s...\n"
1114
+ "***********************************************************/\n",
1115
+ zPage);
1116
+ blob_append(&css, zBuiltin, nFile);
1117
+ blob_appendf(&css,
1118
+ "\n/***********************************************************\n"
1119
+ "** End of page-specific CSS for page %s.\n"
1120
+ "***********************************************************/\n",
1121
+ zPage);
1122
+ }
1123
+ fossil_free(zFile);
1124
+ }
1125
+ blob_append(&css,
1126
+ "\n/***********************************************************\n"
1127
+ "** All CSS which follows is supplied by the repository \"skin\".\n"
1128
+ "***********************************************************/\n",
1129
+ -1);
1130
+ blob_append(&css,skin_get("css"),-1);
10951131
10961132
/* Process through TH1 in order to give an opportunity to substitute
10971133
** variables such as $baseurl.
10981134
*/
10991135
Th_Store("baseurl", g.zBaseURL);
11001136
--- src/style.c
+++ src/style.c
@@ -370,15 +370,31 @@
370 const char *zVarPrefix,
371 const char *zConfigName,
372 const char *zPageName
373 ){
374 char *zVarName = mprintf("%s_url", zVarPrefix);
375 char *zUrl = mprintf("%R/%s?id=%x", zPageName,
376 skin_id(zConfigName));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377 Th_Store(zVarName, zUrl);
378 free(zUrl);
379 free(zVarName);
 
380 }
381
382 /*
383 ** Create a TH1 variable containing the URL for the specified config image.
384 ** The resulting variable name will be of the form $[zImageName]_image_url.
@@ -1063,37 +1079,57 @@
1063 ** WEBPAGE: style.css
1064 **
1065 ** Return the style sheet.
1066 */
1067 void page_style_css(void){
1068 Blob css;
1069 int i;
1070 int isInit = 0;
1071
1072 cgi_set_content_type("text/css");
1073 blob_init(&css,skin_get("css"),-1);
1074
1075 /* add special missing definitions */
1076 for(i=1; cssDefaultList[i].elementClass; i++){
1077 char *z = blob_str(&css);
1078 if( !containsSelector(z, cssDefaultList[i].elementClass) ){
1079 if( !isInit ){
1080 isInit = 1;
1081 blob_append(&css,
1082 "\n/***********************************************************\n"
1083 "** All CSS above is supplied by the repository \"skin\".\n"
1084 "** That which follows is generated automatically by Fossil\n"
1085 "** to fill in needed selectors that are missing from the\n"
1086 "** \"skin\" CSS.\n"
1087 "***********************************************************/\n",
1088 -1);
1089 }
1090 blob_appendf(&css, "%s {\n%s}\n",
1091 cssDefaultList[i].elementClass,
1092 cssDefaultList[i].value);
1093 }
1094 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1095
1096 /* Process through TH1 in order to give an opportunity to substitute
1097 ** variables such as $baseurl.
1098 */
1099 Th_Store("baseurl", g.zBaseURL);
1100
--- src/style.c
+++ src/style.c
@@ -370,15 +370,31 @@
370 const char *zVarPrefix,
371 const char *zConfigName,
372 const char *zPageName
373 ){
374 char *zVarName = mprintf("%s_url", zVarPrefix);
375 char *zExtra = 0;
376 char *zUrl = 0;
377 if(0==strcmp("css",zConfigName)){
378 /* Account for page-specific CSS, appending a /{{g.zPath}} to the
379 ** url only if we have a corresponding built-in page-specific CSS
380 ** file. Do not append it to all pages because we would
381 ** effectively cache-bust all pages which do not have
382 ** page-specific CSS. */
383 char * zBuiltin = mprintf("style.%s.css", g.zPath);
384 if(builtin_file(zBuiltin,0)!=0){
385 zExtra = mprintf("/%s", g.zPath);
386 }
387 fossil_free(zBuiltin);
388 }
389 zUrl = mprintf("%R/%s%s?id=%x", zPageName,
390 zExtra ? zExtra : "",
391 skin_id(zConfigName));
392 Th_Store(zVarName, zUrl);
393 fossil_free(zExtra);
394 fossil_free(zUrl);
395 fossil_free(zVarName);
396 }
397
398 /*
399 ** Create a TH1 variable containing the URL for the specified config image.
400 ** The resulting variable name will be of the form $[zImageName]_image_url.
@@ -1063,37 +1079,57 @@
1079 ** WEBPAGE: style.css
1080 **
1081 ** Return the style sheet.
1082 */
1083 void page_style_css(void){
1084 Blob css = empty_blob;
1085 int i;
1086 const char *zPage = P("name");
1087
1088 cgi_set_content_type("text/css");
 
 
1089 /* add special missing definitions */
1090 for(i=1; cssDefaultList[i].elementClass; i++){
1091 char *z = blob_str(&css);
1092 if( !containsSelector(z, cssDefaultList[i].elementClass) ){
 
 
 
 
 
 
 
 
 
 
 
1093 blob_appendf(&css, "%s {\n%s}\n",
1094 cssDefaultList[i].elementClass,
1095 cssDefaultList[i].value);
1096 }
1097 }
1098 blob_append(&css,
1099 "\n/***********************************************************\n"
1100 "** All CSS above is generated automatically by Fossil to\n"
1101 "** provide default rule implementations which the \"skin\"\n"
1102 "** may cascade.\n"
1103 "***********************************************************/\n",
1104 -1);
1105 blob_append(&css,skin_get("css"),-1);
1106 if(zPage!=0 && zPage[0]!=0){
1107 char * zFile = mprintf("style.%s.css", zPage);
1108 int nFile = 0;
1109 const char *zBuiltin = (const char *)builtin_file(zFile, &nFile);
1110 if(nFile>0){
1111 blob_appendf(&css,
1112 "\n/***********************************************************\n"
1113 "** Start of page-specific CSS for page %s...\n"
1114 "***********************************************************/\n",
1115 zPage);
1116 blob_append(&css, zBuiltin, nFile);
1117 blob_appendf(&css,
1118 "\n/***********************************************************\n"
1119 "** End of page-specific CSS for page %s.\n"
1120 "***********************************************************/\n",
1121 zPage);
1122 }
1123 fossil_free(zFile);
1124 }
1125 blob_append(&css,
1126 "\n/***********************************************************\n"
1127 "** All CSS which follows is supplied by the repository \"skin\".\n"
1128 "***********************************************************/\n",
1129 -1);
1130 blob_append(&css,skin_get("css"),-1);
1131
1132 /* Process through TH1 in order to give an opportunity to substitute
1133 ** variables such as $baseurl.
1134 */
1135 Th_Store("baseurl", g.zBaseURL);
1136
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -665,10 +665,11 @@
665665
$(SRCDIR)/sounds/b.wav \
666666
$(SRCDIR)/sounds/c.wav \
667667
$(SRCDIR)/sounds/d.wav \
668668
$(SRCDIR)/sounds/e.wav \
669669
$(SRCDIR)/sounds/f.wav \
670
+ $(SRCDIR)/style.admin_log.css \
670671
$(SRCDIR)/tree.js \
671672
$(SRCDIR)/useredit.js \
672673
$(SRCDIR)/wiki.wiki
673674
674675
TRANS_SRC = \
675676
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -665,10 +665,11 @@
665 $(SRCDIR)/sounds/b.wav \
666 $(SRCDIR)/sounds/c.wav \
667 $(SRCDIR)/sounds/d.wav \
668 $(SRCDIR)/sounds/e.wav \
669 $(SRCDIR)/sounds/f.wav \
 
670 $(SRCDIR)/tree.js \
671 $(SRCDIR)/useredit.js \
672 $(SRCDIR)/wiki.wiki
673
674 TRANS_SRC = \
675
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -665,10 +665,11 @@
665 $(SRCDIR)/sounds/b.wav \
666 $(SRCDIR)/sounds/c.wav \
667 $(SRCDIR)/sounds/d.wav \
668 $(SRCDIR)/sounds/e.wav \
669 $(SRCDIR)/sounds/f.wav \
670 $(SRCDIR)/style.admin_log.css \
671 $(SRCDIR)/tree.js \
672 $(SRCDIR)/useredit.js \
673 $(SRCDIR)/wiki.wiki
674
675 TRANS_SRC = \
676
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -572,10 +572,11 @@
572572
$(SRCDIR)\sounds\b.wav \
573573
$(SRCDIR)\sounds\c.wav \
574574
$(SRCDIR)\sounds\d.wav \
575575
$(SRCDIR)\sounds\e.wav \
576576
$(SRCDIR)\sounds\f.wav \
577
+ $(SRCDIR)\style.admin_log.css \
577578
$(SRCDIR)\tree.js \
578579
$(SRCDIR)\useredit.js \
579580
$(SRCDIR)\wiki.wiki
580581
581582
OBJ = $(OX)\add$O \
582583
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -572,10 +572,11 @@
572 $(SRCDIR)\sounds\b.wav \
573 $(SRCDIR)\sounds\c.wav \
574 $(SRCDIR)\sounds\d.wav \
575 $(SRCDIR)\sounds\e.wav \
576 $(SRCDIR)\sounds\f.wav \
 
577 $(SRCDIR)\tree.js \
578 $(SRCDIR)\useredit.js \
579 $(SRCDIR)\wiki.wiki
580
581 OBJ = $(OX)\add$O \
582
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -572,10 +572,11 @@
572 $(SRCDIR)\sounds\b.wav \
573 $(SRCDIR)\sounds\c.wav \
574 $(SRCDIR)\sounds\d.wav \
575 $(SRCDIR)\sounds\e.wav \
576 $(SRCDIR)\sounds\f.wav \
577 $(SRCDIR)\style.admin_log.css \
578 $(SRCDIR)\tree.js \
579 $(SRCDIR)\useredit.js \
580 $(SRCDIR)\wiki.wiki
581
582 OBJ = $(OX)\add$O \
583

Keyboard Shortcuts

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