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 +4 -4
- data/bin/flnews_post_proc +12 -2
- data/lib/body.rb +56 -17
- data/lib/configuration.rb +8 -7
- data/lib/version.rb +2 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 501b73b0978b60f22ec85311eb7b9f66df77802e963eec5ed9bf7e86066604fc
|
4
|
+
data.tar.gz: 985d92d55cf867f297f4ec3ceb337091495918d869b48d105b38452412835ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
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
|
-
#
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
130
|
-
|
131
|
-
|
132
|
-
|
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("
|
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.
|
17
|
+
PROGVERSION = "1.60"
|
18
18
|
AUTHORS = "Michael Uplawski"
|
19
19
|
EMAIL = "michael.uplawski@uplawski.eu"
|
20
20
|
YEARS = "2023 - 2024"
|
21
|
-
SUMMARY = "
|
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.
|
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-
|
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:
|
108
|
+
summary: Word wrapping with indenting for reference-lists
|
109
109
|
test_files: []
|