slaw 7.0.0 → 9.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fde17ca3304eb910432a89b75fe777e9ce50cf1abed667d2bb7b2d673bc77aa0
4
- data.tar.gz: 7102e2b19079e12bbf89c783aed99a48b9cd645f9dac396b0b68061279e86174
3
+ metadata.gz: '0654597e1ede427474f5b9b4f703070c4d23fc34fdbf10700ae72485f8372a21'
4
+ data.tar.gz: d19cd4ebfe1e256f5366addde1723817547075e6468ab31b0d65c8d492f5c6d1
5
5
  SHA512:
6
- metadata.gz: c7740c01a12b46d138051b82de734a67806155f5166c2c0c56a9aab1d7d5fc8e79526260bc4236310cd88215dd742ce3beabb298288c086f5a39111375d825ff
7
- data.tar.gz: 219658ca25c23b52ce5f7ae499728a8e183b488db3f03477cb726d5f88f7ec290faf26a02727c8eb705f21ea85866f64d3e437799b0cafdb53fb3a087fd80144
6
+ metadata.gz: a778d4798462049e8fbb123c30d72d2e43c4f7f8344e0bc31590d2c5873daa3675979cafdb3fc14be1327f3ed262c19e6220b2e2ed40e825cc68fe353bb57614
7
+ data.tar.gz: 585ea851576bca2c5059a3693067066f9f06a9b1ef67761534b707ddcd51f447cc8953f7f7b33842486cb77e442b3f7d60dd63e763306d269db14f1c1b17fcaa
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.7.0
3
4
  - 2.6.2
4
5
  - 2.5.4
5
- - 2.4.5
6
6
  before_install:
7
7
  - gem update bundler
data/README.md CHANGED
@@ -79,8 +79,34 @@ You can create your own grammar by creating a gem that provides these files and
79
79
  7. Push to the branch: `git push origin my-new-feature`
80
80
  8. Create a new Pull Request
81
81
 
82
+ ## Releasing
83
+
84
+ 1. Update `lib/slaw/version.rb`
85
+ 2. Run `rake release`
86
+
82
87
  ## Changelog
83
88
 
89
+ ### 9.2.0 (10 June 2020)
90
+
91
+ * Subpart numbers are optional
92
+
93
+ ### 9.1.0 (15 April 2020)
94
+
95
+ * Subsections can have numbers such as 1.1A and 1.1bis
96
+
97
+ ### 9.0.0 (17 Mar 2020)
98
+
99
+ * Support SUBPART
100
+
101
+ ### 8.0.1 (26 Feb 2020)
102
+
103
+ * Fix bug with id prefix on schedules container
104
+
105
+ ### 8.0.0 (19 Feb 2020)
106
+
107
+ * Obey --id-prefix for group nodes
108
+ * Ensure that schedules prefix their children, for those that require it (parts and chapters)
109
+
84
110
  ### 7.0.0 (31 Jan 2020)
85
111
 
86
112
  * Lists ids are now numbered sequentially, rather than by tree position
@@ -1,13 +1,13 @@
1
1
  module Slaw
2
2
  module Grammars
3
3
  class GroupNode < Treetop::Runtime::SyntaxNode
4
- def to_xml(b, *args)
5
- children.elements.each { |e| e.to_xml(b, *args) }
4
+ def to_xml(b, id_prefix='')
5
+ children.elements.each { |e| e.to_xml(b, id_prefix) }
6
6
  end
7
7
  end
8
8
 
9
9
  class Body < Treetop::Runtime::SyntaxNode
10
- def to_xml(b)
10
+ def to_xml(b, id_prefix='')
11
11
  b.body { |b|
12
12
  children.elements.each_with_index { |e, i| e.to_xml(b, '', i) }
13
13
  }
@@ -9,10 +9,10 @@ module Slaw
9
9
  MANIFESTATION_URI = EXPRESSION_URI
10
10
 
11
11
  class ScheduleContainer < Treetop::Runtime::SyntaxNode
12
- def to_xml(b)
12
+ def to_xml(b, idprefix="")
13
13
  b.components { |b|
14
14
  schedules.children.elements.each_with_index { |e, i|
15
- e.to_xml(b, "", i+1)
15
+ e.to_xml(b, idprefix, i+1)
16
16
  }
17
17
  }
18
18
  end
@@ -20,7 +20,11 @@ module Slaw
20
20
  end
21
21
 
22
22
  rule dotted_number_2
23
- number '.' number
23
+ # 9.1
24
+ # 9.1A
25
+ # 9.1A1
26
+ # NOT: 9.A
27
+ number '.' number alphanums?
24
28
  end
