slaw 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "2.2.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -226,6 +226,28 @@ three
226
226
  |-
227
227
  |}
228
228
 
229
+ '
230
+ end
231
+
232
+ it 'should unparse schedules correctly' do
233
+ doc = subject.generate_from_text(<<EOS
234
+ 1. Something
235
+
236
+ Schedule - First Schedule [[remark]]
237
+ Subheading [[another]]
238
+
239
+ Subject to approval in terms of this By-Law.
240
+ EOS
241
+ )
242
+ s = subject.text_from_act(doc)
243
+ s.should == '1. Something
244
+
245
+ SCHEDULE - First Schedule [[remark]]
246
+ Subheading [[another]]
247
+
248
+
249
+ Subject to approval in terms of this By-Law.
250
+
229
251
  '
230
252
  end
231
253
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'slaw'
4
+ require 'slaw/grammars/za/act_nodes'
4
5
 
5
6
  describe Slaw::ActGenerator do
6
7
  subject { Slaw::ActGenerator.new('za') }
@@ -27,6 +28,11 @@ describe Slaw::ActGenerator do
27
28
  b.doc.root.to_xml(encoding: 'UTF-8')
28
29
  end
29
30
 
31
+ before(:each) do
32
+ Slaw::Grammars::ZA::Act::Crossheading.counters.clear
33
+ Slaw::Grammars::ZA::Act::BlockElements.counters.clear
34
+ end
35
+
30
36
  #-------------------------------------------------------------------------------
31
37
  # General body
32
38
 
@@ -37,9 +43,11 @@ Some content before the section
37
43
 
38
44
  1. Section
39
45
  Hello there
46
+
47
+ CROSSHEADING crossheading
40
48
  EOS
41
49
  to_xml(node).should == '<body>
42
- <paragraph id="paragraph-0">
50
+ <paragraph id="paragraph0">
43
51
  <content>
44
52
  <p>Some content before the section</p>
45
53
  </content>
@@ -47,11 +55,14 @@ EOS
47
55
  <section id="section-1">
48
56
  <num>1.</num>
49
57
  <heading>Section</heading>
50
- <paragraph id="section-1.paragraph-0">
58
+ <paragraph id="section-1.paragraph0">
51
59
  <content>
52
60
  <p>Hello there</p>
53
61
  </content>
54
62
  </paragraph>
63
+ <hcontainer id="section-1.crossheading-0" name="crossheading">
64
+ <heading>crossheading</heading>
65
+ </hcontainer>
55
66
  </section>
56
67
  </body>'
57
68
  end
@@ -63,33 +74,43 @@ Some content before the section
63
74
  (a) foo
64
75
  (b) bar
65
76
 
77
+ CROSSHEADING crossheading
78
+
66
79
  1. Section
67
80
  Hello there
81
+
82
+ CROSSHEADING crossheading
68
83
  EOS
69
84
  to_xml(node).should == '<body>
70
- <paragraph id="paragraph-0">
85
+ <paragraph id="paragraph0">
71
86
  <content>
72
87
  <p>Some content before the section</p>
73
- <blockList id="paragraph-0.list1">
74
- <item id="paragraph-0.list1.a">
88
+ <blockList id="paragraph0.list1">
89
+ <item id="paragraph0.list1.a">
75
90
  <num>(a)</num>
76
91
  <p>foo</p>
77
92
  </item>
78
- <item id="paragraph-0.list1.b">
93
+ <item id="paragraph0.list1.b">
79
94
  <num>(b)</num>
80
95
  <p>bar</p>
81
96
  </item>
82
97
  </blockList>
83
98
  </content>
84
99
  </paragraph>
100
+ <hcontainer id="crossheading-0" name="crossheading">
101
+ <heading>crossheading</heading>
102
+ </hcontainer>
85
103
  <section id="section-1">
86
104
  <num>1.</num>
87
105
  <heading>Section</heading>
88
- <paragraph id="section-1.paragraph-0">
106
+ <paragraph id="section-1.paragraph0">
89
107
  <content>
