Commit 2623019d52fd3bf95a3d86562a7128ef062ed4db
1 parent
894cbe327f
Exists in
master
Amélioration de wize.rb
Showing 7 changed files with 356 additions and 91 deletions Side-by-side Diff
style-blue.conf
style-template.conf
1 | +# | |
2 | +# Regarder l'aide de zim section Config Files | |
3 | +# | |
4 | +[TextView] | |
5 | +indent=30 | |
6 | +tabs=None | |
7 | +font= | |
8 | +justify= | |
9 | +linespacing=3 | |
10 | +bullet_icon_size=GTK_ICON_SIZE_MENU | |
11 | + | |
12 | +[Tag strong] | |
13 | +weight=PANGO_WEIGHT_BOLD | |
14 | + | |
15 | +[Tag emphasis] | |
16 | +style=PANGO_STYLE_ITALIC | |
17 | + | |
18 | +[Tag mark] | |
19 | +underline=%%--main-menu-u-decoration%% | |
20 | +background=%%--main-menu-u-background-color%% | |
21 | + | |
22 | +[Tag strike] | |
23 | +strikethrough=True | |
24 | +foreground=%%--main-strike-color%% | |
25 | + | |
26 | +[Tag code] | |
27 | +foreground=%%--main-tt-color%% | |
28 | +family=monospace | |
29 | + | |
30 | +[Tag pre] | |
31 | +foreground=%%--main-pre-color%% | |
32 | +family=monospace | |
33 | +wrap-mode=GTK_WRAP_NONE | |
34 | +indent=20 | |
35 | + | |
36 | +[Tag link] | |
37 | +foreground=%%--main-link-color%% | |
38 | + | |
39 | +[Tag tag] | |
40 | +foreground=#ce5c00 | |
41 | + | |
42 | +[Tag h1] | |
43 | +foreground=%%--main-header-color%% | |
44 | +underline=PANGO_UNDERLINE_SINGLE | |
45 | +weight=PANGO_WEIGHT_BOLD | |
46 | +scale=1.75 | |
47 | + | |
48 | +[Tag h2] | |
49 | +foreground=%%--main-header-color%% | |
50 | +weight=PANGO_WEIGHT_BOLD | |
51 | +scale=1.52 | |
52 | +indent=20 | |
53 | + | |
54 | +[Tag h3] | |
55 | +foreground=%%--main-header-color%% | |
56 | +style=PANGO_STYLE_ITALIC | |
57 | +weight=PANGO_WEIGHT_BOLD | |
58 | +scale=1.32 | |
59 | +indent=40 | |
60 | + | |
61 | +[Tag h4] | |
62 | +foreground=%%--main-header-color%% | |
63 | +weight=PANGO_WEIGHT_BOLD | |
64 | +scale=1.15 | |
65 | +indent=60 | |
66 | + | |
67 | +[Tag h5] | |
68 | +foreground=%%--main-header-color%% | |
69 | +weight=PANGO_WEIGHT_BOLD | |
70 | +indent=80 | |
71 | + | |
72 | +[Tag h6] | |
73 | +foreground=%%--main-header-color%% | |
74 | +indent=100 | |
75 | + | |
76 | +[Tag checked-checkbox] | |
77 | + | |
78 | +[Tag xchecked-checkbox] | |
79 | + | |
80 | +[Tag migrated-checkbox] |
style-wize.conf
1 | +# | |
2 | +# Regarder l'aide de zim section Config Files | |
3 | +# | |
4 | +[TextView] | |
5 | +indent=30 | |
6 | +tabs=None | |
7 | +font= | |
8 | +justify= | |
9 | +linespacing=3 | |
10 | +bullet_icon_size=GTK_ICON_SIZE_MENU | |
11 | + | |
12 | +[Tag strong] | |
13 | +weight=PANGO_WEIGHT_BOLD | |
14 | + | |
15 | +[Tag emphasis] | |
16 | +style=PANGO_STYLE_ITALIC | |
17 | + | |
18 | +[Tag mark] | |
19 | +underline=PANGO_UNDERLINE_SINGLE | |
20 | +background=white | |
21 | + | |
22 | +[Tag strike] | |
23 | +strikethrough=True | |
24 | +foreground=grey | |
25 | + | |
26 | +[Tag code] | |
27 | +foreground=darkmagenta | |
28 | +family=monospace | |
29 | + | |
30 | +[Tag pre] | |
31 | +foreground=darkmagenta | |
32 | +family=monospace | |
33 | +wrap-mode=GTK_WRAP_NONE | |
34 | +indent=20 | |
35 | + | |
36 | +[Tag link] | |
37 | +foreground=blue | |
38 | + | |
39 | +[Tag tag] | |
40 | +foreground=#ce5c00 | |
41 | + | |
42 | +[Tag h1] | |
43 | +foreground=#4e9a06 | |
44 | +underline=PANGO_UNDERLINE_SINGLE | |
45 | +weight=PANGO_WEIGHT_BOLD | |
46 | +scale=1.75 | |
47 | + | |
48 | +[Tag h2] | |
49 | +foreground=#4e9a06 | |
50 | +weight=PANGO_WEIGHT_BOLD | |
51 | +scale=1.52 | |
52 | +indent=20 | |
53 | + | |
54 | +[Tag h3] | |
55 | +foreground=#4e9a06 | |
56 | +style=PANGO_STYLE_ITALIC | |
57 | +weight=PANGO_WEIGHT_BOLD | |
58 | +scale=1.32 | |
59 | +indent=40 | |
60 | + | |
61 | +[Tag h4] | |
62 | +foreground=#4e9a06 | |
63 | +weight=PANGO_WEIGHT_BOLD | |
64 | +scale=1.15 | |
65 | +indent=60 | |
66 | + | |
67 | +[Tag h5] | |
68 | +foreground=#4e9a06 | |
69 | +weight=PANGO_WEIGHT_BOLD | |
70 | +indent=80 | |
71 | + | |
72 | +[Tag h6] | |
73 | +foreground=#4e9a06 | |
74 | +indent=100 | |
75 | + | |
76 | +[Tag checked-checkbox] | |
77 | + | |
78 | +[Tag xchecked-checkbox] | |
79 | + | |
80 | +[Tag migrated-checkbox] |
style.conf
1 | -# | |
2 | -# Regarder l'aide de zim section Config Files | |
3 | -# | |
4 | -[TextView] | |
5 | -indent=30 | |
6 | -tabs=None | |
7 | -font= | |
8 | -justify= | |
9 | -linespacing=3 | |
10 | -bullet_icon_size=GTK_ICON_SIZE_MENU | |
11 | - | |
12 | -[Tag strong] | |
13 | -weight=PANGO_WEIGHT_BOLD | |
14 | - | |
15 | -[Tag emphasis] | |
16 | -style=PANGO_STYLE_ITALIC | |
17 | - | |
18 | -[Tag mark] | |
19 | -underline=PANGO_UNDERLINE_SINGLE | |
20 | -background=white | |
21 | - | |
22 | -[Tag strike] | |
23 | -strikethrough=True | |
24 | -foreground=grey | |
25 | - | |
26 | -[Tag code] | |
27 | -foreground=#8B008B | |
28 | -family=monospace | |
29 | - | |
30 | -[Tag pre] | |
31 | -foreground=#8B008B | |
32 | -family=monospace | |
33 | -wrap-mode=GTK_WRAP_NONE | |
34 | -indent=20 | |
35 | - | |
36 | -[Tag link] | |
37 | -foreground=blue | |
38 | - | |
39 | -[Tag tag] | |
40 | -foreground=#ce5c00 | |
41 | - | |
42 | -[Tag h1] | |
43 | -foreground=#4e9a06 | |
44 | -underline=PANGO_UNDERLINE_SINGLE | |
45 | -weight=PANGO_WEIGHT_BOLD | |
46 | -scale=1.75 | |
47 | - | |
48 | -[Tag h2] | |
49 | -foreground=#4e9a06 | |
50 | -weight=PANGO_WEIGHT_BOLD | |
51 | -scale=1.52 | |
52 | -indent=20 | |
53 | - | |
54 | -[Tag h3] | |
55 | -foreground=#4e9a06 | |
56 | -style=PANGO_STYLE_ITALIC | |
57 | -weight=PANGO_WEIGHT_BOLD | |
58 | -scale=1.32 | |
59 | -indent=40 | |
60 | - | |
61 | -[Tag h4] | |
62 | -foreground=#4e9a06 | |
63 | -weight=PANGO_WEIGHT_BOLD | |
64 | -scale=1.15 | |
65 | -indent=60 | |
66 | - | |
67 | -[Tag h5] | |
68 | -foreground=#4e9a06 | |
69 | -weight=PANGO_WEIGHT_BOLD | |
70 | -indent=80 | |
71 | - | |
72 | -[Tag h6] | |
73 | -foreground=#4e9a06 | |
74 | -indent=100 | |
75 | - | |
76 | -[Tag checked-checkbox] | |
77 | - | |
78 | -[Tag xchecked-checkbox] | |
79 | - | |
80 | -[Tag migrated-checkbox] |
style.conf
1 | +style-wize.conf |
templates/html/Wize_Print_Template.html
1 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
2 | +<html> | |
3 | +<head> | |
4 | + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
5 | + <title>[% title %]</title> | |
6 | + <meta name='Generator' content='[% generator.name %]'> | |
7 | + <!-- ATTENTION Le template Print ne supporte pas les ressources, | |
8 | + Il faut mettre des chemins absolus sur les fichiers :( --> | |
9 | + <link rel="stylesheet" | |
10 | + href="file:///%%HOME%%/.local/share/zim/templates/html/print-common/zim-variables.css" > | |
11 | + <link rel="stylesheet" | |
12 | + href="file:///%%HOME%%/.local/share/zim/templates/html/common/zim-style.css" > | |
13 | + <link rel="stylesheet" | |
14 | + href="file:///%%HOME%%/.local/share/zim/templates/html/common/zim-table-style.css" > | |
15 | + <link rel="stylesheet" | |
16 | + href="file:///%%HOME%%/.local/share/zim/templates/html/common/zim-special.css" > | |
17 | + <link rel="stylesheet" | |
18 | + href="file:///%%HOME%%/.local/share/zim/templates/html/common/zim-hljs.css" > | |
19 | + <style type='text/css'> | |
20 | + | |
21 | + * { font-family: serif } | |
22 | + | |
23 | + /* Centre les images mais elles sont coupées aux sauts de page à l'impression */ | |
24 | + /*img { | |
25 | + display: block; | |
26 | + margin-left: auto; | |
27 | + margin-right: auto; | |
28 | + }*/ | |
29 | + | |
30 | + </style> | |
31 | + | |
32 | + <!-- Themes clair : | |
33 | + atom-one-light.css, vs.css | |
34 | + Themes sombres : | |
35 | + agate.css, vs2015.css, atom-one-dark.css | |
36 | + Demo live : https://highlightjs.org/static/demo/ --> | |
37 | + <link rel="stylesheet" | |
38 | + href="file:///%%HOME%%/.local/share/zim/templates/html/common/hljs/styles/atom-one-light-wb.css" > | |
39 | + | |
40 | + <!-- hljs --> | |
41 | + <script src="file:///%%HOME%%/.local/share/zim/templates/html/common/hljs/highlight.pack.js"></script> | |
42 | + | |
43 | + <script src="file:///%%HOME%%/.local/share/zim/templates/html/print-common/notice.js"></script> | |
44 | + | |
45 | +</head> | |
46 | +<body> | |
47 | + | |
48 | +[% options.empty_lines = "default" %] | |
49 | + | |
50 | +<!-- Wiki content --> | |
51 | + | |
52 | +<div style="float:right"> | |
53 | +<img src="file:///%%HOME%%/.local/share/zim/templates/html/print-common/logo.png" alt=' '> | |
54 | +</div> | |
55 | + | |
56 | + | |
57 | +[% FOR page IN pages %] | |
58 | + [% page.content %] | |
59 | +[% END %] | |
60 | + | |
61 | +<!-- End wiki content --> | |
62 | + | |
63 | +<div id="foot-notice" class="notice"></div> | |
64 | + | |
65 | +<script src="file:///%%HOME%%/.local/share/zim/templates/html/common/go-hljs.js"></script> | |
66 | +<script>printNotice()</script> | |
67 | + | |
68 | +</body> | |
69 | + | |
70 | +</html> |
wize.rb
... | ... | @@ -7,6 +7,11 @@ |
7 | 7 | $auteur = "William Daniau" |
8 | 8 | $date = "2019 10 11" |
9 | 9 | |
10 | +# Global directory definitions | |
11 | +$zimShareDir = "#{ENV['HOME']}/.local/share/zim" | |
12 | +$zimHtmlTemplateDir = "#{$zimShareDir}/templates/html" | |
13 | +$zimConfigDir = "#{ENV['HOME']}/.config/zim" | |
14 | + | |
10 | 15 | # Parse arguments class |
11 | 16 | class ParseOptions |
12 | 17 | def self.parse(args) |
... | ... | @@ -23,6 +28,13 @@ |
23 | 28 | |
24 | 29 | opts.separator whatIDo |
25 | 30 | |
31 | + opts.on("-i", | |
32 | + "--install", | |
33 | + "modifie le fichier Wize_Print.html en remplaçant", | |
34 | + "%%HOME%% par la valeur de $HOME") do |l| | |
35 | + options[:install] = l | |
36 | + end | |
37 | + | |
26 | 38 | opts.on("-l", |
27 | 39 | "--list", |
28 | 40 | "Liste les configurations disponibles") do |l| |
29 | 41 | |
... | ... | @@ -56,7 +68,9 @@ |
56 | 68 | end |
57 | 69 | end |
58 | 70 | |
71 | +# Get the config list | |
59 | 72 | def listConfigs |
73 | + Dir.chdir($zimHtmlTemplateDir) | |
60 | 74 | a = `ls`.split(/\n/) |
61 | 75 | names = [] |
62 | 76 | r = /^common-(.+)$/ |
63 | 77 | |
... | ... | @@ -68,7 +82,9 @@ |
68 | 82 | names |
69 | 83 | end |
70 | 84 | |
85 | +# Apply a config | |
71 | 86 | def applyConfig(name) |
87 | + Dir.chdir($zimHtmlTemplateDir) | |
72 | 88 | list = ["Wize", "Wize_with_index", "Wize_with_index_sod"] |
73 | 89 | list.each { |l| |
74 | 90 | com = "rm -f #{l}/common-spec" |
75 | 91 | |
... | ... | @@ -80,10 +96,104 @@ |
80 | 96 | system("ln -s common-#{name} print-common") |
81 | 97 | end |
82 | 98 | |
99 | +# Is the name a valid config? | |
83 | 100 | def configInList?(name, names) |
84 | 101 | names.include? name |
85 | 102 | end |
86 | 103 | |
104 | +# Re-create Wize_Print.html from template | |
105 | +# and initialize link into zim config directory | |
106 | +def installWize | |
107 | + Dir.chdir($zimHtmlTemplateDir) | |
108 | + begin | |
109 | + printTemplate = File.new("Wize_Print_Template.html", "r") | |
110 | + rescue | |
111 | + puts "cannot open print file for reading" | |
112 | + exit | |
113 | + end | |
114 | + tabfile = [] | |
115 | + stor = '%%HOME%%' | |
116 | + rby = ENV['HOME'] | |
117 | + printTemplate.readlines.each { |line| | |
118 | + line.gsub!(stor,rby) | |
119 | + tabfile.push(line) | |
120 | + } | |
121 | + printTemplate.close | |
122 | + begin | |
123 | + printFile = File.new("Wize_Print.html", "w") | |
124 | + rescue | |
125 | + puts "cannot open print file for writing" | |
126 | + exit | |
127 | + end | |
128 | + tabfile.each { |line| | |
129 | + printFile.write line | |
130 | + } | |
131 | + printFile.close | |
132 | + | |
133 | + Dir.chdir($zimConfigDir) | |
134 | + system("rm -f style.conf") | |
135 | + system("ln -s #{$zimShareDir}/style.conf style.conf") | |
136 | +end | |
137 | + | |
138 | +# Create style-name.conf according to common-name/zim-variables.css | |
139 | +def createStyleFile(name) | |
140 | + lfTags = ["--main-header-color", | |
141 | + "--main-menu-u-decoration", | |
142 | + "--main-menu-u-background-color", | |
143 | + "--main-strike-color", | |
144 | + "--main-tt-color", | |
145 | + "--main-pre-color", | |
146 | + "--main-link-color"] | |
147 | + | |
148 | + # First we load the css file and parse it | |
149 | + Dir.chdir($zimHtmlTemplateDir) | |
150 | + begin | |
151 | + nameCSS = File.new("common-#{name}/zim-variables.css", "r") | |
152 | + rescue | |
153 | + puts "cannot open common-#{name}/zim-variables.css for reading" | |
154 | + exit | |
155 | + end | |
156 | + sCSS = nameCSS.read | |
157 | + regComment = /\/\*.*?\*\//m | |
158 | + sCSS.gsub!(regComment, '') | |
159 | + sTags = {} | |
160 | + lfTags.each { |tag| | |
161 | + var = Regexp.escape(tag) | |
162 | + reg = /#{var}\s*:\s*(\S+)\s*;/ | |
163 | + sCSS =~ reg | |
164 | + sTags[tag] = $1 | |
165 | + # On traite le cas particulier du u-decoration | |
166 | + if tag == "--main-menu-u-decoration" | |
167 | + sTags[tag] = sTags[tag] == 'underline' ? 'PANGO_UNDERLINE_SINGLE' : '' | |
168 | + end | |
169 | + } | |
170 | + | |
171 | + # know read the style template | |
172 | + Dir.chdir($zimShareDir) | |
173 | + begin | |
174 | + styleTemplate = File.new("style-template.conf", "r") | |
175 | + rescue | |
176 | + puts "cannot open style-template.conf for reading" | |
177 | + exit | |
178 | + end | |
179 | + styleTemplateString = styleTemplate.read | |
180 | + lfTags.each { |tag| | |
181 | + styleTemplateString.gsub!("%%#{tag}%%", sTags[tag]) | |
182 | + } | |
183 | + # Now write the file | |
184 | + begin | |
185 | + styleOutput = File.new("style-#{name}.conf", "w") | |
186 | + rescue | |
187 | + puts "cannot open style-#{name}.conf for writing" | |
188 | + exit | |
189 | + end | |
190 | + styleOutput.write styleTemplateString | |
191 | + styleOutput.close | |
192 | + # Now create the symbolic link | |
193 | + system("rm style.conf") | |
194 | + system("ln -s style-#{name}.conf style.conf") | |
195 | +end | |
196 | + | |
87 | 197 | # Parse arguments using the class and get results in a hash |
88 | 198 | options = ParseOptions.parse(ARGV) |
89 | 199 | if options.length == 0 |
90 | 200 | |
... | ... | @@ -91,17 +201,15 @@ |
91 | 201 | exit |
92 | 202 | end |
93 | 203 | |
94 | -# Directory definitions | |
95 | -zimShareDir = "#{ENV['HOME']}/.local/share/zim" | |
96 | -zimHtmlTemplateDir = "#{zimShareDir}/templates/html" | |
97 | -zimConfigDir = "#{ENV['HOME']}/.config/zim" | |
98 | - | |
99 | -# go into template dir | |
100 | -Dir.chdir(zimHtmlTemplateDir) | |
101 | - | |
102 | 204 | # get existing configs |
103 | 205 | configs = listConfigs |
104 | 206 | |
207 | +# Installation | |
208 | +if options[:install] | |
209 | + installPrintFile | |
210 | + exit | |
211 | +end | |
212 | + | |
105 | 213 | # List |
106 | 214 | if options[:list] |
107 | 215 | configs.each { |c| |
... | ... | @@ -120,5 +228,10 @@ |
120 | 228 | end |
121 | 229 | # we have a valid config |
122 | 230 | applyConfig(conf) |
231 | + createStyleFile(conf) | |
232 | + # | |
233 | + puts "All done!" | |
234 | + puts "Les modifications de templates html sont appliquée directement," | |
235 | + puts "mais il faut redémarrer zim pour que les modifications y aapparaissent" | |
123 | 236 | end |