html2index 1.31 → 1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac3500ba93b1ad1108106100ff3ba3f283365fc1d0e9450166e3665094a1399e
4
- data.tar.gz: 353507e7937e2d346a0c6a84090565137e0b7efd5719f6c86c3de3baa4743811
3
+ metadata.gz: 1456e2bc8e3d35b08d58d69cc1261fceb4ec2fc0e1ee3201f2b953c386978349
4
+ data.tar.gz: 98fd67920f0d97a8ec7398217e9a0e5bc6e36de38607248d69884348d3a706d6
5
5
  SHA512:
6
- metadata.gz: b96ea9f2c1af992b11258d41be02d2440227a7e409f71e2e88ce315bac65c05be300dd8731dc8dd6a6f352ccb2bacd4856a3579d0ec414cdc5e1b9057d765dd4
7
- data.tar.gz: 040a38e2d826e985a74cf294eabc0ff7f3dca73eb08f03135841ddb1965915dfcd264aaac38339702ef176e01eda0567e54077fbc934c6058bcf8debb8b067c2
6
+ metadata.gz: 0d41f7adc915c991c9cd76bbc0fcb5b710e42fb1d1c293d3709e8438c7498638dea55f43ef41c955117da6af6a2ca0ea785ecd741a295066def23988ced49b96
7
+ data.tar.gz: d5ae2d2fa8bc32e8bbd3a61efd4acba0c50132a87b5124e1e29eaed3ea945aa6d8ebdb107d540b516c0d80c49d05a1cf2a3bbc9ce355ef7194e469c04059fbe7
Binary file
Binary file
@@ -267,3 +267,15 @@ accessible. You can also decompress the gem-file to take a look at the code.
267
267
 
268
268
  :AUTHOR: Michael Uplawski <michael[dot]uplawski[at]uplawski[dot]eu>
269
269
 
270
+ This document
271
+ =============
272
+ .. _CC By-ND 4.0: https://creativecommons.org/licenses/by-nd/4.0/
273
+ .. |date| date::
274
+
275
+ ©Michael Uplawski <michael.uplawski@uplawski.eu>
276
+
277
+ License: `CC BY-ND 4.0`_
278
+
279
+ Date: |date|
280
+
281
+ **Ω**
data/html2index.gemspec CHANGED
@@ -10,10 +10,10 @@ Gem::Specification.new do |s|
10
10
  s.description = "creates a glossary from HTML"
11
11
  s.authors = ["Michael Uplawski"]
12
12
  s.email = 'michael.uplawski@uplawski.eu'
13
- s.files = %w~html2index~.collect{|f| 'bin/' << f} + %w~version.rb argparser.rb configuration.rb constants.rb dictionary.rb html2index.rb basic_logging.rb translating.rb user_input.rb definition.rb file_checking.rb log.conf template.rb translations~.collect{|f| 'lib/' << f} + %w~html2index.gemspec~.collect{|f|f} + %w~html/html2index.html man/html2index.1.gz pdf/html2index.pdf rst/html2index.rst~.collect{|f| 'doc/' << f}
13
+ s.files = %w~html2index~.collect{|f| 'bin/' << f} + %w~version.rb argparser.rb config configuration.rb constants.rb dictionary.rb html2index.rb basic_logging.rb translating.rb user_input.rb definition.rb template.rb translations~.collect{|f| 'lib/' << f} + %w~html2index.gemspec~.collect{|f|f} + %w~html/html2index.html man/html2index.1.gz pdf/html2index.pdf rst/html2index.rst~.collect{|f| 'doc/' << f}
14
14
  s.requirements = 'nokogiri, ruby-filemagic'
15
15
  s.add_runtime_dependency 'nokogiri', '~> 1.18', '>= 1.18.10'
16
- s.add_runtime_dependency 'ruby-filemagic', '~> 0.7', '>= 0.7.3'
16
+ s.add_runtime_dependency 'marcel', '~> 1.2', '>= 1.2.1'
17
17
  s.executables = 'html2index'