25
29
 
26
30
  rule number
@@ -44,37 +44,43 @@ module Slaw
44
44
 
45
45
  rule body
46
46
  ('BODY' space? eol)?
47
- children:(chapter / part / section / subsection / generic_container)* <Body>
47
+ children:(chapter / part / subpart / section / subsection / generic_container)* <Body>
48
48
  end
49
49
 
50
50
  # chapter (parts allowed)
51
51
  rule chapter
52
52
  heading:chapter_heading
53
- children:(part_no_chapter / section / subsection / generic_container)*
53
+ children:(part_no_chapter / subpart / section / subsection / generic_container)*
54
54
  <Chapter>
55
55
  end
56
56
 
57
57
  # part (chapters allowed)
58
58
  rule part
59
59
  heading:part_heading
60
- children:(chapter_no_part / section / subsection / generic_container)*
60
+ children:(chapter_no_part / subpart / section / subsection / generic_container)*
61
61
  <Part>
62
62
  end
63
63
 
64
64
  # part (no chapters)
65
65
  rule part_no_chapter
66
66
  heading:part_heading
67
- children:(section / subsection / generic_container)*
67
+ children:(subpart / section / subsection / generic_container)*
68
68
  <Part>
69
69
  end
70
70
 
71
71
  # chapter (no parts)
72
72
  rule chapter_no_part
73
73
  heading:chapter_heading
74
- children:(section / subsection / generic_container)*
74
+ children:(subpart / section / subsection / generic_container)*
75
75
  <Chapter>
76
76
  end
77
77
 
78
+ rule subpart
79
+ heading:subpart_heading
80
+ children:(section / subsection / generic_container)*
81
+ <Subpart>
82
+ end
83
+
78
84
  rule section
79
85
  section_title
80
86
  children:(subsection / generic_container)* <Section>
@@ -134,6 +140,10 @@ module Slaw
134
140
  children:part_no_chapter+ <GroupNode>
135
141
  end
136
142
 
143
+ rule subparts
144
+ children:subpart+ <GroupNode>
145
+ end
146
+
137
147
  rule sections
138
148
  children:section+ <GroupNode>
139
149
  end
@@ -151,6 +161,11 @@ module Slaw
151
161
  <PartHeading>
152
162
  end
153
163
 
164
+ rule subpart_heading
165
+ space? subpart_heading_prefix heading:(newline? space? inline_items)? eol
166
+ <SubpartHeading>
167
+ end
168
+
154
169
  rule section_title
155
170
  section_title_1 / section_1_title
156
171
  end
@@ -241,6 +256,10 @@ module Slaw
241
256
  'part'i space alphanums [ :-]*
242
257
  end
243
258
 
259
+ rule subpart_heading_prefix
260
+ 'subpart'i num:(space alphanums)? [ :-]*
261
+ end
262
+
244
263
  rule chapter_heading_prefix
245
264
  'chapter'i space alphanums [ :-]*
246
265
  end
@@ -275,12 +294,12 @@ module Slaw
275
294
 
276
295
  rule body_hierarchy_prefix
277
296
  # Text that indicates the start of a hierarchy element, in the body
278
- chapter_heading / part_heading / section_title / schedule_title / subsection_prefix / crossheading
297
+ chapter_heading / part_heading / subpart_heading / section_title / schedule_title / subsection_prefix / crossheading
279
298
  end
280
299
 
281
300
  rule non_body_hierarchy_prefix
282
301
  # Text that indicates the start of a hierarchy element, in the preamble or preface
283
- chapter_heading / part_heading / section_title / schedule_title / crossheading
302
+ chapter_heading / part_heading / subpart_heading / section_title / schedule_title / crossheading
284
303
  end
285
304
 
286
305
  include Slaw::Grammars::Inlines
@@ -137,13 +137,8 @@ module Slaw
137
137
  heading.num
138
138
  end
139
139
 
140
- def to_xml(b, *args)
141
- id = "part-#{num}"
142
-
143
- # include a chapter number in the id if our parent has one
144
- if parent and parent.parent.is_a?(Chapter) and parent.parent.num
145
- id = "chapter-#{parent.parent.num}.#{id}"
146
- end
140
+ def to_xml(b, id_prefix='', *args)
141
+ id = id_prefix + "part-#{num}"
147
142
 