90
108
  <p>Hello there</p>
91
109
  </content>
92
110
  </paragraph>
111
+ <hcontainer id="section-1.crossheading-0" name="crossheading">
112
+ <heading>crossheading</heading>
113
+ </hcontainer>
93
114
  </section>
94
115
  </body>'
95
116
  end
@@ -98,19 +119,22 @@ EOS
98
119
  node = parse :body, <<EOS
99
120
  \\1. ignored
100
121
 
122
+ \\CROSSHEADING crossheading
123
+
101
124
  1. Section
102
125
  \\Chapter 2 ignored
103
126
  EOS
104
127
  to_xml(node).should == '<body>
105
- <paragraph id="paragraph-0">
128
+ <paragraph id="paragraph0">
106
129
  <content>
107
130
  <p>1. ignored</p>
131
+ <p>CROSSHEADING crossheading</p>
108
132
  </content>
109
133
  </paragraph>
110
134
  <section id="section-1">
111
135
  <num>1.</num>
112
136
  <heading>Section</heading>
113
- <paragraph id="section-1.paragraph-0">
137
+ <paragraph id="section-1.paragraph0">
114
138
  <content>
115
139
  <p>Chapter 2 ignored</p>
116
140
  </content>
@@ -137,7 +161,7 @@ EOS
137
161
  <section id="section-1">
138
162
  <num>1.</num>
139
163
  <heading>Section</heading>
140
- <paragraph id="section-1.paragraph-0">
164
+ <paragraph id="section-1.paragraph0">
141
165
  <content>
142
166
  <p>Hello there</p>
143
167
  </content>
@@ -158,7 +182,7 @@ EOS
158
182
  <section id="section-1">
159
183
  <num>1.</num>
160
184
  <heading>Section</heading>
161
- <paragraph id="section-1.paragraph-0">
185
+ <paragraph id="section-1.paragraph0">
162
186
  <content>
163
187
  <p>Hello there</p>
164
188
  </content>
@@ -172,6 +196,8 @@ EOS
172
196
  Chapter 2
173
197
  The Chapter Heading
174
198
 
199
+ CROSSHEADING crossheading
200
+
175
201
  Some lines at the start of the chapter.
176
202
  EOS
177
203
  node.num.should == "2"
@@ -179,7 +205,10 @@ EOS
179
205
  to_xml(node).should == '<chapter id="chapter-2">
180
206
  <num>2</num>
181
207
  <heading>The Chapter Heading</heading>
182
- <paragraph id="chapter-2.paragraph-0">
208
+ <hcontainer id="chapter-2.crossheading-0" name="crossheading">
209
+ <heading>crossheading</heading>
210
+ </hcontainer>
211
+ <paragraph id="chapter-2.paragraph0">
183
212
  <content>
184
213
  <p>Some lines at the start of the chapter.</p>
185
214
  </content>
@@ -202,7 +231,7 @@ EOS
202
231
  to_xml(node).should == '<chapter id="chapter-2">
203
232
  <num>2</num>
204
233
  <heading>The Chapter Heading</heading>
205
- <paragraph id="chapter-2.paragraph-0">
234
+ <paragraph id="chapter-2.paragraph0">
206
235
  <content>
207
236
  <p>Some lines at the start of the chapter.</p>
208
237
  </content>
@@ -210,7 +239,7 @@ EOS
210
239
  <section id="section-1">
211
240
  <num>1.</num>
212
241
  <heading>Section 1</heading>
213
- <paragraph id="section-1.paragraph-0">
242
+ <paragraph id="section-1.paragraph0">
214
243
  <content>
215
244
  <p>Section text.</p>
216
245
  </content>
@@ -232,7 +261,7 @@ EOS
232
261
  <section id="section-1">
233
262
  <num>1.</num>
234
263
  <heading>Section</heading>
235
- <paragraph id="section-1.paragraph-0">
264
+ <paragraph id="section-1.paragraph0">
236
265
  <content>
237
266
  <p>Hello there</p>
238
267
  </content>
