flnews_post_proc 1.57 → 1.60

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b1429b1ae2eb519f5e35c6f12a6cb56705a4b24b87a33111af776f3759addd9
4
- data.tar.gz: 33009debfaadea2a4e1c2868d3eac2c74ff1216601bb511fc418702a51966511
3
+ metadata.gz: 501b73b0978b60f22ec85311eb7b9f66df77802e963eec5ed9bf7e86066604fc
4
+ data.tar.gz: 985d92d55cf867f297f4ec3ceb337091495918d869b48d105b38452412835ff0
5
5
  SHA512:
6
- metadata.gz: 07ae7873e4f1786ee8b12b0b3b38be2f9e3245714de8675495ba6ca0b037828dbfae9c232f72ee44ed906fa38d4e0a8edae4d5f5c39428d9237287e08be549df
7
- data.tar.gz: 897130b05216307f37d67143e0875179745fbd8bed256821075b6236619e99977e7143597d308be13fdad449c550e53c1e7b59109d3d8109f120c3415da5bff2
6
+ metadata.gz: 2a5d65c1484b211db45f9af9b98f31eabb928cce5707fa7b661166ac02593d52bb76a00aef5e0fe36657b24c13e14faf3b3ce86192c4a8e23a96689f488ec7da
7
+ data.tar.gz: 33563ad93400d39082bf888618a8b43801a98b486bb678a458bb16a09797480c52f3d310d61ce4549ba7dc0c4d1b68fa7cb7921802513440a5ef494c81f94469
data/bin/flnews_post_proc CHANGED
@@ -47,9 +47,16 @@ msg = PROGNAME.dup << ' ' << PROGVERSION << ' starting'
47
47
  msg = "–––––– " << msg << " ––––––"
48
48
  info msg
49
49
  # Get a configuration
50
+ # this call results in the configuration file to be
51
+ # read and interpreted. As the log depends on the
52
+ # configuration, errors may render the debug-log
53
+ # unavailable. See STDERR in these cases, i.e.
54
+ # call the program on the command-line and pipe-in
55
+ # a message. Is this okay?
50
56
  config = Configuration::instance
51
57
 
52
- # store the path to the main executable
58
+ # Store the path to the main executable
59
+ # ... Forgot what this should be good for.
53
60
  # config.set(:BINDIR, File::dirname(__FILE__) )
54
61
 
55
62
  # Only if data is on STDIN
@@ -59,6 +66,8 @@ if (!STDIN.tty?)
59
66
 
60
67
  # There is content, create the post-processor.
61
68
  if !artext.strip.empty?
69
+ # Be sure to know what you are doing.
70
+ # Ask around in case of doubt.
62
71
  mime = FileMagic.mime.buffer artext
63
72
  debug('mime is ' << mime)
64
73
  if ['news', 'rfc822'].any? {|m| mime.start_with?('message/' << m) }
@@ -80,8 +89,9 @@ if (!STDIN.tty?)
80
89
  debug('new config: ' << config.inspect)
81
90
  end
82
91
  #<--------------
92
+ # Do it:
83
93
  pp = PostProcessor.new(artext)
84
- # ... and print its result.
94
+ # and get a result.
85
95
  article = pp.article
86
96
  if article
87
97
  # -------------> The main objective <------
data/lib/body.rb CHANGED
@@ -1,21 +1,54 @@
1
1
  #encoding: UTF-8
2
2
 
3
3
  =begin
