polyrex-headings 0.1.8 → 0.3.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/polyrex-headings.rb +74 -22
- data.tar.gz.sig +4 -1
- metadata +34 -31
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b19b6d302db47697429ca0cce0d833607cda023c91d905c2f36944af7c1a70c8
|
4
|
+
data.tar.gz: 38fafec9887fea9379231e6a239f0136bf30b3607d317d28d7c08ff4bcc01dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88848e4885eb86a400514d608737af46954b4d0cd5ae99f8e7d2d8db2f266887d7063d74b26d7d2f62e0152706ae868986a1c8bd8eaced17d48df3855a6f10f0
|
7
|
+
data.tar.gz: 129558f0ccdade801991f35b1ac2e9664a59435bfa0e42abd1eaddce08faaadf01021a0e470cbe62d326fff6a05a02f9d72781f3f34e345a87d882fb46ceff65
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/polyrex-headings.rb
CHANGED
@@ -3,27 +3,39 @@
|
|
3
3
|
# file: polyrex-headings.rb
|
4
4
|
|
5
5
|
require 'polyrex'
|
6
|
+
require 'rxfreader'
|
7
|
+
|
8
|
+
|
9
|
+
class PolyrexHeadingsException < Exception
|
10
|
+
end
|
6
11
|
|
7
12
|
class PolyrexHeadings
|
8
13
|
|
9
|
-
attr_reader :to_polyrex, :to_s
|
14
|
+
attr_reader :to_polyrex, :to_px, :to_s
|
10
15
|
|
11
|
-
def initialize(raw_s)
|
16
|
+
def initialize(raw_s, debug: false)
|
12
17
|
|
13
|
-
|
18
|
+
@debug = debug
|
19
|
+
buffer, type = RXFReader.read(raw_s)
|
20
|
+
|
21
|
+
if type == :unknown and buffer.lines.length <= 1 then
|
22
|
+
raise PolyrexHeadingsException, 'File not found'
|
23
|
+
end
|
24
|
+
|
25
|
+
# add an empty space to the blank line where there is no
|
14
26
|
# raw record between headings
|
15
|
-
|
16
|
-
|
17
|
-
summary, *s =
|
27
|
+
|
28
|
+
buffer.gsub!(/(#+[^\n]+\n+)(?=\n#)/m,'\1 ')
|
29
|
+
summary, *s = buffer.split(/(?=(?:^#|[\n]+\n-+))/,2)
|
18
30
|
type = nil
|
19
31
|
|
20
|
-
a = if raw_s =~ /----/ then
|
21
|
-
|
22
|
-
# this was the original code which used dashes to make an underline
|
32
|
+
a = if raw_s =~ /----/ then
|
33
|
+
|
34
|
+
# this was the original code which used dashes to make an underline
|
23
35
|
# of a heading. Typically the heading is now prefixed with a hash (#)
|
24
36
|
# which means this block is unlikely to be executed.
|
25
37
|
|
26
|
-
s.join.lines.chunk{|x| x != "\n" }.map do |record, x|
|
38
|
+
s.join.lines.chunk{|x| x != "\n" }.map do |record, x|
|
27
39
|
|
28
40
|
if record then
|
29
41
|
|
@@ -34,25 +46,25 @@ class PolyrexHeadings
|
|
34
46
|
end
|
35
47
|
|
36
48
|
else
|
37
|
-
|
49
|
+
|
38
50
|
a2 = summary.gsub(/\n{2,}/,"\n").lines
|
39
51
|
|
40
52
|
if a2.last =~ /^--+/ then
|
41
53
|
a2.pop
|
42
54
|
summary = a2.join
|
43
|
-
type = :rowx
|
55
|
+
type = :rowx
|
44
56
|
end
|
45
|
-
|
46
|
-
s.join.split(/^\n*#/)[1..-1].map do |x|
|
47
|
-
|
57
|
+
|
58
|
+
s.join.split(/^\n*#/)[1..-1].map do |x|
|
59
|
+
|
48
60
|
lines = x.lines
|
49
|
-
raw_heading = lines.shift.rstrip
|
50
|
-
|
61
|
+
raw_heading = lines.shift.rstrip
|
62
|
+
|
51
63
|
body = lines.join.strip
|
52
64
|
|
53
65
|
if type == :rowx and body.length > 0
|
54
66
|
|
55
|
-
lines2 = ["\n"] +
|
67
|
+
lines2 = ["\n"] +
|
56
68
|
RowX.new(body, level: 0).to_lines(delimiter: ' # ') << "\n"
|
57
69
|
else
|
58
70
|
|
@@ -62,22 +74,62 @@ class PolyrexHeadings
|
|
62
74
|
raw_indent = raw_heading.slice!(/#*/)
|
63
75
|
n, heading = raw_indent.length, raw_heading.lstrip
|
64
76
|
|
65
|
-
([indent(n) + heading] + lines2.map{|x| indent(n+1) + x}).join
|
77
|
+
([indent(n) + heading] + lines2.map{|x| indent(n+1) + x}).join
|
66
78
|
end
|
67
79
|
|
68
80
|
end
|
81
|
+
|
69
82
|
summary.sub!(/^(<\?)(ph|polyrex-headings)/,'\1polyrex')
|
70
83
|
@to_s = string = summary + a.join
|
71
|
-
|
84
|
+
|
72
85
|
px = Polyrex.new
|
86
|
+
|
73
87
|
px.parse(string, delimiter: ' # ')
|
74
|
-
|
75
|
-
@to_polyrex = px
|
76
88
|
|
89
|
+
@to_polyrex = @to_px = @px = px
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_h(symbolise: true)
|
94
|
+
build(@px.records, symbolise)
|
77
95
|
end
|
78
96
|
|
79
97
|
private
|
80
98
|
|
99
|
+
def build(records, symbolise)
|
100
|
+
|
101
|
+
a = records.map do |record|
|
102
|
+
|
103
|
+
if @debug then
|
104
|
+
puts 'record.records: ' + record.records.inspect
|
105
|
+
puts 'record.x: ' + record.x.inspect
|
106
|
+
end
|
107
|
+
|
108
|
+
if record.records.any? then
|
109
|
+
|
110
|
+
key = symbolise ? record.x.downcase.to_sym : record.x
|
111
|
+
{key => build(record.records, symbolise)}
|
112
|
+
|
113
|
+
elsif record.x =~ /^[^:]+:\s/ then
|
114
|
+
raw_key, value = record.x.split(/:\s+/,2)
|
115
|
+
key = symbolise ? raw_key.downcase.to_sym : raw_key
|
116
|
+
{key => value}
|
117
|
+
|
118
|
+
else
|
119
|
+
|
120
|
+
record.x
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
puts 'a.first: ' + a.first.inspect if @debug
|
127
|
+
return a.inject({}) {|r,x| r.merge!(x)} if a.first.is_a? Hash
|
128
|
+
|
129
|
+
a
|
130
|
+
|
131
|
+
end
|
132
|
+
|
81
133
|
def indent(n)
|
82
134
|
' ' * (n)
|
83
135
|
end
|
data.tar.gz.sig
CHANGED
@@ -1 +1,4 @@
|
|
1
|
-
|
1
|
+
0�<�v�s�c��������`A�^�����^�(#�@wA��b
|
2
|
+
�%t���D��>�X:�2�{w��yf��lg^��Z2<�P�2�ޣ(����yq
|
3
|
+
�SKG�d���Kg���gW�$��9��X��0����^�<��0r2�i$"����@`
|
4
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyrex-headings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjIzMTUxNjQwWhcN
|
15
|
+
MjMwMjIzMTUxNjQwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQ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IYR5veqZP1FV5YI3o+QGtUVBYpjVWMCXI3PVlncilHhropytJsgTmK+
|
32
|
+
m7GRkTcw9bDzTOKLy+9DB5hIfDuy2/p4ghZea5tUsKV47kc6001UsRW/iwV2qwRk
|
33
|
+
3QlMWrvZDcIasPm1AuQygEBiY7UvJK40iH6VU2BkY6k4FWoHnGriWFQJajp1Lrg9
|
34
|
+
r4ZBHWMeKglKwXs7dQqJNhc040MV8LIsMNyQmVoovjT0G6BhUgLPI5rPXz1brNim
|
35
|
+
EbJCIfBUoHq2SbAPW+rN8OQU0GFKS5VwWo2ksouLe/cwhhYR9h/wfkNMkm464sGh
|
36
|
+
E7KxhwTztsgd8aBc/itJzLOs
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
41
|
name: polyrex
|
@@ -39,22 +43,22 @@ dependencies:
|
|
39
43
|
requirements:
|
40
44
|
- - "~>"
|
41
45
|
- !ruby/object:Gem::Version
|
42
|
-
version: '1.
|
46
|
+
version: '1.4'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0
|
49
|
+
version: 1.4.0
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
54
|
- - "~>"
|
51
55
|
- !ruby/object:Gem::Version
|
52
|
-
version: '1.
|
56
|
+
version: '1.4'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.0
|
59
|
+
version: 1.4.0
|
56
60
|
description:
|
57
|
-
email:
|
61
|
+
email: digital.robertson@gmail.com
|
58
62
|
executables: []
|
59
63
|
extensions: []
|
60
64
|
extra_rdoc_files: []
|
@@ -72,16 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
76
|
requirements:
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.
|
79
|
+
version: 2.3.0
|
76
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
81
|
requirements:
|
78
82
|
- - ">="
|
79
83
|
- !ruby/object:Gem::Version
|
80
84
|
version: '0'
|
81
85
|
requirements: []
|
82
|
-
|
83
|
-
rubygems_version: 2.6.8
|
86
|
+
rubygems_version: 3.2.22
|
84
87
|
signing_key:
|
85
88
|
specification_version: 4
|
86
|
-
summary:
|
89
|
+
summary: Parses a raw Polyrex document containing Markdown style headings
|
87
90
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|