@@ -269,9 +298,9 @@ EOS
269
298
  to_xml(node).should == '<chapter id="chapter-2">
270
299
  <num>2</num>
271
300
  <heading>The Chapter</heading>
272
- <paragraph id="chapter-2.paragraph-0">
301
+ <paragraph id="chapter-2.paragraph0">
273
302
  <content>
274
- <table id="chapter-2.paragraph-0.table0">
303
+ <table id="chapter-2.paragraph0.table0">
275
304
  <tr>
276
305
  <td>
277
306
  <p>foo</p>
@@ -296,7 +325,7 @@ EOS
296
325
  to_xml(node).should == '<chapter id="chapter-1">
297
326
  <num>1</num>
298
327
  <heading>The Chapter</heading>
299
- <paragraph id="chapter-1.paragraph-0">
328
+ <paragraph id="chapter-1.paragraph0">
300
329
  <content>
301
330
  <p>Stuff</p>
302
331
  <p>Chapter 2 - Ignored</p>
@@ -315,16 +344,22 @@ EOS
315
344
  node = parse :part, <<EOS
316
345
  pART 2
317
346
  The Part Heading
347
+
348
+ CROSSHEADING crossheading
349
+
318
350
  1. Section
319
351
  Hello there
320
352
  EOS
321
353
  to_xml(node).should == '<part id="part-2">
322
354
  <num>2</num>
323
355
  <heading>The Part Heading</heading>
356
+ <hcontainer id="part-2.crossheading-0" name="crossheading">
357
+ <heading>crossheading</heading>
358
+ </hcontainer>
324
359
  <section id="section-1">
325
360
  <num>1.</num>
326
361
  <heading>Section</heading>
327
- <paragraph id="section-1.paragraph-0">
362
+ <paragraph id="section-1.paragraph0">
328
363
  <content>
329
364
  <p>Hello there</p>
330
365
  </content>
@@ -345,7 +380,7 @@ EOS
345
380
  <section id="section-1">
346
381
  <num>1.</num>
347
382
  <heading>Section</heading>
348
- <paragraph id="section-1.paragraph-0">
383
+ <paragraph id="section-1.paragraph0">
349
384
  <content>
350
385
  <p>Hello there</p>
351
386
  </content>
@@ -366,7 +401,7 @@ EOS
366
401
  <section id="section-1">
367
402
  <num>1.</num>
368
403
  <heading>Section</heading>
369
- <paragraph id="section-1.paragraph-0">
404
+ <paragraph id="section-1.paragraph0">
370
405
  <content>
371
406
  <p>Hello there</p>
372
407
  </content>
@@ -387,7 +422,7 @@ EOS
387
422
  <section id="section-1">
388
423
  <num>1.</num>
389
424
  <heading>Section</heading>
390
- <paragraph id="section-1.paragraph-0">
425
+ <paragraph id="section-1.paragraph0">
391
426
  <content>
392
427
  <p>Hello there</p>
393
428
  </content>
@@ -409,7 +444,7 @@ EOS
409
444
  <section id="section-1">
410
445
  <num>1.</num>
411
446
  <heading>Section</heading>
412
- <paragraph id="section-1.paragraph-0">
447
+ <paragraph id="section-1.paragraph0">
413
448
  <content>
414
449
  <p>Hello there</p>
415
450
  </content>
@@ -432,7 +467,7 @@ EOS
432
467
  <section id="section-1">
433
468
  <num>1.</num>
434
469
  <heading/>
435
- <paragraph id="section-1.paragraph-0">
470
+ <paragraph id="section-1.paragraph0">
436
471
  <content>
437
472
  <p>No owner or occupier of any shop or business premises or vacant land adjoining a shop or business premises shall cause a health nuisance.</p>
438
473
  </content>
@@ -456,7 +491,7 @@ EOS
456
491
  to_xml(node).should == '<part id="part-2">
457
492
  <num>2</num>
458
493
  <heading>The Part Heading</heading>
459
- <paragraph id="part-2.paragraph-0">
494
+ <paragraph id="part-2.paragraph0">
460
495
  <content>
461
496
  <p>Some text before the part.</p>
462
497
  </content>
@@ -464,7 +499,7 @@ EOS
464
499
  <section id="section-1">
465
500
  <num>1.</num>
466
501
  <heading>Section</heading>
467
- <paragraph id="section-1.paragraph-0">
502
+ <paragraph id="section-1.paragraph0">
468
503
  <content>
469
504
  <p>Hello there</p>
470
505
  </content>
@@ -499,7 +534,7 @@ EOS
499
534
  <part id="part-2">
500
535
  <num>2</num>
501
536
  <heading>The Part Heading</heading>
502
- <paragraph id="part-2.paragraph-0">
537
+ <paragraph id="part-2.paragraph0">
503
538
  <content>
504
539
  <p>Part 3 ignored</p>
505
540
  </content>
@@ -1221,14 +1256,14 @@ EOS
1221
1256
  s.should == '<section id="section-1">
1222
1257
  <num>1.</num>
1223
1258
  <heading>Section</heading>
1224
- <paragraph id="section-1.paragraph-0">
1259
+ <paragraph id="section-1.paragraph0">
1225
1260
  <content>
1226
- <blockList id="section-1.paragraph-0.list0">
1227
- <item id="section-1.paragraph-0.list0.a">
1261
+ <blockList id="section-1.paragraph0.list0">
1262
+ <item id="section-1.paragraph0.list0.a">
1228
1263
  <num>(a)</num>
1229
1264
  <p>first</p>
1230
1265
  </item>
1231
- <item id="section-1.paragraph-0.list0.b">
1266
+ <item id="section-1.paragraph0.list0.b">
1232
1267
  <num>(b)</num>
1233
1268
  <p>second</p>
1234
1269
  </item>
@@ -1257,15 +1292,15 @@ EOS
1257
1292
  to_xml(node, "").should == '<section id="section-1">
1258
1293
  <num>1.</num>
1259
1294
  <heading>Section</heading>
1260
- <paragraph id="section-1.paragraph-0">
1295
+ <paragraph id="section-1.paragraph0">
1261
1296
  <content>
1262
1297
  <p>naked statement (c) blah</p>
1263
- <blockList id="section-1.paragraph-0.list1">
1264
- <item id="section-1.paragraph-0.list1.a">
1298
+ <blockList id="section-1.paragraph0.list1">
1299
+ <item id="section-1.paragraph0.list1.a">
1265
1300
  <num>(a)</num>
1266
1301
  <p>foo</p>
1267
1302
  </item>
1268
- <item id="section-1.paragraph-0.list1.b">
1303
+ <item id="section-1.paragraph0.list1.b">
1269
1304
  <num>(b)</num>
1270
1305
  <p>bar</p>
1271
1306
  </item>
@@ -1329,7 +1364,7 @@ EOS
1329
1364
  to_xml(node, "").should == '<section id="section-1">
1330
1365
  <num>1.</num>
1331
1366
  <heading>Section</heading>
1332
- <paragraph id="section-1.paragraph-0">
1367
+ <paragraph id="section-1.paragraph0">
1333
1368
  <content>
1334
1369
  <p>1. ignored</p>
1335
1370
  <p>2. another line</p>
@@ -1415,7 +1450,7 @@ EOS
1415
1450
  <mainBody>
1416
1451
  <hcontainer id="schedule" name="schedule">
1417
1452
  <heading>Schedule</heading>
1418
- <paragraph id="schedule.paragraph-0">
1453
+ <paragraph id="schedule.paragraph0">
1419
1454
  <content>
1420
1455
  <p>Subject to approval in terms of this By-Law, the erection:</p>
1421
1456
  </content>
@@ -1524,7 +1559,7 @@ EOS
1524
1559
  <hcontainer id="schedule3" name="schedule">
1525
1560
  <heading>Schedule 3</heading>
1526
1561
  <subheading>Another Title</subheading>
1527
- <paragraph id="schedule3.paragraph-0">
1562
+ <paragraph id="schedule3.paragraph0">
1528
1563
  <content>
1529
1564
  <p>Baz</p>
1530
1565
  <p>Boom</p>
@@ -1582,7 +1617,7 @@ EOS
1582
1617
  <hcontainer id="schedule1" name="schedule">
1583
1618
  <heading>First Schedule</heading>
1584
1619
  <subheading>Schedule Heading</subheading>
1585
- <paragraph id="schedule1.paragraph-0">
1620
+ <paragraph id="schedule1.paragraph0">
1586
1621
  <content>
1587
1622
  <p>Subject to approval in terms of this By-Law, the erection:</p>
1588
1623
  </content>
@@ -1643,7 +1678,7 @@ EOS
1643
1678
  <hcontainer id="schedule1" name="schedule">
1644
1679
  <heading>First Schedule</heading>
1645
1680
  <subheading>Schedule Heading</subheading>
1646
- <paragraph id="schedule1.paragraph-0">
1681
+ <paragraph id="schedule1.paragraph0">
1647
1682
  <content>
1648
1683
  <p>Subject to approval in terms of this By-Law, the erection:</p>
1649
1684
  </content>
@@ -1702,7 +1737,7 @@ EOS
1702
1737
  <mainBody>
1703
1738
  <hcontainer id="firstschedule" name="schedule">
1704
1739
  <heading>First Schedule</heading>
1705
- <paragraph id="firstschedule.paragraph-0">
1740
+ <paragraph id="firstschedule.paragraph0">
1706
1741
  <content>
1707
1742
  <p>Subject to approval in terms of this By-Law, the erection:</p>
1708
1743
  </content>
@@ -1763,7 +1798,7 @@ EOS
1763
1798
  <mainBody>
1764
1799
  <hcontainer id="schedule1" name="schedule">
1765
1800
  <heading>Schedule 1</heading>
1766
- <paragraph id="schedule1.paragraph-0">
1801
+ <paragraph id="schedule1.paragraph0">
1767
1802
  <content>
1768
1803
  <p>Other than as is set out hereinbelow, no signs other than locality bound signs, temporary signs including loose portable sign, estate agents signs, newspaper headline posters and posters (the erection of which must comply with the appropriate schedules pertinent thereto) shall be erected on Municipal owned land.</p>
1769
1804
  </content>
@@ -1837,7 +1872,7 @@ EOS
1837
1872
  <part id="part-I">
1838
1873
  <num>I</num>
1839
1874
  <heading>Form of authentication statement</heading>
1840
- <paragraph id="part-I.paragraph-0">
1875
+ <paragraph id="part-I.paragraph0">
1841
1876
  <content>
1842
1877
  <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>
1843
1878
  </content>
@@ -1846,7 +1881,7 @@ EOS
1846
1881
  <part id="part-II">
1847
1882
  <num>II</num>
1848
1883
  <heading>Form of statement of the President’s assent.</heading>
1849
- <paragraph id="part-II.paragraph-0">
1884
+ <paragraph id="part-II.paragraph0">
1850
1885
  <content>
1851
1886
  <p>I signify my assent to the bill and a whole bunch of other stuff.</p>
1852
1887
  </content>
@@ -1911,7 +1946,7 @@ EOS
1911
1946
  <mainBody>
1912
1947
  <hcontainer id="schedule" name="schedule">
1913
1948
  <heading>Schedule</heading>
1914
- <paragraph id="schedule.paragraph-0">
1949
+ <paragraph id="schedule.paragraph0">
1915
1950
  <content>
1916
1951
  <p>Subject to approval in terms of this By-Law.</p>
1917
1952
  <p>Schedule another</p>
@@ -1927,23 +1962,105 @@ EOS
1927
1962
  end
1928
1963
 
1929
1964
  #-------------------------------------------------------------------------------
1930
- # clauses
1965
+ # inline_items
1931
1966
 
1932
- context 'clauses' do
1967
+ context 'inline_items' do
1933
1968
  it 'should handle a simple clause' do
1934
- node = parse :clauses, "simple text"
1969
+ node = parse :inline_items, "simple text"
1935
1970
  node.text_value.should == "simple text"
