From 2623019d52fd3bf95a3d86562a7128ef062ed4db Mon Sep 17 00:00:00 2001 From: William Daniau Date: Fri, 11 Oct 2019 15:22:26 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20wize.rb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- style-blue.conf | 4 +- style-template.conf | 81 ++++++++++++++++++++ style-wize.conf | 81 ++++++++++++++++++++ style.conf | 82 +------------------- templates/html/Wize_Print_Template.html | 70 +++++++++++++++++ wize.rb | 129 ++++++++++++++++++++++++++++++-- 6 files changed, 356 insertions(+), 91 deletions(-) create mode 100644 style-template.conf create mode 100644 style-wize.conf mode change 100644 => 120000 style.conf create mode 100644 templates/html/Wize_Print_Template.html diff --git a/style-blue.conf b/style-blue.conf index 78a0d33..072e190 100644 --- a/style-blue.conf +++ b/style-blue.conf @@ -24,11 +24,11 @@ strikethrough=True foreground=grey [Tag code] -foreground=#8B008B +foreground=darkmagenta family=monospace [Tag pre] -foreground=#8B008B +foreground=darkmagenta family=monospace wrap-mode=GTK_WRAP_NONE indent=20 diff --git a/style-template.conf b/style-template.conf new file mode 100644 index 0000000..8f79965 --- /dev/null +++ b/style-template.conf @@ -0,0 +1,81 @@ +# +# Regarder l'aide de zim section Config Files +# +[TextView] +indent=30 +tabs=None +font= +justify= +linespacing=3 +bullet_icon_size=GTK_ICON_SIZE_MENU + +[Tag strong] +weight=PANGO_WEIGHT_BOLD + +[Tag emphasis] +style=PANGO_STYLE_ITALIC + +[Tag mark] +underline=%%--main-menu-u-decoration%% +background=%%--main-menu-u-background-color%% + +[Tag strike] +strikethrough=True +foreground=%%--main-strike-color%% + +[Tag code] +foreground=%%--main-tt-color%% +family=monospace + +[Tag pre] +foreground=%%--main-pre-color%% +family=monospace +wrap-mode=GTK_WRAP_NONE +indent=20 + +[Tag link] +foreground=%%--main-link-color%% + +[Tag tag] +foreground=#ce5c00 + +[Tag h1] +foreground=%%--main-header-color%% +underline=PANGO_UNDERLINE_SINGLE +weight=PANGO_WEIGHT_BOLD +scale=1.75 + +[Tag h2] +foreground=%%--main-header-color%% +weight=PANGO_WEIGHT_BOLD +scale=1.52 +indent=20 + +[Tag h3] +foreground=%%--main-header-color%% +style=PANGO_STYLE_ITALIC +weight=PANGO_WEIGHT_BOLD +scale=1.32 +indent=40 + +[Tag h4] +foreground=%%--main-header-color%% +weight=PANGO_WEIGHT_BOLD +scale=1.15 +indent=60 + +[Tag h5] +foreground=%%--main-header-color%% +weight=PANGO_WEIGHT_BOLD +indent=80 + +[Tag h6] +foreground=%%--main-header-color%% +indent=100 + +[Tag checked-checkbox] + +[Tag xchecked-checkbox] + +[Tag migrated-checkbox] + diff --git a/style-wize.conf b/style-wize.conf new file mode 100644 index 0000000..6a56b5f --- /dev/null +++ b/style-wize.conf @@ -0,0 +1,81 @@ +# +# Regarder l'aide de zim section Config Files +# +[TextView] +indent=30 +tabs=None +font= +justify= +linespacing=3 +bullet_icon_size=GTK_ICON_SIZE_MENU + +[Tag strong] +weight=PANGO_WEIGHT_BOLD + +[Tag emphasis] +style=PANGO_STYLE_ITALIC + +[Tag mark] +underline=PANGO_UNDERLINE_SINGLE +background=white + +[Tag strike] +strikethrough=True +foreground=grey + +[Tag code] +foreground=darkmagenta +family=monospace + +[Tag pre] +foreground=darkmagenta +family=monospace +wrap-mode=GTK_WRAP_NONE +indent=20 + +[Tag link] +foreground=blue + +[Tag tag] +foreground=#ce5c00 + +[Tag h1] +foreground=#4e9a06 +underline=PANGO_UNDERLINE_SINGLE +weight=PANGO_WEIGHT_BOLD +scale=1.75 + +[Tag h2] +foreground=#4e9a06 +weight=PANGO_WEIGHT_BOLD +scale=1.52 +indent=20 + +[Tag h3] +foreground=#4e9a06 +style=PANGO_STYLE_ITALIC +weight=PANGO_WEIGHT_BOLD +scale=1.32 +indent=40 + +[Tag h4] +foreground=#4e9a06 +weight=PANGO_WEIGHT_BOLD +scale=1.15 +indent=60 + +[Tag h5] +foreground=#4e9a06 +weight=PANGO_WEIGHT_BOLD +indent=80 + +[Tag h6] +foreground=#4e9a06 +indent=100 + +[Tag checked-checkbox] + +[Tag xchecked-checkbox] + +[Tag migrated-checkbox] + diff --git a/style.conf b/style.conf deleted file mode 100644 index 64094b7..0000000 --- a/style.conf +++ /dev/null @@ -1,81 +0,0 @@ -# -# Regarder l'aide de zim section Config Files -# -[TextView] -indent=30 -tabs=None -font= -justify= -linespacing=3 -bullet_icon_size=GTK_ICON_SIZE_MENU - -[Tag strong] -weight=PANGO_WEIGHT_BOLD - -[Tag emphasis] -style=PANGO_STYLE_ITALIC - -[Tag mark] -underline=PANGO_UNDERLINE_SINGLE -background=white - -[Tag strike] -strikethrough=True -foreground=grey - -[Tag code] -foreground=#8B008B -family=monospace - -[Tag pre] -foreground=#8B008B -family=monospace -wrap-mode=GTK_WRAP_NONE -indent=20 - -[Tag link] -foreground=blue - -[Tag tag] -foreground=#ce5c00 - -[Tag h1] -foreground=#4e9a06 -underline=PANGO_UNDERLINE_SINGLE -weight=PANGO_WEIGHT_BOLD -scale=1.75 - -[Tag h2] -foreground=#4e9a06 -weight=PANGO_WEIGHT_BOLD -scale=1.52 -indent=20 - -[Tag h3] -foreground=#4e9a06 -style=PANGO_STYLE_ITALIC -weight=PANGO_WEIGHT_BOLD -scale=1.32 -indent=40 - -[Tag h4] -foreground=#4e9a06 -weight=PANGO_WEIGHT_BOLD -scale=1.15 -indent=60 - -[Tag h5] -foreground=#4e9a06 -weight=PANGO_WEIGHT_BOLD -indent=80 - -[Tag h6] -foreground=#4e9a06 -indent=100 - -[Tag checked-checkbox] - -[Tag xchecked-checkbox] - -[Tag migrated-checkbox] - diff --git a/style.conf b/style.conf new file mode 120000 index 0000000..01f2852 --- /dev/null +++ b/style.conf @@ -0,0 +1 @@ +style-wize.conf \ No newline at end of file diff --git a/templates/html/Wize_Print_Template.html b/templates/html/Wize_Print_Template.html new file mode 100644 index 0000000..b35a4cf --- /dev/null +++ b/templates/html/Wize_Print_Template.html @@ -0,0 +1,70 @@ + + + + + [% title %] + + + + + + + + + + + + + + + + + + + + +[% options.empty_lines = "default" %] + + + +
+ +
+ + +[% FOR page IN pages %] + [% page.content %] +[% END %] + + + +
+ + + + + + + diff --git a/wize.rb b/wize.rb index 5a829fe..08d00bc 100755 --- a/wize.rb +++ b/wize.rb @@ -7,6 +7,11 @@ $version = "0.1" $auteur = "William Daniau" $date = "2019 10 11" +# Global directory definitions +$zimShareDir = "#{ENV['HOME']}/.local/share/zim" +$zimHtmlTemplateDir = "#{$zimShareDir}/templates/html" +$zimConfigDir = "#{ENV['HOME']}/.config/zim" + # Parse arguments class class ParseOptions def self.parse(args) @@ -23,6 +28,13 @@ class ParseOptions opts.separator whatIDo + opts.on("-i", + "--install", + "modifie le fichier Wize_Print.html en remplaçant", + "%%HOME%% par la valeur de $HOME") do |l| + options[:install] = l + end + opts.on("-l", "--list", "Liste les configurations disponibles") do |l| @@ -56,7 +68,9 @@ class ParseOptions end end +# Get the config list def listConfigs + Dir.chdir($zimHtmlTemplateDir) a = `ls`.split(/\n/) names = [] r = /^common-(.+)$/ @@ -68,7 +82,9 @@ def listConfigs names end +# Apply a config def applyConfig(name) + Dir.chdir($zimHtmlTemplateDir) list = ["Wize", "Wize_with_index", "Wize_with_index_sod"] list.each { |l| com = "rm -f #{l}/common-spec" @@ -80,10 +96,104 @@ def applyConfig(name) system("ln -s common-#{name} print-common") end +# Is the name a valid config? def configInList?(name, names) names.include? name end +# Re-create Wize_Print.html from template +# and initialize link into zim config directory +def installWize + Dir.chdir($zimHtmlTemplateDir) + begin + printTemplate = File.new("Wize_Print_Template.html", "r") + rescue + puts "cannot open print file for reading" + exit + end + tabfile = [] + stor = '%%HOME%%' + rby = ENV['HOME'] + printTemplate.readlines.each { |line| + line.gsub!(stor,rby) + tabfile.push(line) + } + printTemplate.close + begin + printFile = File.new("Wize_Print.html", "w") + rescue + puts "cannot open print file for writing" + exit + end + tabfile.each { |line| + printFile.write line + } + printFile.close + + Dir.chdir($zimConfigDir) + system("rm -f style.conf") + system("ln -s #{$zimShareDir}/style.conf style.conf") +end + +# Create style-name.conf according to common-name/zim-variables.css +def createStyleFile(name) + lfTags = ["--main-header-color", + "--main-menu-u-decoration", + "--main-menu-u-background-color", + "--main-strike-color", + "--main-tt-color", + "--main-pre-color", + "--main-link-color"] + + # First we load the css file and parse it + Dir.chdir($zimHtmlTemplateDir) + begin + nameCSS = File.new("common-#{name}/zim-variables.css", "r") + rescue + puts "cannot open common-#{name}/zim-variables.css for reading" + exit + end + sCSS = nameCSS.read + regComment = /\/\*.*?\*\//m + sCSS.gsub!(regComment, '') + sTags = {} + lfTags.each { |tag| + var = Regexp.escape(tag) + reg = /#{var}\s*:\s*(\S+)\s*;/ + sCSS =~ reg + sTags[tag] = $1 + # On traite le cas particulier du u-decoration + if tag == "--main-menu-u-decoration" + sTags[tag] = sTags[tag] == 'underline' ? 'PANGO_UNDERLINE_SINGLE' : '' + end + } + + # know read the style template + Dir.chdir($zimShareDir) + begin + styleTemplate = File.new("style-template.conf", "r") + rescue + puts "cannot open style-template.conf for reading" + exit + end + styleTemplateString = styleTemplate.read + lfTags.each { |tag| + styleTemplateString.gsub!("%%#{tag}%%", sTags[tag]) + } + # Now write the file + begin + styleOutput = File.new("style-#{name}.conf", "w") + rescue + puts "cannot open style-#{name}.conf for writing" + exit + end + styleOutput.write styleTemplateString + styleOutput.close + # Now create the symbolic link + system("rm style.conf") + system("ln -s style-#{name}.conf style.conf") +end + # Parse arguments using the class and get results in a hash options = ParseOptions.parse(ARGV) if options.length == 0 @@ -91,17 +201,15 @@ if options.length == 0 exit end -# Directory definitions -zimShareDir = "#{ENV['HOME']}/.local/share/zim" -zimHtmlTemplateDir = "#{zimShareDir}/templates/html" -zimConfigDir = "#{ENV['HOME']}/.config/zim" - -# go into template dir -Dir.chdir(zimHtmlTemplateDir) - # get existing configs configs = listConfigs +# Installation +if options[:install] + installPrintFile + exit +end + # List if options[:list] configs.each { |c| @@ -120,4 +228,9 @@ if options[:conf] end # we have a valid config applyConfig(conf) + createStyleFile(conf) + # + puts "All done!" + puts "Les modifications de templates html sont appliquée directement," + puts "mais il faut redémarrer zim pour que les modifications y aapparaissent" end -- 2.16.4