4
- /***************************************************************************
5
- * 2023-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
6
- * This program is free software; you can redistribute it and/or modify *
7
- * it under the terms of the WTFPL 2.0 or later, see *
8
- * http://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
- ***************************************************************************/
4
+ /***************************************************************************
5
+ * 2023-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the WTFPL 2.0 or later, see *
8
+ * http://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
15
  =end
16
16
 
17
17
  require_relative 'basic_logging'
18
- require_relative 'configuration'
18
+ require_relative 'configuration'
19
+
20
+ WRAP_LENGTH = 65
21
+ # Endow the String class with a wrap function.
22
+ # This is not yet applicable to the message body, itself.
23
+ class String
24
+ include BasicLogging
25
+ public
26
+ # wraps at length, returns the result
27
+ def wrap! (length = WRAP_LENGTH, indent = 0)
28
+ max = length
29
+
30
+ line = 0
31
+ out = [""]
32
+
33
+ self.gsub!("\r\n", " ")
34
+ self.gsub!(" ", " ")
35
+
36
+ words = self.split(" ")
37
+
38
+ while !words.empty?
39
+ word = words.shift.strip
40
+ break if not word
41
+ if out[line].length + word.length > max
42
+ out[line].squeeze!(" ")
43
+ line += 1
44
+ out[line] = (line > 0 ? " " * indent : "")
45
+ end
46
+ out[line] << word + " "
47
+ end
48
+ self.replace( out.join("\r\n"))
49
+ end
50
+
51
+ end
19
52
 
20
53
  # An object of this class represents the body of a news-article.
21
54
  # It processes the original text and changes some details:
@@ -104,7 +137,7 @@ class Body
104
137
  # exchange original intro-line against the new one
105
138
  @lines[@lines.index(ointro)] = intro.strip
106
139
  # looked complicated because it is.
107
-
140
+
108
141
  # keep this line for reference.
109
142
  @intro = intro
110
143
  else
@@ -141,7 +174,7 @@ class Body
141
174
  # TODO : Concentrate all URL/URI munging functionality in 1 or 2 helper
142
175
  # classes, e.g. Body::News and Body::Http
143
176
  # <------
144
-
177
+
145
178
  # Verify and possibly correct links in the post.
146
179
  # Simple.
147
180
  def handle_uris()
@@ -149,11 +182,11 @@ class Body
149
182
  # Default is no. nil or '' do qualify as default.
150
183
  debug 'verify URLs ? ' << @@config.VFY_URLS.to_s
151
184
  if @@config.VFY_URLS
152
- debug 'verifying URLs'
185
+ debug 'verifying URLs'
153
186
  @lines.each_with_index do | l, i |
154
187
  # leave cited lines as they are.
155
188
  if !l.start_with?( '>')
156
- =begin
189
+ =begin Currently Unused
157
190
  # IMPORTANT --------------------------------->
158
191
  # IT IS HENCEFORTH PROHIBITED TO WRITE AN EMAIL-ADDRESS
159
192
  # IN THE BODY OF A NEWS-POST AND TO NOT PREPEND IT WITH
@@ -205,6 +238,9 @@ class Body
205
238
  end
206
239
  end until ref == nil
207
240
  debug("all references found:\n" << references.join('\n')) if !references.empty?
241
+ # re-wrap body
242
+ # ATTN! Does not work!
243
+ # body.wrap!
208
244
  else
209
245
  msg = 'The References Delimiter is the same in its reversed form.'
210
246
  msg << "#{$LN}Cannot handle references or footnotes!"
@@ -216,7 +252,10 @@ class Body
216
252
  body << $LN << @@config.REFERENCES_SEPARATOR << $LN
217
253
  references.each_with_index do |r, i|
218
254
  r = r.gsub(ref_delim, '').gsub(ref_delim.reverse,'')
219
- body << (i + 1 ).to_s << ") " << r.strip << $LN
255
+ num = (i + 1).to_s << ") "
256
+ r.strip!
257
+ r.wrap!(WRAP_LENGTH, num.length)
258
+ body << num << r << $LN
220
259
  end
221
260
  else
222
261
  debug('no refences found')
data/lib/configuration.rb CHANGED
@@ -98,8 +98,8 @@ class Configuration
98
98
  File::write(bak_conf, File.read(@config_file))
99
99
  File::write(@config_file, @conf.to_yaml)
100
100
  rescue Exception => ex
101
- msg = ex.message
102
- error "Cannot write altered configuration to " << @config_file << "!"
101
+ msg = "Cannot write altered configuration to " << @config_file << "!\n\t" << ex.message
102
+ STDERR.puts(msg << "\nAborting, bye\n")
103
103
  error msg
104
104
  exit false
105
105
  end
@@ -126,14 +126,15 @@ class Configuration
126
126
  clear_log
127
127
  debug('log target and -level set: ' << @@log_level.to_s << ', ' << target_string)
128
128
  rescue Exception => ex
129
- msg = ex.message
130
- error msg
131
- STDERR.puts("Configuration: cannot use the configuration-file (" << @config_file << ")")
132
- STDERR.puts("Exception: " << msg)
129
+ msg = "Cannot use the configuration-file (" << @config_file << ")"
130
+ msg << "\n\t" << ex.message
131
+ # No log.
132
+ # error msg
133
+ STDERR.puts(msg << "\nAborting, bye\n")
133
134
  exit false
134
135
  end
135
136
  else
136
- STDERR.puts("cannot read the configuration-file (" << @config_file << ")")
137
+ STDERR.puts("Cannot read the configuration-file (" << @config_file << ")")
137
138
  exit false
138
139
  end
139
140
  end
data/lib/version.rb CHANGED
@@ -14,10 +14,9 @@
14
14
  =end
15
15
 
16
16
  PROGNAME = 'flnews_post_proc'
17
- PROGVERSION = "1.57"
17
+ PROGVERSION = "1.60"
18
18
  AUTHORS = "Michael Uplawski"
19
19
  EMAIL = "michael.uplawski@uplawski.eu"
20
20
  YEARS = "2023 - 2024"
21
- SUMMARY = "Better error-handling when interpreting the configuration."
22
- SUMMARY << " README updated"
21
+ SUMMARY = "Word wrapping with indenting for reference-lists"
23
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flnews_post_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.57'
4
+ version: '1.60'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Uplawski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-22 00:00:00.000000000 Z
11
+ date: 2024-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -105,5 +105,5 @@ requirements: []
105
105
  rubygems_version: 3.5.3
106
106
  signing_key:
107
107
  specification_version: 4
108
- summary: Better error-handling when interpreting the configuration. README updated
108
+ summary: Word wrapping with indenting for reference-lists
109
109
  test_files: []