1936
1971
  end
1937
1972
 
1938
1973
  it 'should handle a clause with a remark' do
1939
- node = parse :clauses, "simple [[remark]]. text"
1974
+ node = parse :inline_items, "simple [[remark]]. text"
1940
1975
  node.text_value.should == "simple [[remark]]. text"
1941
1976
  node.elements[7].is_a?(Slaw::Grammars::ZA::Act::Remark).should be_true
1942
1977
 
1943
- node = parse :clauses, "simple [[remark]][[another]] text"
1978
+ node = parse :inline_items, "simple [[remark]][[another]] text"
1944
1979
  node.text_value.should == "simple [[remark]][[another]] text"
1945
1980
  node.elements[7].is_a?(Slaw::Grammars::ZA::Act::Remark).should be_true
1946
1981
  node.elements[7].is_a?(Slaw::Grammars::ZA::Act::Remark).should be_true
1947
1982
  end
1948
1983
  end
1984
+
1985
+ #-------------------------------------------------------------------------------
1986
+ # crossheadings
1987
+
1988
+ context 'crossheadings' do
1989
+ it 'should handle a inline_items in crossheadings' do
1990
+ node = parse :crossheading, "CROSSHEADING something [[remark]] [link](/foo/bar)\n"
1991
+ to_xml(node, '').should == '<hcontainer id="crossheading-0" name="crossheading">
1992
+ <heading>something <remark status="editorial">[remark]</remark> <ref href="/foo/bar">link</ref></heading>
1993
+ </hcontainer>'
1994
+ end
1995
+ end
1996
+
1997
+ #-------------------------------------------------------------------------------
1998
+ # longTitle
1999
+
2000
+ context 'longtitle' do
2001
+ it 'should handle a basic longtitle' do
2002
+ node = parse :longtitle, "LONGTITLE something [[remark]] [link](/foo/bar)\n"
2003
+ to_xml(node, '').should == '<longTitle>
2004
+ <p>something <remark status="editorial">[remark]</remark> <ref href="/foo/bar">link</ref></p>
2005
+ </longTitle>'
2006
+ end
2007
+
2008
+ it 'should handle a longtitle in a preface' do
2009
+ node = parse :act, <<EOS
2010
+ PREFACE
2011
+
2012
+ Blah blah
2013
+
2014
+ LONGTITLE a long title
2015
+
2016
+ \\LONGTITLE escaped
2017
+
2018
+ Enacting clause
2019
+
2020
+ 1. Section
2021
+ (1) hello
2022
+ EOS
2023
+
2024
+ to_xml(node.preface).should == '<preface>
2025
+ <p>Blah blah</p>
2026
+ <longTitle>
2027
+ <p>a long title</p>
2028
+ </longTitle>
2029
+ <p>LONGTITLE escaped</p>
2030
+ <p>Enacting clause</p>
2031
+ </preface>'
2032
+ end
2033
+
2034
+ it 'should ignore a longtitle in preamble' do
2035
+ node = parse :preamble, <<EOS
2036
+ PREAMBLE
2037
+
2038
+ LONGTITLE a long title
2039
+ EOS
2040
+
2041
+ to_xml(node).should == '<preamble>
2042
+ <p>LONGTITLE a long title</p>
2043
+ </preamble>'
2044
+ end
2045
+
2046
+ it 'should ignore a longtitle in body' do
2047
+ node = parse :body, <<EOS
2048
+ 1. Section
2049
+
2050
+ LONGTITLE a long title
2051
+ EOS
2052
+
2053
+ to_xml(node).should == '<body>
2054
+ <section id="section-1">
2055
+ <num>1.</num>
2056
+ <heading>Section</heading>
2057
+ <paragraph id="section-1.paragraph0">
2058
+ <content>
2059
+ <p>LONGTITLE a long title</p>
2060
+ </content>
2061
+ </paragraph>
2062
+ </section>
2063
+ </body>'
2064
+ end
2065
+ end
1949
2066
  end