Fossil SCM

Enhance the --skin option so that it can be a directory holding the three skin files.

drh 2015-02-16 13:41 trunk
Commit bfd413bf1eb6049195b18c8f5e4c619856cf04b0
3 files changed +17 -1 +1 -1 +23 -3
+17 -1
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,11 @@
11
Built-in Skins
22
==============
33
44
Each subdirectory under this folder describes a built-in "skin".
55
There are three files in each subdirectory for the CSS, the header,
6
-and the footer for the skin.
6
+and the footer for that skin.
77
88
To improve an existing built-in skin, simply edit the appropriate
99
files and recompile.
1010
1111
To add a new skin:
@@ -23,5 +23,21 @@
2323
2424
4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
2525
file so that it describes and references the "newskin" skin.
2626
2727
5. Type "make" to rebuild.
28
+
29
+Development Hints
30
+-----------------
31
+
32
+One way to develop a new skin is to copy the baseline files (css.txt,
33
+footer.txt, and header.txt) into a working directory $WORKDIR then
34
+launch Fossil with a command-line option "--skin $WORKDIR". Example:
35
+
36
+ cp -r skins/default newskin
37
+ fossil ui --skin ./newskin
38
+
39
+When the argument to --skin contains one or more '/' characters, the
40
+appropriate skin files are read from disk from the directory specified.
41
+So after launching fossil as shown above, you can edit the newskin/css.txt,
42
+newskin/header.txt, and newskin/footer.txt files using your favorite
43
+text editor, then press Reload on your browser to see immediate results.
2844
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,11 @@
1 Built-in Skins
2 ==============
3
4 Each subdirectory under this folder describes a built-in "skin".
5 There are three files in each subdirectory for the CSS, the header,
6 and the footer for the skin.
7
8 To improve an existing built-in skin, simply edit the appropriate
9 files and recompile.
10
11 To add a new skin:
@@ -23,5 +23,21 @@
23
24 4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
25 file so that it describes and references the "newskin" skin.
26
27 5. Type "make" to rebuild.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,11 @@
1 Built-in Skins
2 ==============
3
4 Each subdirectory under this folder describes a built-in "skin".
5 There are three files in each subdirectory for the CSS, the header,
6 and the footer for that skin.
7
8 To improve an existing built-in skin, simply edit the appropriate
9 files and recompile.
10
11 To add a new skin:
@@ -23,5 +23,21 @@
23
24 4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
25 file so that it describes and references the "newskin" skin.
26
27 5. Type "make" to rebuild.
28
29 Development Hints
30 -----------------
31
32 One way to develop a new skin is to copy the baseline files (css.txt,
33 footer.txt, and header.txt) into a working directory $WORKDIR then
34 launch Fossil with a command-line option "--skin $WORKDIR". Example:
35
36 cp -r skins/default newskin
37 fossil ui --skin ./newskin
38
39 When the argument to --skin contains one or more '/' characters, the
40 appropriate skin files are read from disk from the directory specified.
41 So after launching fossil as shown above, you can edit the newskin/css.txt,
42 newskin/header.txt, and newskin/footer.txt files using your favorite
43 text editor, then press Reload on your browser to see immediate results.
44
+1 -1
--- src/blob.c
+++ src/blob.c
@@ -753,11 +753,11 @@
753753
** Initialize a blob to be the content of a file. If the filename
754754
** is blank or "-" then read from standard input.
755755
**
756756
** Any prior content of the blob is discarded, not freed.
757757
**
758
-** Return the number of bytes read. Calls fossil_fatal() error (i.e.
758
+** Return the number of bytes read. Calls fossil_fatal() on error (i.e.
759759
** it exit()s and does not return).
760760
*/
761761
int blob_read_from_file(Blob *pBlob, const char *zFilename){
762762
int size, got;
763763
FILE *in;
764764
--- src/blob.c
+++ src/blob.c
@@ -753,11 +753,11 @@
753 ** Initialize a blob to be the content of a file. If the filename
754 ** is blank or "-" then read from standard input.
755 **
756 ** Any prior content of the blob is discarded, not freed.
757 **
758 ** Return the number of bytes read. Calls fossil_fatal() error (i.e.
759 ** it exit()s and does not return).
760 */
761 int blob_read_from_file(Blob *pBlob, const char *zFilename){
762 int size, got;
763 FILE *in;
764
--- src/blob.c
+++ src/blob.c
@@ -753,11 +753,11 @@
753 ** Initialize a blob to be the content of a file. If the filename
754 ** is blank or "-" then read from standard input.
755 **
756 ** Any prior content of the blob is discarded, not freed.
757 **
758 ** Return the number of bytes read. Calls fossil_fatal() on error (i.e.
759 ** it exit()s and does not return).
760 */
761 int blob_read_from_file(Blob *pBlob, const char *zFilename){
762 int size, got;
763 FILE *in;
764
+23 -3
--- src/skins.c
+++ src/skins.c
@@ -60,28 +60,38 @@
6060
**
6161
** The following static variable holds the name of the alternative skin,
6262
** or NULL if the skin should be as configured.
6363
*/
6464
static struct BuiltinSkin *pAltSkin = 0;
65
+static char *zAltSkinDir = 0;
6566
6667
/*
6768
** Invoke this routine to set the alternative skin. Return NULL if the
6869
** alternative was successfully installed. Return a string listing all
6970
** available skins if zName does not match an available skin. Memory
7071
** for the returned string comes from fossil_malloc() and should be freed
7172
** by the caller.
73
+**
74
+** If the alternative skin name contains one or more '/' characters, then
75
+** it is assumed to be a directory on disk that holds override css.txt,
76
+** footer.txt, and header.txt. This mode can be used for interactive
77
+** development of new skins.
7278
*/
7379
char *skin_use_alternative(const char *zName){
7480
int i;
75
- Blob err;
81
+ Blob err = BLOB_INITIALIZER;
82
+ if( strchr(zName, '/')!=0 ){
83
+ zAltSkinDir = fossil_strdup(zName);
84
+ return 0;
85
+ }
7686
for(i=0; i<ArraySize(aBuiltinSkin); i++){
7787
if( fossil_strcmp(aBuiltinSkin[i].zLabel, zName)==0 ){
7888
pAltSkin = &aBuiltinSkin[i];
7989
return 0;
8090
}
8191
}
82
- blob_init(&err, aBuiltinSkin[0].zLabel, -1);
92
+ blob_appendf(&err, "available skins: %s", aBuiltinSkin[0].zLabel);
8393
for(i=1; i<ArraySize(aBuiltinSkin); i++){
8494
blob_append(&err, " ", 1);
8595
blob_append(&err, aBuiltinSkin[i].zLabel, -1);
8696
}
8797
return blob_str(&err);
@@ -93,11 +103,11 @@
93103
*/
94104
void skin_override(void){
95105
const char *zSkin = find_option("skin",0,1);
96106
if( zSkin ){
97107
char *zErr = skin_use_alternative(zSkin);
98
- if( zErr ) fossil_fatal("available skins: %s", zErr);
108
+ if( zErr ) fossil_fatal("%s", zErr);
99109
}
100110
}
101111
102112
/*
103113
** The following routines return the various components of the skin
@@ -104,10 +114,20 @@
104114
** that should be used for the current run.
105115
*/
106116
const char *skin_get(const char *zWhat){
107117
const char *zOut;
108118
char *z;
119
+ if( zAltSkinDir ){
120
+ char *z = mprintf("%s/%s.txt", zAltSkinDir, zWhat);
121
+ if( file_isfile(z) ){
122
+ Blob x;
123
+ blob_read_from_file(&x, z);
124
+ fossil_free(z);
125
+ return blob_str(&x);
126
+ }
127
+ fossil_free(z);
128
+ }
109129
if( pAltSkin ){
110130
z = mprintf("skins/%s/%s.txt", pAltSkin->zLabel, zWhat);
111131
zOut = builtin_text(z);
112132
fossil_free(z);
113133
}else{
114134
--- src/skins.c
+++ src/skins.c
@@ -60,28 +60,38 @@
60 **
61 ** The following static variable holds the name of the alternative skin,
62 ** or NULL if the skin should be as configured.
63 */
64 static struct BuiltinSkin *pAltSkin = 0;
 
65
66 /*
67 ** Invoke this routine to set the alternative skin. Return NULL if the
68 ** alternative was successfully installed. Return a string listing all
69 ** available skins if zName does not match an available skin. Memory
70 ** for the returned string comes from fossil_malloc() and should be freed
71 ** by the caller.
 
 
 
 
 
72 */
73 char *skin_use_alternative(const char *zName){
74 int i;
75 Blob err;
 
 
 
 
76 for(i=0; i<ArraySize(aBuiltinSkin); i++){
77 if( fossil_strcmp(aBuiltinSkin[i].zLabel, zName)==0 ){
78 pAltSkin = &aBuiltinSkin[i];
79 return 0;
80 }
81 }
82 blob_init(&err, aBuiltinSkin[0].zLabel, -1);
83 for(i=1; i<ArraySize(aBuiltinSkin); i++){
84 blob_append(&err, " ", 1);
85 blob_append(&err, aBuiltinSkin[i].zLabel, -1);
86 }
87 return blob_str(&err);
@@ -93,11 +103,11 @@
93 */
94 void skin_override(void){
95 const char *zSkin = find_option("skin",0,1);
96 if( zSkin ){
97 char *zErr = skin_use_alternative(zSkin);
98 if( zErr ) fossil_fatal("available skins: %s", zErr);
99 }
100 }
101
102 /*
103 ** The following routines return the various components of the skin
@@ -104,10 +114,20 @@
104 ** that should be used for the current run.
105 */
106 const char *skin_get(const char *zWhat){
107 const char *zOut;
108 char *z;
 
 
 
 
 
 
 
 
 
 
109 if( pAltSkin ){
110 z = mprintf("skins/%s/%s.txt", pAltSkin->zLabel, zWhat);
111 zOut = builtin_text(z);
112 fossil_free(z);
113 }else{
114
--- src/skins.c
+++ src/skins.c
@@ -60,28 +60,38 @@
60 **
61 ** The following static variable holds the name of the alternative skin,
62 ** or NULL if the skin should be as configured.
63 */
64 static struct BuiltinSkin *pAltSkin = 0;
65 static char *zAltSkinDir = 0;
66
67 /*
68 ** Invoke this routine to set the alternative skin. Return NULL if the
69 ** alternative was successfully installed. Return a string listing all
70 ** available skins if zName does not match an available skin. Memory
71 ** for the returned string comes from fossil_malloc() and should be freed
72 ** by the caller.
73 **
74 ** If the alternative skin name contains one or more '/' characters, then
75 ** it is assumed to be a directory on disk that holds override css.txt,
76 ** footer.txt, and header.txt. This mode can be used for interactive
77 ** development of new skins.
78 */
79 char *skin_use_alternative(const char *zName){
80 int i;
81 Blob err = BLOB_INITIALIZER;
82 if( strchr(zName, '/')!=0 ){
83 zAltSkinDir = fossil_strdup(zName);
84 return 0;
85 }
86 for(i=0; i<ArraySize(aBuiltinSkin); i++){
87 if( fossil_strcmp(aBuiltinSkin[i].zLabel, zName)==0 ){
88 pAltSkin = &aBuiltinSkin[i];
89 return 0;
90 }
91 }
92 blob_appendf(&err, "available skins: %s", aBuiltinSkin[0].zLabel);
93 for(i=1; i<ArraySize(aBuiltinSkin); i++){
94 blob_append(&err, " ", 1);
95 blob_append(&err, aBuiltinSkin[i].zLabel, -1);
96 }
97 return blob_str(&err);
@@ -93,11 +103,11 @@
103 */
104 void skin_override(void){
105 const char *zSkin = find_option("skin",0,1);
106 if( zSkin ){
107 char *zErr = skin_use_alternative(zSkin);
108 if( zErr ) fossil_fatal("%s", zErr);
109 }
110 }
111
112 /*
113 ** The following routines return the various components of the skin
@@ -104,10 +114,20 @@
114 ** that should be used for the current run.
115 */
116 const char *skin_get(const char *zWhat){
117 const char *zOut;
118 char *z;
119 if( zAltSkinDir ){
120 char *z = mprintf("%s/%s.txt", zAltSkinDir, zWhat);
121 if( file_isfile(z) ){
122 Blob x;
123 blob_read_from_file(&x, z);
124 fossil_free(z);
125 return blob_str(&x);
126 }
127 fossil_free(z);
128 }
129 if( pAltSkin ){
130 z = mprintf("skins/%s/%s.txt", pAltSkin->zLabel, zWhat);
131 zOut = builtin_text(z);
132 fossil_free(z);
133 }else{
134

Keyboard Shortcuts

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