148
143
  b.part(id: id) { |b|
149
144
  heading.to_xml(b)
@@ -167,18 +162,48 @@ module Slaw
167
162
  end
168
163
  end
169
164
 
170
- class Chapter < Treetop::Runtime::SyntaxNode
165
+ class Subpart < Treetop::Runtime::SyntaxNode
171
166
  def num
172
167
  heading.num
173
168
  end
174
169
 
175
- def to_xml(b, *args)
176
- id = "chapter-#{num}"
170
+ def to_xml(b, id_prefix='', *args)
171
+ num = self.num
172
+ if num.empty?
173
+ num = Slaw::Grammars::Counters.counters[id_prefix]['subpart'] += 1
174
+ end
177
175
 
178
- # include a part number in the id if our parent has one
179
- if parent and parent.parent.is_a?(Part) and parent.parent.num
180
- id = "part-#{parent.parent.num}.#{id}"
176
+ id = id_prefix + "subpart-#{num}"
177
+
178
+ b.subpart(id: id) { |b|
179
+ heading.to_xml(b)
180
+ children.elements.each_with_index { |e, i| e.to_xml(b, id + '.', i) }
181
+ }
182
+ end
183
+ end
184
+
185
+ class SubpartHeading < Treetop::Runtime::SyntaxNode
186
+ def num
187
+ subpart_heading_prefix.num.text_value.strip()
188
+ end
189
+
190
+ def to_xml(b)
191
+ b.num(num) unless self.num.empty?
192
+ if heading.respond_to? :inline_items
193
+ b.heading { |b|
194
+ heading.inline_items.to_xml(b)
195
+ }
181
196
  end
197
+ end
198
+ end
199
+
200
+ class Chapter < Treetop::Runtime::SyntaxNode
201
+ def num
202
+ heading.num
203
+ end
204
+
205
+ def to_xml(b, id_prefix='', *args)
206
+ id = id_prefix + "chapter-#{num}"
182
207
 
183
208
  b.chapter(id: id) { |b|
184
209
  heading.to_xml(b)
@@ -23,6 +23,7 @@
23
23
  $prefix = 'PREFACE' or
24
24
  starts-with($prefix, 'CHAPTER ') or
25
25
  starts-with($prefix, 'PART ') or
26
+ starts-with($prefix, 'SUBPART ') or
26
27
  starts-with($prefix, 'SCHEDULE ') or
27
28
  starts-with($prefix, 'HEADING ') or
28
29
  starts-with($prefix, 'SUBHEADING ') or
@@ -74,6 +75,16 @@
74
75
  <xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
75
76
  </xsl:template>
76
77
 
78
+ <xsl:template match="a:subpart">
79
+ <xsl:text>Subpart </xsl:text>
80
+ <xsl:value-of select="a:num" />
81
+ <xsl:text> - </xsl:text>
82
+ <xsl:apply-templates select="a:heading" />
83
+ <xsl:text>&#10;&#10;</xsl:text>
84
+
85
+ <xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
86
+ </xsl:template>
87
+
77
88
  <xsl:template match="a:chapter">
78
89
  <xsl:text>Chapter </xsl:text>
79
90
  <xsl:value-of select="a:num" />
@@ -148,14 +148,7 @@ module Slaw
148
148
  builder.akomaNtoso("xmlns:xsi"=> "http://www.w3.org/2001/XMLSchema-instance",
149
149
  "xsi:schemaLocation" => "http://www.akomantoso.org/2.0 akomantoso20.xsd",
150
150
  "xmlns" => NS) do |b|
151
- args = [b]
152
-
153
- # should we provide an id prefix?
154
- arity = tree.method('to_xml').arity
155
- arity = arity.abs-1 if arity < 0
156
- args << (fragment_id_prefix || "") if arity > 1
157
-
158
- tree.to_xml(*args)
151
+ tree.to_xml(b, fragment_id_prefix || '')
159
152
  end
160
153
 
161
154
  builder.to_xml(encoding: 'UTF-8')
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "7.0.0"
2
+ VERSION = "9.2.0"
3
3
  end
@@ -755,6 +755,102 @@ EOS
755
755
  end
756
756
  end
757
757
 
758
+ #-------------------------------------------------------------------------------
759
+ # Subparts
760
+
761
+ describe 'subparts' do
762
+ it 'should handle subparts' do
763
+ node = parse :subpart, <<EOS
764
+ SUBPART 2 - Heading
765
+
766
+ 1. Section
767
+ Hello there
768
+ EOS
769
+ to_xml(node).should == '<subpart id="subpart-2">
770
+ <num>2</num>
771
+ <heading>Heading</heading>
772
+ <section id="section-1">
773
+ <num>1.</num>
774
+ <heading>Section</heading>
775
+ <paragraph id="section-1.paragraph0">
776
+ <content>
777
+ <p>Hello there</p>
778
+ </content>
779
+ </paragraph>
780
+ </section>
781
+ </subpart>'
782
+ end
783
+
784
+ it 'should handle subparts in parts' do
785
+ node = parse :part, <<EOS
786
+ PART A - The Part
787
+
788
+ SUBPART 1 - The Subpart 1
789
+
790
+ 1. Section
791
+
792
+ Hello
793
+
794
+ SUBPART 2 - The Subpart 2
795
+
796
+ 2. Section
797
+
798
+ Bye
799
+ EOS
800
+ to_xml(node).should == '<part id="part-A">
801
+ <num>A</num>
802
+ <heading>The Part</heading>
803
+ <subpart id="part-A.subpart-1">
804
+ <num>1</num>
805
+ <heading>The Subpart 1</heading>
806
+ <section id="section-1">
807
+ <num>1.</num>
808
+ <heading>Section</heading>
809
+ <paragraph id="section-1.paragraph0">
810
+ <content>
811
+ <p>Hello</p>
812
+ </content>
813
+ </paragraph>
814
+ </section>
815
+ </subpart>
816
+ <subpart id="part-A.subpart-2">
817
+ <num>2</num>
818
+ <heading>The Subpart 2</heading>
819
+ <section id="section-2">
820
+ <num>2.</num>
821
+ <heading>Section</heading>
822
+ <paragraph id="section-2.paragraph0">
823
+ <content>
824
+ <p>Bye</p>
825
+ </content>
826
+ </paragraph>
827
+ </section>
828
+ </subpart>
829
+ </part>'
830
+ end
831
+
832
+ it 'should allow optional numbers' do
833
+ node = parse :subpart, <<EOS
834
+ SUBPART - Heading - with a dash
835
+
836
+ 1. Section
837
+ Hello there
838
+ EOS
839
+ to_xml(node).should == '<subpart id="subpart-0">
840
+ <heading>Heading - with a dash</heading>
841
+ <section id="section-1">
842
+ <num>1.</num>
843
+ <heading>Section</heading>
844
+ <paragraph id="section-1.paragraph0">
845
+ <content>
846
+ <p>Hello there</p>
847
+ </content>
848
+ </paragraph>
849
+ </section>
850
+ </subpart>'
851
+ end
852
+ end
853
+
758
854
  #-------------------------------------------------------------------------------
759
855
  # Subsections
760
856
 
@@ -963,6 +1059,28 @@ EOS
963
1059
  9.9. foo
964
1060
  EOS
965
1061
  node.num.should == "9.9"
1062
+
1063
+ node = parse :subsection, <<EOS
1064
+ 9.9 foo
1065
+ EOS
1066
+ node.num.should == "9.9"
1067
+ end
1068
+
1069
+ it 'should handle dotted number and letter subsection numbers' do
1070
+ node = parse :subsection, <<EOS
1071
+ 9.9A. foo
1072
+ EOS
1073
+ node.num.should == "9.9A"
1074
+
1075
+ node = parse :subsection, <<EOS
1076
+ 9.9bis foo
1077
+ EOS
1078
+ node.num.should == "9.9bis"
1079
+
1080
+ node = parse :subsection, <<EOS
1081
+ 9.9A foo
1082
+ EOS
1083
+ node.num.should == "9.9A"
966
1084
  end
967
1085
 
968
1086
  it 'should handle dotted number sublists' do
@@ -383,19 +383,19 @@ EOS
383
383
  <hcontainer id="schedule1" name="schedule">
384
384
  <heading>Schedule 1</heading>
385
385
  <subheading>Forms</subheading>
386
- <part id="part-I">
386
+ <part id="schedule1.part-I">
387
387
  <num>I</num>
388
388
  <heading>Form of authentication statement</heading>
389
- <paragraph id="part-I.paragraph0">
389
+ <paragraph id="schedule1.part-I.paragraph0">
390
390
  <content>
391
391
  <p>This printed impression has been carefully compared by me with the bill which was passed by Parliament and found by me to be a true copy of the bill.</p>
392
392
  </content>
393
393
  </paragraph>
394
394
  </part>
395
- <part id="part-II">
395
+ <part id="schedule1.part-II">
396
396
  <num>II</num>
397
397
  <heading>Form of statement of the President’s assent.</heading>
398
- <paragraph id="part-II.paragraph0">
398
+ <paragraph id="schedule1.part-II.paragraph0">
399
399
  <content>
400
400
  <p>I signify my assent to the bill and a whole bunch of other stuff.</p>
401
401
  </content>
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: 7.0.0
4
+ version: 9.2.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-31 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake