slaw 6.2.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/slaw/grammars/counters.rb +27 -0
- data/lib/slaw/grammars/za/act_nodes.rb +7 -19
- data/lib/slaw/version.rb +1 -1
- data/spec/za/act_block_spec.rb +38 -39
- data/spec/za/act_inline_spec.rb +3 -4
- data/spec/za/act_schedules_spec.rb +1 -2
- data/spec/za/act_table_spec.rb +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde17ca3304eb910432a89b75fe777e9ce50cf1abed667d2bb7b2d673bc77aa0
|
4
|
+
data.tar.gz: 7102e2b19079e12bbf89c783aed99a48b9cd645f9dac396b0b68061279e86174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7740c01a12b46d138051b82de734a67806155f5166c2c0c56a9aab1d7d5fc8e79526260bc4236310cd88215dd742ce3beabb298288c086f5a39111375d825ff
|
7
|
+
data.tar.gz: 219658ca25c23b52ce5f7ae499728a8e183b488db3f03477cb726d5f88f7ec290faf26a02727c8eb705f21ea85866f64d3e437799b0cafdb53fb3a087fd80144
|
data/README.md
CHANGED
@@ -81,6 +81,11 @@ You can create your own grammar by creating a gem that provides these files and
|
|
81
81
|
|
82
82
|
## Changelog
|
83
83
|
|
84
|
+
### 7.0.0 (31 Jan 2020)
|
85
|
+
|
86
|
+
* Lists ids are now numbered sequentially, rather than by tree position
|
87
|
+
* New Slaw::Grammars::Counters helper module
|
88
|
+
|
84
89
|
### 6.2.0 (15 Jan 2020)
|
85
90
|
|
86
91
|
* Better support for ol, ul and li when importing from HTML
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Slaw
|
2
|
+
module Grammars
|
3
|
+
class Counters
|
4
|
+
# Counters for generating element IDs. This is a hash from the element ID
|
5
|
+
# prefix, to another hash that maps the element type name to a count.
|
6
|
+
#
|
7
|
+
# For backwards compatibility, counters always start at -1, and must be
|
8
|
+
# incremented before being used. This ensures that element ids start at 0.
|
9
|
+
# This is NOT compatible with AKN 3.0 which requires that element numbers
|
10
|
+
# start at 1.
|
11
|
+
#
|
12
|
+
# eg.
|
13
|
+
#
|
14
|
+
# section-1 => paragraph => 2
|
15
|
+
#
|
16
|
+
@@counters = Hash.new{ |h, k| h[k] = Hash.new(-1) }
|
17
|
+
|
18
|
+
def self.counters
|
19
|
+
@@counters
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.reset!
|
23
|
+
@@counters.clear
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'slaw/grammars/core_nodes'
|
2
|
+
require 'slaw/grammars/counters'
|
2
3
|
|
3
4
|
module Slaw
|
4
5
|
module Grammars
|
@@ -281,16 +282,9 @@ module Slaw
|
|
281
282
|
end
|
282
283
|
|
283
284
|
class BlockElements < Treetop::Runtime::SyntaxNode
|
284
|
-
@@counters = {}
|
285
|
-
|
286
|
-
def self.counters
|
287
|
-
@@counters
|
288
|
-
end
|
289
|
-
|
290
285
|
def to_xml(b, idprefix='', i=0)
|
291
|
-
|
292
|
-
|
293
|
-
id = "#{idprefix}paragraph#{@@counters[idprefix]}"
|
286
|
+
cnt = Slaw::Grammars::Counters.counters[idprefix]['paragraph'] += 1
|
287
|
+
id = "#{idprefix}paragraph#{cnt}"
|
294
288
|
idprefix = "#{id}."
|
295
289
|
|
296
290
|
b.paragraph(id: id) { |b|
|
@@ -321,7 +315,8 @@ module Slaw
|
|
321
315
|
# Render a block list to xml. If a block is given,
|
322
316
|
# yield to it a builder to insert a listIntroduction node
|
323
317
|
def to_xml(b, idprefix, i=0, &block)
|
324
|
-
|
318
|
+
cnt = Slaw::Grammars::Counters.counters[idprefix]['list'] += 1
|
319
|
+
id = idprefix + "list#{cnt}"
|
325
320
|
idprefix = id + '.'
|
326
321
|
|
327
322
|
b.blockList(id: id, renest: true) { |b|
|
@@ -348,16 +343,9 @@ module Slaw
|
|
348
343
|
end
|
349
344
|
|
350
345
|
class Crossheading < Treetop::Runtime::SyntaxNode
|
351
|
-
@@counters = {}
|
352
|
-
|
353
|
-
def self.counters
|
354
|
-
@@counters
|
355
|
-
end
|
356
|
-
|
357
346
|
def to_xml(b, idprefix, i=0)
|
358
|
-
|
359
|
-
|
360
|
-
id = "#{idprefix}crossheading-#{@@counters[idprefix]}"
|
347
|
+
cnt = Slaw::Grammars::Counters.counters[idprefix]['crossheading'] += 1
|
348
|
+
id = "#{idprefix}crossheading-#{cnt}"
|
361
349
|
|
362
350
|
b.hcontainer(id: id, name: 'crossheading') { |b|
|
363
351
|
b.heading { |b|
|
data/lib/slaw/version.rb
CHANGED
data/spec/za/act_block_spec.rb
CHANGED
@@ -29,8 +29,7 @@ describe Slaw::ActGenerator do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
before(:each) do
|
32
|
-
Slaw::Grammars::
|
33
|
-
Slaw::Grammars::ZA::Act::BlockElements.counters.clear
|
32
|
+
Slaw::Grammars::Counters.reset!
|
34
33
|
end
|
35
34
|
|
36
35
|
#-------------------------------------------------------------------------------
|
@@ -85,12 +84,12 @@ EOS
|
|
85
84
|
<paragraph id="paragraph0">
|
86
85
|
<content>
|
87
86
|
<p>Some content before the section</p>
|
88
|
-
<blockList id="paragraph0.
|
89
|
-
<item id="paragraph0.
|
87
|
+
<blockList id="paragraph0.list0" renest="true">
|
88
|
+
<item id="paragraph0.list0.a">
|
90
89
|
<num>(a)</num>
|
91
90
|
<p>foo</p>
|
92
91
|
</item>
|
93
|
-
<item id="paragraph0.
|
92
|
+
<item id="paragraph0.list0.b">
|
94
93
|
<num>(b)</num>
|
95
94
|
<p>bar</p>
|
96
95
|
</item>
|
@@ -778,20 +777,20 @@ EOS
|
|
778
777
|
<num>(2)</num>
|
779
778
|
<content>
|
780
779
|
<p>title</p>
|
781
|
-
<blockList id="2.
|
782
|
-
<item id="2.
|
780
|
+
<blockList id="2.list0" renest="true">
|
781
|
+
<item id="2.list0.a">
|
783
782
|
<num>(a)</num>
|
784
783
|
<p>one</p>
|
785
784
|
</item>
|
786
|
-
<item id="2.
|
785
|
+
<item id="2.list0.b">
|
787
786
|
<num>(b)</num>
|
788
787
|
<p>two</p>
|
789
788
|
</item>
|
790
|
-
<item id="2.
|
789
|
+
<item id="2.list0.c">
|
791
790
|
<num>(c)</num>
|
792
791
|
<p>three</p>
|
793
792
|
</item>
|
794
|
-
<item id="2.
|
793
|
+
<item id="2.list0.i">
|
795
794
|
<num>(i)</num>
|
796
795
|
<p>four</p>
|
797
796
|
</item>
|
@@ -902,20 +901,20 @@ EOS
|
|
902
901
|
<num>(1)</num>
|
903
902
|
<content>
|
904
903
|
<p>here\'s my really cool list,</p>
|
905
|
-
<blockList id="1.
|
906
|
-
<item id="1.
|
904
|
+
<blockList id="1.list0" renest="true">
|
905
|
+
<item id="1.list0.a">
|
907
906
|
<num>(a)</num>
|
908
907
|
<p>one</p>
|
909
908
|
</item>
|
910
|
-
<item id="1.
|
909
|
+
<item id="1.list0.b">
|
911
910
|
<num>(b)</num>
|
912
911
|
<p/>
|
913
912
|
</item>
|
914
|
-
<item id="1.
|
913
|
+
<item id="1.list0.i">
|
915
914
|
<num>(i)</num>
|
916
915
|
<p>single</p>
|
917
916
|
</item>
|
918
|
-
<item id="1.
|
917
|
+
<item id="1.list0.ii">
|
919
918
|
<num>(ii)</num>
|
920
919
|
<p>double</p>
|
921
920
|
</item>
|
@@ -936,20 +935,20 @@ EOS
|
|
936
935
|
<num>(1)</num>
|
937
936
|
<content>
|
938
937
|
<p>here\'s my really cool list,</p>
|
939
|
-
<blockList id="1.
|
940
|
-
<item id="1.
|
938
|
+
<blockList id="1.list0" renest="true">
|
939
|
+
<item id="1.list0.a">
|
941
940
|
<num>(a)</num>
|
942
941
|
<p/>
|
943
942
|
</item>
|
944
|
-
<item id="1.
|
943
|
+
<item id="1.list0.b">
|
945
944
|
<num>(b)</num>
|
946
945
|
<p/>
|
947
946
|
</item>
|
948
|
-
<item id="1.
|
947
|
+
<item id="1.list0.i">
|
949
948
|
<num>(i)</num>
|
950
949
|
<p>single</p>
|
951
950
|
</item>
|
952
|
-
<item id="1.
|
951
|
+
<item id="1.list0.ii">
|
953
952
|
<num>(ii)</num>
|
954
953
|
<p>double</p>
|
955
954
|
</item>
|
@@ -978,16 +977,16 @@ EOS
|
|
978
977
|
<num>9.9</num>
|
979
978
|
<content>
|
980
979
|
<p>foo</p>
|
981
|
-
<blockList id="9.9.
|
982
|
-
<item id="9.9.
|
980
|
+
<blockList id="9.9.list0" renest="true">
|
981
|
+
<item id="9.9.list0.9.9.1">
|
983
982
|
<num>9.9.1</num>
|
984
983
|
<p>item1</p>
|
985
984
|
</item>
|
986
|
-
<item id="9.9.
|
985
|
+
<item id="9.9.list0.9.9.2">
|
987
986
|
<num>9.9.2</num>
|
988
987
|
<p>item2</p>
|
989
988
|
</item>
|
990
|
-
<item id="9.9.
|
989
|
+
<item id="9.9.list0.9.9.2.1">
|
991
990
|
<num>9.9.2.1</num>
|
992
991
|
<p>item3</p>
|
993
992
|
</item>
|
@@ -1012,23 +1011,23 @@ EOS
|
|
1012
1011
|
<num>(1)</num>
|
1013
1012
|
<content>
|
1014
1013
|
<p>a list</p>
|
1015
|
-
<blockList id="1.
|
1016
|
-
<item id="1.
|
1014
|
+
<blockList id="1.list0" renest="true">
|
1015
|
+
<item id="1.list0.a">
|
1017
1016
|
<num>(a)</num>
|
1018
1017
|
<p>item 1</p>
|
1019
1018
|
</item>
|
1020
|
-
<item id="1.
|
1019
|
+
<item id="1.list0.b">
|
1021
1020
|
<num>(b)</num>
|
1022
1021
|
<p>item 2</p>
|
1023
1022
|
</item>
|
1024
1023
|
</blockList>
|
1025
1024
|
<p>some text</p>
|
1026
|
-
<blockList id="1.
|
1027
|
-
<item id="1.
|
1025
|
+
<blockList id="1.list1" renest="true">
|
1026
|
+
<item id="1.list1.c">
|
1028
1027
|
<num>(c)</num>
|
1029
1028
|
<p>item 3</p>
|
1030
1029
|
</item>
|
1031
|
-
<item id="1.
|
1030
|
+
<item id="1.list1.d">
|
1032
1031
|
<num>(d)</num>
|
1033
1032
|
<p>item 4</p>
|
1034
1033
|
</item>
|
@@ -1615,12 +1614,12 @@ EOS
|
|
1615
1614
|
<paragraph id="section-1.paragraph0">
|
1616
1615
|
<content>
|
1617
1616
|
<p>naked statement (c) blah</p>
|
1618
|
-
<blockList id="section-1.paragraph0.
|
1619
|
-
<item id="section-1.paragraph0.
|
1617
|
+
<blockList id="section-1.paragraph0.list0" renest="true">
|
1618
|
+
<item id="section-1.paragraph0.list0.a">
|
1620
1619
|
<num>(a)</num>
|
1621
1620
|
<p>foo</p>
|
1622
1621
|
</item>
|
1623
|
-
<item id="section-1.paragraph0.
|
1622
|
+
<item id="section-1.paragraph0.list0.b">
|
1624
1623
|
<num>(b)</num>
|
1625
1624
|
<p>bar</p>
|
1626
1625
|
</item>
|
@@ -1657,12 +1656,12 @@ EOS
|
|
1657
1656
|
<num>(2)</num>
|
1658
1657
|
<content>
|
1659
1658
|
<p>Schedule 1</p>
|
1660
|
-
<blockList id="section-1.2.
|
1661
|
-
<item id="section-1.2.
|
1659
|
+
<blockList id="section-1.2.list0" renest="true">
|
1660
|
+
<item id="section-1.2.list0.a">
|
1662
1661
|
<num>(a)</num>
|
1663
1662
|
<p>Part 1</p>
|
1664
1663
|
</item>
|
1665
|
-
<item id="section-1.2.
|
1664
|
+
<item id="section-1.2.list0.b">
|
1666
1665
|
<num>(b)</num>
|
1667
1666
|
<p>thing</p>
|
1668
1667
|
</item>
|
@@ -1729,12 +1728,12 @@ EOS
|
|
1729
1728
|
<num>3.1</num>
|
1730
1729
|
<content>
|
1731
1730
|
<p>Informal trading may include, amongst others:-</p>
|
1732
|
-
<blockList id="section-3.3.1.
|
1733
|
-
<item id="section-3.3.1.
|
1731
|
+
<blockList id="section-3.3.1.list0" renest="true">
|
1732
|
+
<item id="section-3.3.1.list0.3.1.1">
|
1734
1733
|
<num>3.1.1</num>
|
1735
1734
|
<p>street trading;</p>
|
1736
1735
|
</item>
|
1737
|
-
<item id="section-3.3.1.
|
1736
|
+
<item id="section-3.3.1.list0.3.1.2">
|
1738
1737
|
<num>3.1.2</num>
|
1739
1738
|
<p>trading in pedestrian malls;</p>
|
1740
1739
|
</item>
|
data/spec/za/act_inline_spec.rb
CHANGED
@@ -29,8 +29,7 @@ describe Slaw::ActGenerator do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
before(:each) do
|
32
|
-
Slaw::Grammars::
|
33
|
-
Slaw::Grammars::ZA::Act::BlockElements.counters.clear
|
32
|
+
Slaw::Grammars::Counters.reset!
|
34
33
|
end
|
35
34
|
|
36
35
|
#-------------------------------------------------------------------------------
|
@@ -146,8 +145,8 @@ EOS
|
|
146
145
|
<num>(1)</num>
|
147
146
|
<content>
|
148
147
|
<p>something</p>
|
149
|
-
<blockList id="section-1.1.
|
150
|
-
<item id="section-1.1.
|
148
|
+
<blockList id="section-1.1.list0" renest="true">
|
149
|
+
<item id="section-1.1.list0.a">
|
151
150
|
<num>(a)</num>
|
152
151
|
<p>with a remark <remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark></p>
|
153
152
|
</item>
|
@@ -29,8 +29,7 @@ describe Slaw::ActGenerator do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
before(:each) do
|
32
|
-
Slaw::Grammars::
|
33
|
-
Slaw::Grammars::ZA::Act::BlockElements.counters.clear
|
32
|
+
Slaw::Grammars::Counters.reset!
|
34
33
|
end
|
35
34
|
|
36
35
|
#-------------------------------------------------------------------------------
|
data/spec/za/act_table_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slaw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Kempe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/slaw/extract/html_to_akn_text.xsl
|
131
131
|
- lib/slaw/generator.rb
|
132
132
|
- lib/slaw/grammars/core_nodes.rb
|
133
|
+
- lib/slaw/grammars/counters.rb
|
133
134
|
- lib/slaw/grammars/inlines.treetop
|
134
135
|
- lib/slaw/grammars/inlines_nodes.rb
|
135
136
|
- lib/slaw/grammars/schedules.treetop
|