18
18
  s.metadata = {
19
19
  "homepage_uri" => 'https://www.uplawski.eu/software/',
data/lib/argparser.rb CHANGED
@@ -23,7 +23,7 @@ require_relative 'version'
23
23
  require_relative 'constants'
24
24
 
25
25
  class ArgParser
26
- include BasicLogging
26
+ extend BasicLogging
27
27
  # self.extend(Translating)
28
28
 
29
29
  # Returns a structure describing the options.
@@ -45,8 +45,8 @@ class ArgParser
45
45
  opts.banner = usage
46
46
 
47
47
  opts.on("-d", "--debug", 'Be verbose') do
48
- $log_level = Logger::DEBUG
49
- set_level $log_level
48
+ $log_level = BasicLogging::DEBUG
49
+ set_level BasicLogging::DEBUG
50
50
  end
51
51
 
52
52
  opts.on("-sOURCE", "--source=SOURCE", 'Source document (html)') do |so|
@@ -83,7 +83,6 @@ class ArgParser
83
83
  puts "Start this program with parameter -h or --help to see the usage-message."
84
84
  exit false
85
85
  end
86
- debug('options are ' << options.to_s)
87
86
 
88
87
  options
89
88
  end # parse()
data/lib/basic_logging.rb CHANGED
@@ -21,15 +21,15 @@
21
21
  # Execute this file to see the output.
22
22
  module BasicLogging
23
23
 
24
- DEBUG = 0
25
- INFO = 1
26
- WARN = 2
27
- ERROR = 3
28
- FATAL = 4
29
- UNKNOWN = nil
24
+ DEBUG ||= 0
25
+ INFO ||= 1
26
+ WARN ||= 2
27
+ ERROR ||= 3
28
+ FATAL ||= 4
29
+ UNKNOWN ||= nil
30
30
 
31
31
  # this is mainly for the translation of method calls into log levels
32
- Levels = {:debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR,
32
+ Levels ||= {:debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR,
33
33
  :fatal => FATAL, :unknown => UNKNOWN}
34
34
 
35
35
  @@log_level = UNKNOWN
data/lib/config ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+
3
+ template: "~/template.html "
4
+
5
+ placeholders:
6
+ dict_list : "index"
7
+ glossary : "glossary"
8
+
9
+ fdelim: '%='
10
+
11
+ html_tag: 'span'
12
+ html_attribute: 'class'
13
+ attr_value: 'glossar'
14
+
15
+ dictionaries:
16
+ - dict1:
17
+ name: Merriam-Webster
18
+ url: https://www.merriam-webster.com/thesaurus/
19
+ xpath: ".//span[@class='dt ']"
20
+ color: #a0a000
21
+
22
+ # - dict2
23
+ # name:
24
+ # url:
25
+ # xpath:
26
+ # color:
27
+
data/lib/configuration.rb CHANGED
@@ -17,12 +17,11 @@ require 'yaml'
17
17
  require 'singleton'
18
18
  require 'ostruct'
19
19
  require_relative 'constants'
20
- require_relative 'file_checking'
21
20
  require_relative 'basic_logging'
22
21
  require_relative 'translating'
23
22
 
23
+ # TODO: write default configuration to file !
24
24
  class Configuration
25
- include File_Checking
26
25
  include Translating
27
26
  include BasicLogging
28
27
 
@@ -44,8 +43,17 @@ class Configuration
44
43
  config = confdir << File::Separator << 'config'
45
44
  if(!File.exist?(config ) )
46
45
  begin
47
- File.open(config, 'w') {|co| co.write(File.read(@@config_file))}
48
- info("Created user-version of the configuration-file in\n\t" << config)
46
+ debug 'user cofiguration shall be ' << config
47
+ debug 'reading defaults from ' << @@config_file
48
+ if(File.exist?(@@config_file) )
49
+ File.open(config, 'w+') {|co| co.write(File.read(@@config_file))}
50
+ info("Created user-version of the configuration-file in\n\t" << config)
51
+ else
52
+ warn(@@config_file.dup << ' does not exist!')
53
+ #----------- write default configuration to file --------
54
+
55
+ give_up
56
+ end
49
57
  rescue Exception => ex
50
58
  error('Cannot create the configuration: ' << ex.message)
51
59
  give_up
@@ -77,14 +85,16 @@ class Configuration
77
85
  if(options['config'])
78
86
  cf = options['config']
79
87
  debug('config should be ' << cf.to_s)
80
- msg = file_check(cf, :file, :readable)
81
- if(!msg)
82
- @@config_file = cf
83
- else
84
- msg = ("The file %s " << msg.split[1,100].join(' ')) %msg.split[0]
85
- error(("ERROR! Unsuitable file") << ' ' << msg)
86
- give_up
88
+ [:file?, :readable?].each do |cond|
89
+ if ! File.send(cond, cf)
90
+ msg = cf.dup.to_s << ": Not " << cond.to_s.split('?')[0] << '!'
91
+ error(("ERROR! Unsuitable file") << ' ' << msg)
92
+ # exit
93
+ give_up
94
+ end
87
95
  end
96
+
97
+ @@config_file = cf
88
98
  else
89
99
  @@config_file = user_conf
90
100
  end
@@ -158,7 +168,7 @@ Defaults are: %s~ %[URL_DICT1.dup << ', ' << URL_DICT2.dup])
158
168
  @dicts << Dictionary.new(NAME_DICT2, URL_DICT2, XPATH_DICT2, DICT_COLORS[1])
159
169
  debug('dicts are from constants' << @dicts.to_s)
160
170
  end
161
- warn "HINT: Adapt #{@@config_file} to avoid warnings in the future." if warn
171
+ warn "HINT: Adapt #{@@config_file} to avoid warnings in the future."
162
172
  end
163
173
 
164
174
  # exit on error
data/lib/constants.rb CHANGED
@@ -17,7 +17,7 @@ require_relative 'dictionary'
17
17
  require_relative 'basic_logging'
18
18
  require 'date'
19
19
 
20
- APPNAME = 'HTML2Index'
20
+ APPNAME ||= 'HTML2Index'
21
21
 
22
22
  # URL and xpath for the definitions.
23
23
  #
@@ -43,7 +43,7 @@ DICT_COLORS ||= ['a000a0', '00a000']
43
43
 
44
44
  # definitions which cause problems are logged.
45
45
  PROBLEM_LOG ||= 'html2index_problems.txt'
46
- $log_level = BasicLogging::INFO
46
+ $log_level ||= BasicLogging::INFO
47
47
 
48
48
  # meta-tag for the html-output
49
- GeneratorMeta = "<meta name=\"generator\" content=\"HTML2Index ©2015-#{Date.today.strftime('%Y')} michael.uplawski@uplawski.eu\" />"
49
+ GeneratorMeta ||= "<meta name=\"generator\" content=\"HTML2Index ©2015-#{Date.today.strftime('%Y')} michael.uplawski@uplawski.eu\" />"
data/lib/dictionary.rb CHANGED
@@ -27,6 +27,13 @@ class Dictionary
27
27
  @xpath = xpath
28
28
  @color = color
29
29
  end
30
+
31
+ def valid?
32
+ return (@name && ! @name.empty?
33
+ && @url && ! @url.empty?
34
+ && @xpath && ! @xpath.empty?
35
+ && @color && ! @color.empty?)
36
+ end
30
37
  end
31
38
 
32
39
  ##### TEST
data/lib/html2index.rb CHANGED
@@ -24,14 +24,15 @@ require_relative 'dictionary'
24
24
  require_relative 'template'
25
25
  require 'open-uri'
26
26
  require 'nokogiri'
27
- require 'filemagic'
28
- require_relative 'file_checking'
27
+ require 'marcel'
29
28
  require_relative 'configuration'
30
29
 
31
30
  class HTML2Index
32
31
  include BasicLogging
33
32
  include Nokogiri
34
33
 
34
+
35
+ @@log_level = :debug
35
36
  =begin
36
37
  initialize the HTML2Index-object
37
38
  =end
@@ -45,15 +46,18 @@ class HTML2Index
45
46
  @file = $configuration.source
46
47
 
47
48
  debug("read #{@file}, write #{$configuration.target}")
48
- msg = File_Checking::file_check(@file, :exist?, :readable?, :file?)
49
- if(msg)
50
- error("Error: unsuitable file " <<@file << ": " << msg)
51
- exit false
49
+ msg = ''
50
+ [:exist?, :readable?, :file?].each do |cond|
51
+ if !File.send(cond, @file)
52
+ error("Error: unsuitable file " <<@file << ": NOT " << cond.to_s.split('?')[0] << '!')
53
+ exit false
54
+ end
52
55
  end
53
56
 
54
- ftype = File_Checking::file_type(@file)
57
+ ftype = Marcel::Magic.by_path(@file).subtype
58
+
55
59
  debug('ftype for ' << @file << ' is ' << ftype.to_s)
56
- if(ftype && !ftype.empty? && !ftype[0].downcase.match("(html|xml) .*document") )
60
+ if(ftype && !ftype.empty? && !ftype.downcase.match(/(html|xml)/) )
57
61
  error(@file.dup << ' does not look like a valid file to scan: ' << ftype)
58
62
  exit false
59
63
  end
@@ -101,41 +105,62 @@ class HTML2Index
101
105
  =end
102
106
  def dict_definition(expression)
103
107
  definitions = Array.new
104
- $configuration.dicts.each do |d|
105
- text_array = Array.new
106
- page = nil
107
- begin
108
- url = d.url.dup << URI.encode_www_form_component(expression.gsub(/\s/,'_').gsub("'", ''))
109
- page = Nokogiri::HTML(URI.open(url))
110
- rescue Exception => ex
111
- url_b = d.url.dup << URI.encode_www_form_component(expression.gsub(/\s/,'_'))
112
- warn('WARNING, accessing ' << url << ': ' << ex.message)
113
- if(url_b != url)
114
- warn("\twill try " << url_b)
108
+ if $configuration.dicts && ! $configuration.dicts.empty?
109
+ $configuration.dicts.each do |d|
110
+ if d && d.valid?
111
+ debug 'dict: ' << (d ? d.inspect : ' N I L ')
112
+ text_array = Array.new
113
+ page = nil
115
114
  begin
116
- page = Nokogiri::HTML(URI.open(url_b, "User-Agent"=>"#{APPNAME} #{VERSION}", "From"=>"Function Test <bat.guano@don.blech.e4ward.com>"))
115
+ url = d.url.dup << URI.encode_www_form_component(expression.gsub(/\s/,'_').gsub("'", ''))
116
+ page = Nokogiri::HTML(URI.open(url))
117
117
  rescue Exception => ex
118
- warn("\tWARNING, accessing " << url_b << ': ' << ex.message)
118
+ url_b = d.url.dup << URI.encode_www_form_component(expression.gsub(/\s/,'_'))
119
+ warn('WARNING, accessing ' << url << ': ' << ex.message)
120
+ if(url_b != url)
121
+ warn("\twill try " << url_b)
122
+ begin
123
+ page = Nokogiri::HTML(URI.open(url_b, "User-Agent"=>"#{APPNAME} #{VERSION}", "From"=>"Function Test <bat.guano@don.blech.e4ward.com>"))
124
+ rescue Exception => ex
125
+ warn("\tWARNING, accessing " << url_b << ': ' << ex.message)
126
+ end
127
+ end
128
+ else
129
+ warn 'invalid dictionary definition'
130
+
119
131
  end
120
132
  end
121
- end
122
- if(page)
123
- nodes = page.xpath(d.xpath)
124
- if(nodes)
125
- text_array = nodes.collect {|n| n.inner_text.to_s.strip}
126
- if(!text_array.empty?)
127
- definition = Definition.new(d.name, expression.gsub('_', ' '), text_array)
128
- definition.color = d.color
129
- definitions.push(definition)
133
+ if(page)
134
+ nodes = page.xpath(d.xpath)
135
+ if(nodes)
136
+ text_array = nodes.collect {|n| n.inner_text.to_s.strip}
137
+ if(!text_array.empty?)
138
+ definition = Definition.new(d.name, expression.gsub('_', ' '), text_array)
139
+ definition.color = d.color
140
+ definitions.push(definition)
141
+ end
130
142
  end
143
+ else
144
+ File.open(@problem_log, 'a'){|f| f.write(expression + "\n") }
131
145
  end
132
- else
133
- File.open(@problem_log, 'a'){|f| f.write(expression + "\n") }
134
146
  end
147
+ else
148
+ error 'no dictionaries defined!'
149
+ exit false
135
150
  end
136
151
  return definitions
137
152
  end
138
153
 
154
+ def verify_strings(strs)
155
+ debug 'strings to verify: ' << strs.to_s
156
+ if strs.respond_to?(:to_ary)
157
+ strs.each {|s| return false if(!s || s.strip.empty?) }
158
+ else
159
+ return strs && !(strs.strip).empy?()
160
+ end
161
+ return true
162
+ end
163
+
139
164
  =begin
140
165
  Creates and returns an Array of Definitions.
141
166
  =end
@@ -144,43 +169,57 @@ Creates and returns an Array of Definitions.
144
169
  #TODO: Hash
145
170
  list = Array.new
146
171
  def_list = Array.new
172
+
147
173
  tag = $configuration.html_tag
148
174
  attr = $configuration.html_attribute
149
175
  value = $configuration.attr_value
150
- xpath = ".//#{tag}[contains(@#{attr}, '#{value}')]"
151
- # xpath = './/' << value << '[@' << attr << '="' << value << '"]'
152
- debug('xpath is ' << xpath)
153
- tags = @doc.xpath(xpath)
154
- tags.each do |t|
155
- expression = t.attribute('title').to_s
156
- unless (expression && !expression.strip.empty? )
157
- expression = t.text.to_s
158
- end
159
- if(expression)
160
- expression.gsub!(/\s+/, " ")
161
- expression.strip!
162
- if(!expression.empty? && !def_list.include?(expression) )
163
- if(!list.include?expression.downcase)
164
- list.push expression.downcase
165
- definition = dict_definition(expression)
166
- if(definition && !definition.empty?)
167
- # debug('definition is ' << definition.to_s)
168
- def_list.push(format_index(definition) )
169
- def_list.sort!
176
+
177
+ if verify_strings([tag,attr,value])
178
+ xpath = ".//#{tag}[contains(@#{attr}, '#{value}')]"
179
+ # xpath = './/' << value << '[@' << attr << '="' << value << '"]'
180
+ debug('xpath is ' << xpath)
181
+ tags = @doc.xpath(xpath)
182
+ if(tags && !tags.empty?)
183
+ tags.each do |t|
184
+ expression = t.attribute('title').to_s
185
+ unless (expression && !expression.strip.empty? )
186
+ expression = t.text.to_s
187
+ end
188
+ if(expression)
189
+ expression.gsub!(/\s+/, " ")
190
+ expression.strip!
191
+ if(!expression.empty? && !def_list.include?(expression) )
192
+ if(!list.include?expression.downcase)
193
+ list.push expression.downcase
194
+ definition = dict_definition(expression)
195
+ if(definition && !definition.empty?)
196
+ # debug('definition is ' << definition.to_s)
197
+ def_list.push(format_index(definition) )
198
+ def_list.sort!
199
+ end
200
+ end
170
201
  end
171
202
  end
172
203
  end
204
+ else
205
+ error 'Cannot find any marked tags in the source-file. Aborting!'
206
+ raise SystemExit
207
+ #exit false
173
208
  end
209
+ else
210
+ error 'Configuration incomplete. Verify tag, attribute and attribute value! Aborting!'
211
+ raise SystemExit
212
+ #exit false
174
213
  end
175
- =begin
176
- if(level == Logger::DEBUG)
177
- debug('def_list is ')
178
- def_list.each_with_index{|t, i| debug( "%i %s"%[i, t]) }
179
- end
180
- =end
181
214
  rescue Interrupt => ex
182
215
  warn "--------------\n\tIndex generation interrupted by user\n---------------"
216
+ rescue SystemExit => sx
217
+ raise sx
218
+ rescue Exception => ex
219
+ error( "line #{__LINE__} " << ex.message << ' (' << ex.class.name << ')')
220
+ exit false
183
221
  end
222
+
184
223
  return def_list
185
224
  end
186
225
 
@@ -219,10 +258,12 @@ Formats the definition text.
219
258
  tempfile = nil
220
259
  out = nil
221
260
  out_file = $configuration.target
261
+ debug 'out_file is ' << out_file
222
262
  template = Template.new
263
+ debug 'template is ' << template.to_s
223
264
  if out_file
224
- if(File.exist?(out_file))
225
- if(File.writable?(out_file))
265
+ if(out_file != '<STDOUT>' && File.exist?(out_file) )
266
+ if( File.writable?(out_file) )
226
267
  puts "\nWARNING! File " << out_file << " exists!"
227
268
  print "Do you want to overwrite it? (Y/n) "
228
269
  res = wait_for_user
@@ -237,9 +278,10 @@ Formats the definition text.
237
278
  end
238
279
  end
239
280
  else
240
- debug('out_file is STDOUT')
281
+ info('Writing to ' << out_file)
241
282
  end
242
283
  begin
284
+ debug 'begin'
243
285
  html = template.to_s
244
286
 
245
287
  # create the definitions in index()
data/lib/template.rb CHANGED
@@ -19,7 +19,6 @@ require 'date'
19
19
  require_relative 'basic_logging'
20
20
  require_relative 'dictionary'
21
21
  require_relative 'constants'
22
- require_relative 'file_checking'
23
22
 
24
23
  class Template
25
24
  include BasicLogging
@@ -29,18 +28,17 @@ class Template
29
28
  template_file = $configuration.template
30
29
  @template = nil
31
30
  if template_file
32
- msg = File_Checking::file_check(template_file, :file, :readable )
33
- if !msg
34
- ftype = File_Checking::file_type(template_file)
35
- if ftype && !ftype.empty? && !ftype[0].downcase.match("(html|xml) .*document")
36
- msg = template_file.dup << ' does not look like a valid template file for (x)html: ' << ftype.join('; ')
31
+ error = nil
32
+ [:file?, :readable?].each do |cond|
33
+ if(!File.send(cond, template_file) )
34
+ error = true
35
+ warn('Cannot use template ' << template_file << ': NOT ' << cond.to_s.split('?')[0] << ',' << "\n\tusing default template")
37
36
  end
38
37
  end
39
- if(!msg)
38
+
39
+ if(!error)
40
40
  @template = File.read(template_file)
41
41
  debug('using template ' << template_file)
42
- else
43
- warn('Cannot use template ' << template_file << ': ' << msg << "\n\tusing default template")
44
42
  end
45
43
  end
46
44
  end
data/lib/translating.rb CHANGED
@@ -18,7 +18,6 @@
18
18
  RD = File.expand_path(File.dirname(__FILE__) ) + File::SEPARATOR if !defined?(RD)
19
19
 
20
20
  require 'yaml'
21
- require_relative 'file_checking'
22
21
 
23
22
 
24
23
  # A way to produce translated text in a ruby-program.
@@ -31,21 +30,32 @@ module Translating
31
30
 
32
31
  @@lang = nil
33
32
  @@lang_file = format("%s%s", RD, 'LANG')
34
- @@tr = YAML::load_file("#{RD}translations")
35
-
36
- # find the current language-setting and return it.
37
- def self.language()
38
- if @@lang == nil
39
- r = ENV['LANG']
40
- if(r)
41
- @@lang = r[0, 2]
42
- elsif( !File_Checking::file_check(@@lang_file, [:exist?, :readable?]) && File::size(@@lang_file) >= 2)
43
- File::open(@@lang_file, 'r') {|f| @@lang = f.readline}
44
- @@lang.chomp!.downcase! if @@lang
45
- end
46
- end
47
- @@lang = 'en' if !@@lang
48
- end
33
+ @@tr = YAML::load_file("#{RD}translations")
34
+
35
+ # find the current language-setting and return it.
36
+ def self.language()
37
+ if @@lang == nil
38
+ r = ENV['LANG']
39
+ if(r)
40
+ @@lang = r[0, 2]
41
+ else
42
+ error = nil
43
+ [:exist?, :readable?].each do |cond|
44
+ if(! File.send(cond, @@lang_File))
45
+ error = cond.to_s.split('?')[0]
46
+ end
47
+ end
48
+ if(!error && File::size(@@lang_file) >= 2)
49
+ File::open(@@lang_file, 'r') {|f| @@lang = f.readline}
50
+ @@lang.chomp!.downcase! if @@lang
51
+ else
52
+ warn 'Cannot use ' << @@lang_file << '; file unuseable'
53
+ info 'Language will be English'
54
+ end
55
+ end
56
+ end
57
+ @@lang = 'en' if !@@lang
58
+ end
49
59
 
50
60
  # Translate a string to the currently set langage.
51
61
  # The args parameter may contain replacement-text which
data/lib/version.rb CHANGED
@@ -12,5 +12,5 @@
12
12
  * *
13
13
  ***************************************************************************/
14
14
  =end
15
- VERSION ='1.31'
16
- SUMMARY = "New logging module, new license, homepage and documentation"
15
+ VERSION ='1.32'
16
+ SUMMARY = "Generate a Glossary from a html-page"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2index
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.31'
4
+ version: '1.32'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Uplawski
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-01-16 00:00:00.000000000 Z
10
+ date: 2026-08-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: nokogiri
@@ -30,25 +30,25 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 1.18.10
32
32
  - !ruby/object:Gem::Dependency
33
- name: ruby-filemagic
33
+ name: marcel
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - "~>"
37
37
  - !ruby/object:Gem::Version
38
- version: '0.7'
38
+ version: '1.2'
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 0.7.3
41
+ version: 1.2.1
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.7'
48
+ version: '1.2'
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: 0.7.3
51
+ version: 1.2.1
52
52
  description: creates a glossary from HTML
53
53
  email: michael.uplawski@uplawski.eu
54
54
  executables:
@@ -64,13 +64,12 @@ files:
64
64
  - html2index.gemspec
65
65
  - lib/argparser.rb
66
66
  - lib/basic_logging.rb
67
+ - lib/config
67
68
  - lib/configuration.rb
68
69
  - lib/constants.rb
69
70
  - lib/definition.rb
70
71
  - lib/dictionary.rb
71
- - lib/file_checking.rb
72
72
  - lib/html2index.rb
73
- - lib/log.conf
74
73
  - lib/template.rb
75
74
  - lib/translating.rb
76
75
  - lib/translations
@@ -97,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
96
  version: '0'
98
97
  requirements:
99
98
  - nokogiri, ruby-filemagic
100
- rubygems_version: 3.6.7
99
+ rubygems_version: 4.0.18
101
100
  specification_version: 4
102
- summary: New logging module, new license, homepage and documentation
101
+ summary: Generate a Glossary from a html-page
103
102
  test_files: []
data/lib/file_checking.rb DELETED
@@ -1,98 +0,0 @@
1
- #encoding: UTF-8
2
- =begin
3
- /***************************************************************************
4
- * ©2015-2026, 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 WTFPL, version 2 or later, as published on *
8
- * https://www.wtfpl.net/about/. *
9
- * *
10
- * This program is distributed in the hope that it will be useful, *
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
13
- * *
14
- ***************************************************************************/
15
- =end
16
-
17
- require 'filemagic'
18
-
19
- =begin
20
- A module to facilitate frequently occuring checks on
21
- file-system objects
22
- =end
23
- module File_Checking
24
-
25
- @@text_messages = {
26
- :exist? => "does not exist!",
27
- :exist => "does not exist!",
28
- :readable? => "is not readable!",
29
- :readable => "is not readable!",
30
- :executable? => "is not executable!",
31
- :executable => "is not executable!",
32
- :writable? => "is not writable!",
33
- :writable => "is not writable!",
34
- :directory? => "is not a directory!",
35
- :directory => "is not a directory!",
36
- :file? => "is not a file!",
37
- :file => "is not a file!",
38
- :type => "is not of the right file-type!",
39
- :mime => "does not have the right mime-type!",
40
- }
41
-
42
- # find the file-type for a given file name
43
- def self::file_type(file, mime = false)
44
- fm = FileMagic.fm
45
- file_magic = fm.file(file)
46
- file_mime = nil
47
- if mime
48
- fm.flags = [:mime_type]
49
- file_mime = fm.file(file)
50
- end
51
- return file_magic, file_mime
52
- end
53
-
54
-
55
- # Checks if the file with the name from the first
56
- # parameter has the properties, listed in the second.
57
- # The messages parameter is an array of one or several
58
- # of :exist?, :readable?, :writable?, :directory? or
59
- # their string-representations, respectively.
60
- # Returns nil in case of success, otherwise an
61
- # informative message, describing the first negative
62
- # test-result.
63
- def file_check(file, *messages)
64
- File_Checking.file_check(file, *messages)
65
- end
66
-
67
- # Checks if the file with the name from the first
68
- # parameter has the properties, listed in the second.
69
- # The messages parameter is an array of one or all
70
- # of :exist?, :readable?, :writable?, :directory? or
71
- # their string-representations, respectively.
72
- # Returns nil in case of success, otherwise an
73
- # informative message, describing the first negative
74
- # test-result.
75
- def self.file_check(file, *messages)
76
- msg = nil
77
- if(file && messages.respond_to?(:to_ary) && !messages.empty?)
78
- messages.each do |k|
79
- if(! k.to_s.end_with?('?'))
80
- k = (k.to_s << '?').to_sym
81
- end
82
- @log.debug ('checking ' << k.to_s) if @log
83
- if(msg == nil && File.respond_to?(k) && ! File.send(k, file.to_s))
84
- msg = "#{file} #{@@text_messages[k.to_sym]}"
85
- end
86
- end
87
- end
88
- msg
89
- end
90
- end
91
-
92
- =begin
93
- # example
94
-
95
- include File_Checking
96
- msg = file_check('some_file.txt', [:exist?, :readable?, 'writable'])
97
- puts msg if msg
98
- =end
data/lib/log.conf DELETED
@@ -1,56 +0,0 @@
1
- #encoding: UTF-8
2
- =begin
3
- /***************************************************************************
4
- * ©2013-2015 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
-
22
- A simplified logger configuration. Set the level for each individual logger
23
- below. Choose a different log-device or log-file if you like. Keep the
24
- formatting intact. Do not change other sections of this file.
25
- =end
26
-
27
- # Do not touch from here ----->
28
- require 'logger'
29
-
30
- debug = Logger::DEBUG
31
- info = Logger::INFO
32
- error = Logger::ERROR
33
- fatal = Logger::FATAL
34
- warn = Logger::WARN
35
- unknown = Logger::UNKNOWN
36
- {
37
- # <---------------- to here !
38
-
39
- # Enter your settings here, but take into consideration that not all
40
- # the named classes will really produce readable output. Well, you can
41
- # always try... Either name just the log-level or make the log-level
42
- # precede the output-device or output-file like in the examples.
43
-
44
- # Example: naming a log-file
45
- # :HtmlBuilder => [info, 'C:\temp\htmlbuilder.log']
46
- # :HtmlBuilder => [debug, '/tmp/htmlbuilder.log'],
47
-
48
- :HTML2Index => debug,
49
- :Template => info,
50
- :Configuration => info,
51
- :ArgParser => info,
52
-
53
- # And ignore the remainder, too.
54
- }
55
-
56
- #eof