html2index 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/template.rb ADDED
@@ -0,0 +1,134 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2017-2017 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+ require 'logger'
23
+ require 'date'
24
+ require_relative 'logging'
25
+ require_relative 'dictionary'
26
+ require_relative 'constants'
27
+ require_relative 'file_checking'
28
+
29
+ class Template
30
+ self.extend(Logging)
31
+ @@log = init_logger
32
+
33
+ def initialize()
34
+ @log = @@log
35
+ @log.level = $log_level
36
+ template_file = $configuration.template
37
+ @template = nil
38
+ if template_file
39
+ msg = File_Checking::file_check(template_file, :file, :readable )
40
+ if !msg
41
+ ftype = File_Checking::file_type(template_file)
42
+ if ftype && !ftype.empty? && !ftype[0].downcase.match("(html|xml) .*document")
43
+ msg = template_file.dup << ' does not look like a valid template file for (x)html: ' << ftype.join('; ')
44
+ end
45
+ end
46
+ if(!msg)
47
+ @template = File.read(template_file)
48
+ @log.debug('using template ' << template_file)
49
+ else
50
+ @log.warn('Cannot use template ' << template_file << ': ' << msg << "\n\tusing default template")
51
+ end
52
+ end
53
+ end
54
+
55
+ def to_s
56
+ str = nil
57
+ if @template && @template.respond_to?(:to_str)
58
+ str = @template
59
+ else
60
+ @log.warn('Empty template, using default!')
61
+ str = @@def_template
62
+ end
63
+ str
64
+ end
65
+
66
+ attr_accessor :template
67
+
68
+ def self::default(name)
69
+ case name
70
+ when :fdelim
71
+ @@fdelim
72
+ when :placeholders
73
+ @@placeholders
74
+ when :def_template
75
+ @@def_template
76
+ else
77
+ @log.error('Do not know ' << name.to_s)
78
+ @log.error('Aborting. Bye!')
79
+ end
80
+ end
81
+
82
+ @@fdelim = '%='
83
+ @@placeholders = {:dict_list => 'dict_list', :glossary => 'index'}
84
+ @@def_template = %~<?xml version="1.0" encoding="utf-8"?>
85
+ <!-- created with HTML2Index #{VERSION}-->
86
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
87
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
88
+
89
+ <html xmlns="http://www.w3.org/1999/xhtml">
90
+ <head>
91
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
92
+ <meta http-equiv="Content-Style-Type" content="text/css" />
93
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
94
+ <meta http-equiv="Content-Type" content="application/xhtml+xml" />
95
+ <meta name="revisit-after" content="30 days" />
96
+
97
+ <title>Glossaire</title>
98
+ <style type="text/css">
99
+ body {font-family:LinuxBiolinum, Trebuchet;}
100
+ h1 {margin-left:1em; margin-bottom:1em;}
101
+ div.content {margin-bottom:9em;margin-left:2em;width:80%;border:1px solid #000060;padding:1em;border-radius:1em;}
102
+ div.sources {border:0.5pt solid #000060;border-radius:1em;padding:0 0.5em 0 0.5em;background-color:#e0e0f0;margin:3em;width:40em;}
103
+ dt {font-weight:bold;color:#000070;}
104
+ div.navtop {border:1px solid #000000;border-radius:1em;background-color:#ffffff;font-weight:bold;font-size:1.3em;position:fixed;top:1em;right:7em;}
105
+ a {text-decoration:none;}
106
+ a:hover {border:1px solid #800000;border-radius:1em;}
107
+ dd i {text-decoration:underline;}
108
+ #omega {color:#a000a0;font-weight:bold;text-align:right;margin-right:12em;}
109
+ </style>
110
+ </head>
111
+ <body>
112
+ <div class="navtop" title="début"><a href="#top">&#x21e7;</a></div>
113
+ <div><a id="top"></a></div>
114
+ <p style="position:absolute;right:2em;top:2em;">généré avec html2index #{VERSION}, #{Date.today.to_s}</p>
115
+ <h1>Glossaire </h1>
116
+ <div class="sources">
117
+ <h2>Sources</h2>
118
+ <!-- ============================ -->
119
+ <!-- Insert list of dictionaries -->
120
+ #{@@fdelim}#{@@placeholders[:dict_list]}#{@@fdelim.reverse}
121
+ <!-- ============================ -->
122
+ </div>
123
+
124
+ <div class="content">
125
+ <!-- ============================ -->
126
+ <!-- Insert glossary -->
127
+ #{@@fdelim}#{@@placeholders[:glossary]}#{@@fdelim.reverse}
128
+ <!-- ============================ -->
129
+ <div id="omega">&Omega;</div>
130
+ </div>
131
+ </body>
132
+ </html>~
133
+
134
+ end
@@ -0,0 +1,89 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2011-2017, Michael Uplawski *
5
+ * <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************/
22
+ =end
23
+
24
+
25
+ RD = File.expand_path(File.dirname(__FILE__) ) + File::SEPARATOR if !defined?(RD)
26
+
27
+ require 'yaml'
28
+ require_relative 'file_checking'
29
+
30
+
31
+ # A way to produce translated text in a ruby-program.
32
+ # Translations are read from a file "translations" in the program folder.
33
+ module Translating
34
+ # There are better ways to extend a translated
35
+ # string, but I keep the 'wild-card' for
36
+ # historical reasons.
37
+ @@awild = 'XX'
38
+
39
+ @@lang = nil
40
+ @@lang_file = format("%s%s", RD, 'LANG')
41
+ @@tr = YAML::load_file("#{RD}translations")
42
+
43
+ # find the current language-setting and return it.
44
+ def self.language()
45
+ if @@lang == nil
46
+ r = ENV['LANG']
47
+ if(r)
48
+ @@lang = r[0, 2]
49
+ elsif( !File_Checking::file_check(@@lang_file, [:exist?, :readable?]) && File::size(@@lang_file) >= 2)
50
+ File::open(@@lang_file, 'r') {|f| @@lang = f.readline}
51
+ @@lang.chomp!.downcase! if @@lang
52
+ end
53
+ end
54
+ @@lang = 'en' if !@@lang
55
+ end
56
+
57
+ # Translate a string to the currently set langage.
58
+ # The args parameter may contain replacement-text which
59
+ # will appear at the positions indicated by wildcard-characters
60
+ # in the original string.
61
+ def self.trl(t, *args)
62
+ Translating::language()
63
+ lt = @@tr[t]
64
+ if(lt)
65
+ lt = lt[@@lang]
66
+ else
67
+ # File.open('/tmp/mtf', 'a+') {|f| f << t << "\n"}
68
+ puts "\nTRANSLATION MISSING: \"" << t << "\""
69
+ end
70
+ lt ||= t
71
+ if(args && !args.empty?)
72
+ i = -1
73
+ lt = lt.gsub(@@awild) do |a|
74
+ i += 1
75
+ args.flatten[i]
76
+ end
77
+ lt += args[i + 1, args.length].join
78
+ end
79
+ return lt
80
+ end
81
+
82
+ # Translate a string to the currently set langage.
83
+ # The args parameter may contain replacement-text which
84
+ # will appear at the positions indicated by wildcard-characters
85
+ # in the original string.
86
+ def trl(t, *args )
87
+ Translating::trl(t, args)
88
+ end
89
+ end
data/lib/translations ADDED
File without changes
data/lib/user_input.rb ADDED
@@ -0,0 +1,45 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ /***************************************************************************
5
+ * Copyright © 2014, Michael Uplawski <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************/
22
+ =end
23
+
24
+ require 'io/wait'
25
+ require 'io/console'
26
+
27
+ def wait_for_user()
28
+ char = nil
29
+ STDIN.raw do
30
+ STDIN.noecho do
31
+ until (STDIN.ready?)
32
+ sleep(0.1)
33
+ end
34
+
35
+ char = (STDIN.read_nonblock(1).ord rescue nil)
36
+ end
37
+ end
38
+ return char
39
+ end
40
+
41
+ #### TEST
42
+ if __FILE__ == $0
43
+ puts 'hit any key'
44
+ puts wait_for_user().chr
45
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,12 @@
1
+ #
2
+ # DON'T FORGET SCHWEINE-MET ON THE FENSTERBRETT !!
3
+ # =================================================
4
+ # - Change gemspec !!
5
+ # - Change version in the doc/rst folder !!
6
+ # - INSTALL AND TEST THAT GEM !!
7
+ # - gem push
8
+ #
9
+ # - blame yourself.
10
+ #
11
+ VERSION='1.2.1'
12
+
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html2index
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Uplawski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.10.9
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.9
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-filemagic
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.7.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.7.2
53
+ description: creates a glossary from HTML
54
+ email: michael.uplawski@uplawski.eu
55
+ executables:
56
+ - html2index
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - bin/html2index
61
+ - doc/html/html2index.html
62
+ - doc/man/html2index.1.gz
63
+ - doc/pdf/html2index.pdf
64
+ - doc/rst/html2index.rst
65
+ - html2index.gemspec
66
+ - lib/argparser.rb
67
+ - lib/configuration.rb
68
+ - lib/constants.rb
69
+ - lib/definition.rb
70
+ - lib/dictionary.rb
71
+ - lib/file_checking.rb
72
+ - lib/html2index.rb
73
+ - lib/log.conf
74
+ - lib/logging.rb
75
+ - lib/template.rb
76
+ - lib/translating.rb
77
+ - lib/translations
78
+ - lib/user_input.rb
79
+ - lib/version.rb
80
+ homepage: http://www.souris-libre.fr
81
+ licenses:
82
+ - GPL-3.0
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.7.1
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements:
99
+ - nokogiri, ruby-filemagic
100
+ rubygems_version: 3.1.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: updated dependencies, updated use of the URI module.
104
+ test_files: []