slaw 0.13.0 → 0.14.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/parse/cleanser.rb +16 -4
- data/lib/slaw/version.rb +1 -1
- data/lib/slaw/za/act.treetop +10 -1
- data/lib/slaw/za/act_nodes.rb +8 -0
- data/spec/za/{act_spec.rb → act_block_spec.rb} +0 -251
- data/spec/za/act_inline_spec.rb +308 -0
- data/spec/za/act_schedules_spec.rb +576 -0
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f461d44372208bc42f6cedb31c28b4cf8953c58d
|
4
|
+
data.tar.gz: cc3e56f02927e80e96aacfb67b19b3be88c64836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ba42c10bd5fb2efaf5bec9e9570efb0cbd840c974d0ccf69509114358a9bc4370385d07d4ec18d685c39f96c61899790fdd101d30df69596e634875ebcac9b
|
7
|
+
data.tar.gz: 8c47909bbe42bd51b6fb0ebb46893b4808340e8259aa79721ed1516f8dfd9740e7873a5ba65451245505d8890be26a61bc10aec7ce9f29af2766d1ef74314d27
|
data/README.md
CHANGED
@@ -218,6 +218,11 @@ Akoma Ntoso `component` elements at the end of the XML document, with a name of
|
|
218
218
|
|
219
219
|
## Changelog
|
220
220
|
|
221
|
+
### 0.14.0
|
222
|
+
|
223
|
+
* Support inline image tags, using Markdown syntax: \![alt text](image url)
|
224
|
+
* Smarter un-break lines
|
225
|
+
|
221
226
|
### 0.13.0
|
222
227
|
|
223
228
|
* FIX allow Schedule, Part and other headings at the start of blocklist and subsections
|
data/lib/slaw/parse/cleanser.rb
CHANGED
@@ -47,7 +47,7 @@ module Slaw
|
|
47
47
|
def scrub(s)
|
48
48
|
# we often get this unicode codepoint in the string, nuke it
|
49
49
|
s.gsub([65532].pack('U*'), '')\
|
50
|
-
.gsub(
|
50
|
+
.gsub(/\n*/, '')
|
51
51
|
end
|
52
52
|
|
53
53
|
# change weird quotes to normal ones
|
@@ -135,8 +135,12 @@ module Slaw
|
|
135
135
|
def unbreak_lines(s)
|
136
136
|
lines = s.split(/\n/)
|
137
137
|
output = []
|
138
|
-
|
139
|
-
|
138
|
+
|
139
|
+
# set of regex matcher pairs, one for the prev line, one for the current line
|
140
|
+
matchers = [
|
141
|
+
[/[a-z0-9]$/, /^\s*[a-z]/], # line ends with and starst with lowercase
|
142
|
+
[/;$/, /^\s*(and|or)/], # ends with ; then and/or on new line
|
143
|
+
]
|
140
144
|
|
141
145
|
prev = nil
|
142
146
|
lines.each_with_index do |line, i|
|
@@ -144,8 +148,16 @@ module Slaw
|
|
144
148
|
output << line
|
145
149
|
else
|
146
150
|
prev = output[-1]
|
151
|
+
unbreak = false
|
152
|
+
|
153
|
+
for prev_re, curr_re in matchers
|
154
|
+
if prev =~ prev_re and line =~ curr_re
|
155
|
+
unbreak = true
|
156
|
+
break
|
157
|
+
end
|
158
|
+
end
|
147
159
|
|
148
|
-
if
|
160
|
+
if unbreak
|
149
161
|
output[-1] = prev + ' ' + line
|
150
162
|
else
|
151
163
|
output << line
|
data/lib/slaw/version.rb
CHANGED
data/lib/slaw/za/act.treetop
CHANGED
@@ -210,7 +210,7 @@ module Slaw
|
|
210
210
|
|
211
211
|
# one or more words, allowing inline elements
|
212
212
|
rule clauses
|
213
|
-
(remark / ref / [^\n])+
|
213
|
+
(remark / image / ref / [^\n])+
|
214
214
|
<Clauses>
|
215
215
|
end
|
216
216
|
|
@@ -219,6 +219,15 @@ module Slaw
|
|
219
219
|
<Remark>
|
220
220
|
end
|
221
221
|
|
222
|
+
rule image
|
223
|
+
# images like markdown
|
224
|
+
# eg. ![title text](image url)
|
225
|
+
#
|
226
|
+
# the title text is optional, but the enclosing square brackets aren't
|
227
|
+
'![' content:(!'](' [^\n])* '](' href:([^)\n]+) ')'
|
228
|
+
<Image>
|
229
|
+
end
|
230
|
+
|
222
231
|
rule ref
|
223
232
|
# links like markdown
|
224
233
|
# eg. [link text](link url)
|
data/lib/slaw/za/act_nodes.rb
CHANGED
@@ -312,6 +312,14 @@ module Slaw
|
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
315
|
+
class Image < Treetop::Runtime::SyntaxNode
|
316
|
+
def to_xml(b, idprefix)
|
317
|
+
attrs = {src: href.text_value}
|
318
|
+
attrs[:alt] = content.text_value unless content.text_value.empty?
|
319
|
+
b.img(attrs)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
315
323
|
class Ref < Treetop::Runtime::SyntaxNode
|
316
324
|
def to_xml(b, idprefix)
|
317
325
|
b.ref(content.text_value, href: href.text_value)
|
@@ -842,257 +842,6 @@ EOS
|
|
842
842
|
end
|
843
843
|
end
|
844
844
|
|
845
|
-
#-------------------------------------------------------------------------------
|
846
|
-
# Remarks
|
847
|
-
|
848
|
-
describe 'remark' do
|
849
|
-
it 'should handle a plain remark' do
|
850
|
-
node = parse :block_paragraphs, <<EOS
|
851
|
-
[[Section 2 amended by Act 23 of 2004]]
|
852
|
-
EOS
|
853
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
854
|
-
<content>
|
855
|
-
<p>
|
856
|
-
<remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>
|
857
|
-
</p>
|
858
|
-
</content>
|
859
|
-
</paragraph>'
|
860
|
-
end
|
861
|
-
|
862
|
-
it 'should handle an inline remark at the end of a sentence' do
|
863
|
-
node = parse :block_paragraphs, <<EOS
|
864
|
-
This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]
|
865
|
-
EOS
|
866
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
867
|
-
<content>
|
868
|
-
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark></p>
|
869
|
-
</content>
|
870
|
-
</paragraph>'
|
871
|
-
end
|
872
|
-
|
873
|
-
it 'should handle an inline remark mid-way through' do
|
874
|
-
node = parse :subsection, <<EOS
|
875
|
-
(1) This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]] And now some more.
|
876
|
-
EOS
|
877
|
-
to_xml(node, "", 1).should == '<subsection id="1">
|
878
|
-
<num>(1)</num>
|
879
|
-
<content>
|
880
|
-
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark> And now some more.</p>
|
881
|
-
</content>
|
882
|
-
</subsection>'
|
883
|
-
end
|
884
|
-
|
885
|
-
it 'should handle many inline remarks' do
|
886
|
-
node = parse :block_paragraphs, <<EOS
|
887
|
-
This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]. And now some more. [[Another remark]] [[and another]]
|
888
|
-
EOS
|
889
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
890
|
-
<content>
|
891
|
-
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>. And now some more. <remark status="editorial">[Another remark]</remark> <remark status="editorial">[and another]</remark></p>
|
892
|
-
</content>
|
893
|
-
</paragraph>'
|
894
|
-
end
|
895
|
-
|
896
|
-
it 'should handle a remark in a section' do
|
897
|
-
node = parse :section, <<EOS
|
898
|
-
1. Section title
|
899
|
-
Some text is a long line.
|
900
|
-
|
901
|
-
[[Section 1 amended by Act 23 of 2004]]
|
902
|
-
EOS
|
903
|
-
to_xml(node).should == '<section id="section-1">
|
904
|
-
<num>1.</num>
|
905
|
-
<heading>Section title</heading>
|
906
|
-
<paragraph id="section-1.paragraph-0">
|
907
|
-
<content>
|
908
|
-
<p>Some text is a long line.</p>
|
909
|
-
<p>
|
910
|
-
<remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark>
|
911
|
-
</p>
|
912
|
-
</content>
|
913
|
-
</paragraph>
|
914
|
-
</section>'
|
915
|
-
end
|
916
|
-
|
917
|
-
it 'should handle a remark in a blocklist' do
|
918
|
-
node = parse :section, <<EOS
|
919
|
-
1. Section title
|
920
|
-
Some text is a long line.
|
921
|
-
|
922
|
-
(1) something
|
923
|
-
(a) with a remark [[Section 1 amended by Act 23 of 2004]]
|
924
|
-
EOS
|
925
|
-
to_xml(node).should == '<section id="section-1">
|
926
|
-
<num>1.</num>
|
927
|
-
<heading>Section title</heading>
|
928
|
-
<paragraph id="section-1.paragraph-0">
|
929
|
-
<content>
|
930
|
-
<p>Some text is a long line.</p>
|
931
|
-
</content>
|
932
|
-
</paragraph>
|
933
|
-
<subsection id="section-1.1">
|
934
|
-
<num>(1)</num>
|
935
|
-
<content>
|
936
|
-
<p>something</p>
|
937
|
-
<blockList id="section-1.1.list1">
|
938
|
-
<item id="section-1.1.list1.a">
|
939
|
-
<num>(a)</num>
|
940
|
-
<p>with a remark <remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark></p>
|
941
|
-
</item>
|
942
|
-
</blockList>
|
943
|
-
</content>
|
944
|
-
</subsection>
|
945
|
-
</section>'
|
946
|
-
end
|
947
|
-
|
948
|
-
it 'should handle a remark in a schedule' do
|
949
|
-
node = parse :schedule, <<EOS
|
950
|
-
Schedule 1
|
951
|
-
A Title
|
952
|
-
|
953
|
-
[[Schedule 1 added by Act 23 of 2004]]
|
954
|
-
|
955
|
-
Some content
|
956
|
-
EOS
|
957
|
-
|
958
|
-
today = Time.now.strftime('%Y-%m-%d')
|
959
|
-
to_xml(node, "").should == '<component id="component-schedule1">
|
960
|
-
<doc name="schedule1">
|
961
|
-
<meta>
|
962
|
-
<identification source="#slaw">
|
963
|
-
<FRBRWork>
|
964
|
-
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
965
|
-
<FRBRuri value="/za/act/1980/01"/>
|
966
|
-
<FRBRalias value="Schedule 1"/>
|
967
|
-
<FRBRdate date="1980-01-01" name="Generation"/>
|
968
|
-
<FRBRauthor href="#council"/>
|
969
|
-
<FRBRcountry value="za"/>
|
970
|
-
</FRBRWork>
|
971
|
-
<FRBRExpression>
|
972
|
-
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
973
|
-
<FRBRuri value="/za/act/1980/01/eng@"/>
|
974
|
-
<FRBRdate date="1980-01-01" name="Generation"/>
|
975
|
-
<FRBRauthor href="#council"/>
|
976
|
-
<FRBRlanguage language="eng"/>
|
977
|
-
</FRBRExpression>
|
978
|
-
<FRBRManifestation>
|
979
|
-
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
980
|
-
<FRBRuri value="/za/act/1980/01/eng@"/>
|
981
|
-
<FRBRdate date="' + today + '" name="Generation"/>
|
982
|
-
<FRBRauthor href="#slaw"/>
|
983
|
-
</FRBRManifestation>
|
984
|
-
</identification>
|
985
|
-
</meta>
|
986
|
-
<mainBody>
|
987
|
-
<article id="schedule1">
|
988
|
-
<heading>A Title</heading>
|
989
|
-
<paragraph id="schedule1.paragraph-0">
|
990
|
-
<content>
|
991
|
-
<p>
|
992
|
-
<remark status="editorial">[Schedule 1 added by Act 23 of 2004]</remark>
|
993
|
-
</p>
|
994
|
-
<p>Some content</p>
|
995
|
-
</content>
|
996
|
-
</paragraph>
|
997
|
-
</article>
|
998
|
-
</mainBody>
|
999
|
-
</doc>
|
1000
|
-
</component>'
|
1001
|
-
end
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
#-------------------------------------------------------------------------------
|
1005
|
-
# Refs
|
1006
|
-
|
1007
|
-
describe 'ref' do
|
1008
|
-
it 'should handle a plain ref' do
|
1009
|
-
node = parse :block_paragraphs, <<EOS
|
1010
|
-
Hello [there](/za/act/123) friend.
|
1011
|
-
EOS
|
1012
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1013
|
-
<content>
|
1014
|
-
<p>Hello <ref href="/za/act/123">there</ref> friend.</p>
|
1015
|
-
</content>
|
1016
|
-
</paragraph>'
|
1017
|
-
end
|
1018
|
-
|
1019
|
-
it 'should work many on a line' do
|
1020
|
-
node = parse :block_paragraphs, <<EOS
|
1021
|
-
Hello [there](/za/act/123) friend [and](http://foo.bar.com/with space) you too.
|
1022
|
-
EOS
|
1023
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1024
|
-
<content>
|
1025
|
-
<p>Hello <ref href="/za/act/123">there</ref> friend <ref href="http://foo.bar.com/with space">and</ref> you too.</p>
|
1026
|
-
</content>
|
1027
|
-
</paragraph>'
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
it 'should handle brackets' do
|
1031
|
-
node = parse :block_paragraphs, <<EOS
|
1032
|
-
Hello ([there](/za/act/123)).
|
1033
|
-
EOS
|
1034
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1035
|
-
<content>
|
1036
|
-
<p>Hello (<ref href="/za/act/123">there</ref>).</p>
|
1037
|
-
</content>
|
1038
|
-
</paragraph>'
|
1039
|
-
end
|
1040
|
-
|
1041
|
-
it 'should handle many clauses on a line' do
|
1042
|
-
node = parse :block_paragraphs, <<EOS
|
1043
|
-
Hello [there](/za/act/123)[[remark one]] my[friend](/za) [[remark 2]][end](/foo).
|
1044
|
-
EOS
|
1045
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1046
|
-
<content>
|
1047
|
-
<p>Hello <ref href="/za/act/123">there</ref><remark status="editorial">[remark one]</remark> my<ref href="/za">friend</ref> <remark status="editorial">[remark 2]</remark><ref href="/foo">end</ref>.</p>
|
1048
|
-
</content>
|
1049
|
-
</paragraph>'
|
1050
|
-
end
|
1051
|
-
|
1052
|
-
it 'text should not cross end of line' do
|
1053
|
-
node = parse :block_paragraphs, <<EOS
|
1054
|
-
Hello [there
|
1055
|
-
|
1056
|
-
my](/za/act/123) friend.
|
1057
|
-
EOS
|
1058
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1059
|
-
<content>
|
1060
|
-
<p>Hello [there</p>
|
1061
|
-
<p>my](/za/act/123) friend.</p>
|
1062
|
-
</content>
|
1063
|
-
</paragraph>'
|
1064
|
-
end
|
1065
|
-
|
1066
|
-
it 'href should not cross end of line' do
|
1067
|
-
node = parse :block_paragraphs, <<EOS
|
1068
|
-
Hello [there](/za/act
|
1069
|
-
/123) friend.
|
1070
|
-
EOS
|
1071
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1072
|
-
<content>
|
1073
|
-
<p>Hello [there](/za/act</p>
|
1074
|
-
<p>/123) friend.</p>
|
1075
|
-
</content>
|
1076
|
-
</paragraph>'
|
1077
|
-
end
|
1078
|
-
|
1079
|
-
it 'href should handle refs in a list' do
|
1080
|
-
node = parse :block_paragraphs, <<EOS
|
1081
|
-
2.18.1 a traffic officer appointed in terms of section 3 of the Road Traffic [Act, No. 29 of 1989](/za/act/1989/29) or section 3A of the National Road Traffic [Act No. 93 of 1996](/za/act/1996/93) as the case may be;
|
1082
|
-
EOS
|
1083
|
-
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
1084
|
-
<content>
|
1085
|
-
<blockList id="paragraph-0.list0">
|
1086
|
-
<item id="paragraph-0.list0.2.18.1">
|
1087
|
-
<num>2.18.1</num>
|
1088
|
-
<p>a traffic officer appointed in terms of section 3 of the Road Traffic <ref href="/za/act/1989/29">Act, No. 29 of 1989</ref> or section 3A of the National Road Traffic <ref href="/za/act/1996/93">Act No. 93 of 1996</ref> as the case may be;</p>
|
1089
|
-
</item>
|
1090
|
-
</blockList>
|
1091
|
-
</content>
|
1092
|
-
</paragraph>'
|
1093
|
-
end
|
1094
|
-
end
|
1095
|
-
|
1096
845
|
#-------------------------------------------------------------------------------
|
1097
846
|
# Numbered statements
|
1098
847
|
|
@@ -0,0 +1,308 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'builder'
|
4
|
+
|
5
|
+
require 'slaw'
|
6
|
+
|
7
|
+
describe Slaw::ActGenerator do
|
8
|
+
def parse(rule, s)
|
9
|
+
subject.builder.text_to_syntax_tree(s, {root: rule})
|
10
|
+
end
|
11
|
+
|
12
|
+
def should_parse(rule, s)
|
13
|
+
s << "\n" unless s.end_with?("\n")
|
14
|
+
tree = subject.builder.text_to_syntax_tree(s, {root: rule})
|
15
|
+
|
16
|
+
if not tree
|
17
|
+
raise Exception.new(subject.failure_reason || "Couldn't match to grammar") if tree.nil?
|
18
|
+
else
|
19
|
+
# count an assertion
|
20
|
+
tree.should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xml(node, *args)
|
25
|
+
b = ::Nokogiri::XML::Builder.new
|
26
|
+
node.to_xml(b, *args)
|
27
|
+
b.doc.root.to_xml(encoding: 'UTF-8')
|
28
|
+
end
|
29
|
+
|
30
|
+
#-------------------------------------------------------------------------------
|
31
|
+
# Remarks
|
32
|
+
|
33
|
+
describe 'remark' do
|
34
|
+
it 'should handle a plain remark' do
|
35
|
+
node = parse :block_paragraphs, <<EOS
|
36
|
+
[[Section 2 amended by Act 23 of 2004]]
|
37
|
+
EOS
|
38
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
39
|
+
<content>
|
40
|
+
<p>
|
41
|
+
<remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>
|
42
|
+
</p>
|
43
|
+
</content>
|
44
|
+
</paragraph>'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should handle an inline remark at the end of a sentence' do
|
48
|
+
node = parse :block_paragraphs, <<EOS
|
49
|
+
This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]
|
50
|
+
EOS
|
51
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
52
|
+
<content>
|
53
|
+
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark></p>
|
54
|
+
</content>
|
55
|
+
</paragraph>'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should handle an inline remark mid-way through' do
|
59
|
+
node = parse :subsection, <<EOS
|
60
|
+
(1) This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]] And now some more.
|
61
|
+
EOS
|
62
|
+
to_xml(node, "", 1).should == '<subsection id="1">
|
63
|
+
<num>(1)</num>
|
64
|
+
<content>
|
65
|
+
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark> And now some more.</p>
|
66
|
+
</content>
|
67
|
+
</subsection>'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should handle many inline remarks' do
|
71
|
+
node = parse :block_paragraphs, <<EOS
|
72
|
+
This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]. And now some more. [[Another remark]] [[and another]]
|
73
|
+
EOS
|
74
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
75
|
+
<content>
|
76
|
+
<p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>. And now some more. <remark status="editorial">[Another remark]</remark> <remark status="editorial">[and another]</remark></p>
|
77
|
+
</content>
|
78
|
+
</paragraph>'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should handle a remark in a section' do
|
82
|
+
node = parse :section, <<EOS
|
83
|
+
1. Section title
|
84
|
+
Some text is a long line.
|
85
|
+
|
86
|
+
[[Section 1 amended by Act 23 of 2004]]
|
87
|
+
EOS
|
88
|
+
to_xml(node).should == '<section id="section-1">
|
89
|
+
<num>1.</num>
|
90
|
+
<heading>Section title</heading>
|
91
|
+
<paragraph id="section-1.paragraph-0">
|
92
|
+
<content>
|
93
|
+
<p>Some text is a long line.</p>
|
94
|
+
<p>
|
95
|
+
<remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark>
|
96
|
+
</p>
|
97
|
+
</content>
|
98
|
+
</paragraph>
|
99
|
+
</section>'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should handle a remark in a blocklist' do
|
103
|
+
node = parse :section, <<EOS
|
104
|
+
1. Section title
|
105
|
+
Some text is a long line.
|
106
|
+
|
107
|
+
(1) something
|
108
|
+
(a) with a remark [[Section 1 amended by Act 23 of 2004]]
|
109
|
+
EOS
|
110
|
+
to_xml(node).should == '<section id="section-1">
|
111
|
+
<num>1.</num>
|
112
|
+
<heading>Section title</heading>
|
113
|
+
<paragraph id="section-1.paragraph-0">
|
114
|
+
<content>
|
115
|
+
<p>Some text is a long line.</p>
|
116
|
+
</content>
|
117
|
+
</paragraph>
|
118
|
+
<subsection id="section-1.1">
|
119
|
+
<num>(1)</num>
|
120
|
+
<content>
|
121
|
+
<p>something</p>
|
122
|
+
<blockList id="section-1.1.list1">
|
123
|
+
<item id="section-1.1.list1.a">
|
124
|
+
<num>(a)</num>
|
125
|
+
<p>with a remark <remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark></p>
|
126
|
+
</item>
|
127
|
+
</blockList>
|
128
|
+
</content>
|
129
|
+
</subsection>
|
130
|
+
</section>'
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should handle a remark in a schedule' do
|
134
|
+
node = parse :schedule, <<EOS
|
135
|
+
Schedule 1
|
136
|
+
A Title
|
137
|
+
|
138
|
+
[[Schedule 1 added by Act 23 of 2004]]
|
139
|
+
|
140
|
+
Some content
|
141
|
+
EOS
|
142
|
+
|
143
|
+
today = Time.now.strftime('%Y-%m-%d')
|
144
|
+
to_xml(node, "").should == '<component id="component-schedule1">
|
145
|
+
<doc name="schedule1">
|
146
|
+
<meta>
|
147
|
+
<identification source="#slaw">
|
148
|
+
<FRBRWork>
|
149
|
+
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
150
|
+
<FRBRuri value="/za/act/1980/01"/>
|
151
|
+
<FRBRalias value="Schedule 1"/>
|
152
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
153
|
+
<FRBRauthor href="#council"/>
|
154
|
+
<FRBRcountry value="za"/>
|
155
|
+
</FRBRWork>
|
156
|
+
<FRBRExpression>
|
157
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
158
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
159
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
160
|
+
<FRBRauthor href="#council"/>
|
161
|
+
<FRBRlanguage language="eng"/>
|
162
|
+
</FRBRExpression>
|
163
|
+
<FRBRManifestation>
|
164
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
165
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
166
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
167
|
+
<FRBRauthor href="#slaw"/>
|
168
|
+
</FRBRManifestation>
|
169
|
+
</identification>
|
170
|
+
</meta>
|
171
|
+
<mainBody>
|
172
|
+
<article id="schedule1">
|
173
|
+
<heading>A Title</heading>
|
174
|
+
<paragraph id="schedule1.paragraph-0">
|
175
|
+
<content>
|
176
|
+
<p>
|
177
|
+
<remark status="editorial">[Schedule 1 added by Act 23 of 2004]</remark>
|
178
|
+
</p>
|
179
|
+
<p>Some content</p>
|
180
|
+
</content>
|
181
|
+
</paragraph>
|
182
|
+
</article>
|
183
|
+
</mainBody>
|
184
|
+
</doc>
|
185
|
+
</component>'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#-------------------------------------------------------------------------------
|
190
|
+
# Refs
|
191
|
+
|
192
|
+
describe 'ref' do
|
193
|
+
it 'should handle a plain ref' do
|
194
|
+
node = parse :block_paragraphs, <<EOS
|
195
|
+
Hello [there](/za/act/123) friend.
|
196
|
+
EOS
|
197
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
198
|
+
<content>
|
199
|
+
<p>Hello <ref href="/za/act/123">there</ref> friend.</p>
|
200
|
+
</content>
|
201
|
+
</paragraph>'
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should work many on a line' do
|
205
|
+
node = parse :block_paragraphs, <<EOS
|
206
|
+
Hello [there](/za/act/123) friend [and](http://foo.bar.com/with space) you too.
|
207
|
+
EOS
|
208
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
209
|
+
<content>
|
210
|
+
<p>Hello <ref href="/za/act/123">there</ref> friend <ref href="http://foo.bar.com/with space">and</ref> you too.</p>
|
211
|
+
</content>
|
212
|
+
</paragraph>'
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should handle brackets' do
|
216
|
+
node = parse :block_paragraphs, <<EOS
|
217
|
+
Hello ([there](/za/act/123)).
|
218
|
+
EOS
|
219
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
220
|
+
<content>
|
221
|
+
<p>Hello (<ref href="/za/act/123">there</ref>).</p>
|
222
|
+
</content>
|
223
|
+
</paragraph>'
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should handle many clauses on a line' do
|
227
|
+
node = parse :block_paragraphs, <<EOS
|
228
|
+
Hello [there](/za/act/123)[[remark one]] my[friend](/za) [[remark 2]][end](/foo).
|
229
|
+
EOS
|
230
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
231
|
+
<content>
|
232
|
+
<p>Hello <ref href="/za/act/123">there</ref><remark status="editorial">[remark one]</remark> my<ref href="/za">friend</ref> <remark status="editorial">[remark 2]</remark><ref href="/foo">end</ref>.</p>
|
233
|
+
</content>
|
234
|
+
</paragraph>'
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'text should not cross end of line' do
|
238
|
+
node = parse :block_paragraphs, <<EOS
|
239
|
+
Hello [there
|
240
|
+
|
241
|
+
my](/za/act/123) friend.
|
242
|
+
EOS
|
243
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
244
|
+
<content>
|
245
|
+
<p>Hello [there</p>
|
246
|
+
<p>my](/za/act/123) friend.</p>
|
247
|
+
</content>
|
248
|
+
</paragraph>'
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'href should not cross end of line' do
|
252
|
+
node = parse :block_paragraphs, <<EOS
|
253
|
+
Hello [there](/za/act
|
254
|
+
/123) friend.
|
255
|
+
EOS
|
256
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
257
|
+
<content>
|
258
|
+
<p>Hello [there](/za/act</p>
|
259
|
+
<p>/123) friend.</p>
|
260
|
+
</content>
|
261
|
+
</paragraph>'
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'href should handle refs in a list' do
|
265
|
+
node = parse :block_paragraphs, <<EOS
|
266
|
+
2.18.1 a traffic officer appointed in terms of section 3 of the Road Traffic [Act, No. 29 of 1989](/za/act/1989/29) or section 3A of the National Road Traffic [Act No. 93 of 1996](/za/act/1996/93) as the case may be;
|
267
|
+
EOS
|
268
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
269
|
+
<content>
|
270
|
+
<blockList id="paragraph-0.list0">
|
271
|
+
<item id="paragraph-0.list0.2.18.1">
|
272
|
+
<num>2.18.1</num>
|
273
|
+
<p>a traffic officer appointed in terms of section 3 of the Road Traffic <ref href="/za/act/1989/29">Act, No. 29 of 1989</ref> or section 3A of the National Road Traffic <ref href="/za/act/1996/93">Act No. 93 of 1996</ref> as the case may be;</p>
|
274
|
+
</item>
|
275
|
+
</blockList>
|
276
|
+
</content>
|
277
|
+
</paragraph>'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
#-------------------------------------------------------------------------------
|
282
|
+
# images
|
283
|
+
|
284
|
+
describe 'images' do
|
285
|
+
it 'should handle a simple image' do
|
286
|
+
node = parse :block_paragraphs, <<EOS
|
287
|
+
Hello ![title](media/foo.png) friend.
|
288
|
+
EOS
|
289
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
290
|
+
<content>
|
291
|
+
<p>Hello <img src="media/foo.png" alt="title"/> friend.</p>
|
292
|
+
</content>
|
293
|
+
</paragraph>'
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'should work many on a line' do
|
297
|
+
node = parse :block_paragraphs, <<EOS
|
298
|
+
Hello ![title](media/foo.png) friend and ![](media/bar.png) a second.
|
299
|
+
EOS
|
300
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
301
|
+
<content>
|
302
|
+
<p>Hello <img src="media/foo.png" alt="title"/> friend and <img src="media/bar.png"/> a second.</p>
|
303
|
+
</content>
|
304
|
+
</paragraph>'
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
@@ -0,0 +1,576 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'builder'
|
4
|
+
|
5
|
+
require 'slaw'
|
6
|
+
|
7
|
+
describe Slaw::ActGenerator do
|
8
|
+
def parse(rule, s)
|
9
|
+
subject.builder.text_to_syntax_tree(s, {root: rule})
|
10
|
+
end
|
11
|
+
|
12
|
+
def should_parse(rule, s)
|
13
|
+
s << "\n" unless s.end_with?("\n")
|
14
|
+
tree = subject.builder.text_to_syntax_tree(s, {root: rule})
|
15
|
+
|
16
|
+
if not tree
|
17
|
+
raise Exception.new(subject.failure_reason || "Couldn't match to grammar") if tree.nil?
|
18
|
+
else
|
19
|
+
# count an assertion
|
20
|
+
tree.should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xml(node, *args)
|
25
|
+
b = ::Nokogiri::XML::Builder.new
|
26
|
+
node.to_xml(b, *args)
|
27
|
+
b.doc.root.to_xml(encoding: 'UTF-8')
|
28
|
+
end
|
29
|
+
|
30
|
+
#-------------------------------------------------------------------------------
|
31
|
+
# schedules
|
32
|
+
|
33
|
+
context 'schedules' do
|
34
|
+
it 'should handle a simple schedule' do
|
35
|
+
node = parse :schedules, <<EOS
|
36
|
+
Schedule
|
37
|
+
|
38
|
+
Subject to approval in terms of this By-Law, the erection:
|
39
|
+
1. Foo
|
40
|
+
2. Bar
|
41
|
+
EOS
|
42
|
+
s = to_xml(node)
|
43
|
+
today = Time.now.strftime('%Y-%m-%d')
|
44
|
+
s.should == '<component id="component-schedule">
|
45
|
+
<doc name="schedule">
|
46
|
+
<meta>
|
47
|
+
<identification source="#slaw">
|
48
|
+
<FRBRWork>
|
49
|
+
<FRBRthis value="/za/act/1980/01/schedule"/>
|
50
|
+
<FRBRuri value="/za/act/1980/01"/>
|
51
|
+
<FRBRalias value="Schedule"/>
|
52
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
53
|
+
<FRBRauthor href="#council"/>
|
54
|
+
<FRBRcountry value="za"/>
|
55
|
+
</FRBRWork>
|
56
|
+
<FRBRExpression>
|
57
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
58
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
59
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
60
|
+
<FRBRauthor href="#council"/>
|
61
|
+
<FRBRlanguage language="eng"/>
|
62
|
+
</FRBRExpression>
|
63
|
+
<FRBRManifestation>
|
64
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
65
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
66
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
67
|
+
<FRBRauthor href="#slaw"/>
|
68
|
+
</FRBRManifestation>
|
69
|
+
</identification>
|
70
|
+
</meta>
|
71
|
+
<mainBody>
|
72
|
+
<article id="schedule">
|
73
|
+
<paragraph id="schedule.paragraph-0">
|
74
|
+
<content>
|
75
|
+
<p>Subject to approval in terms of this By-Law, the erection:</p>
|
76
|
+
</content>
|
77
|
+
</paragraph>
|
78
|
+
<section id="section-1">
|
79
|
+
<num>1.</num>
|
80
|
+
<heading>Foo</heading>
|
81
|
+
</section>
|
82
|
+
<section id="section-2">
|
83
|
+
<num>2.</num>
|
84
|
+
<heading>Bar</heading>
|
85
|
+
</section>
|
86
|
+
</article>
|
87
|
+
</mainBody>
|
88
|
+
</doc>
|
89
|
+
</component>'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should serialise many schedules correctly' do
|
93
|
+
node = parse :schedules_container, <<EOS
|
94
|
+
Schedule "2"
|
95
|
+
A Title
|
96
|
+
1. Foo
|
97
|
+
2. Bar
|
98
|
+
Schedule 3
|
99
|
+
Another Title
|
100
|
+
Baz
|
101
|
+
Boom
|
102
|
+
EOS
|
103
|
+
|
104
|
+
s = to_xml(node)
|
105
|
+
today = Time.now.strftime('%Y-%m-%d')
|
106
|
+
s.should == <<EOS
|
107
|
+
<components>
|
108
|
+
<component id="component-schedule2">
|
109
|
+
<doc name="schedule2">
|
110
|
+
<meta>
|
111
|
+
<identification source="#slaw">
|
112
|
+
<FRBRWork>
|
113
|
+
<FRBRthis value="/za/act/1980/01/schedule2"/>
|
114
|
+
<FRBRuri value="/za/act/1980/01"/>
|
115
|
+
<FRBRalias value="Schedule 2"/>
|
116
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
117
|
+
<FRBRauthor href="#council"/>
|
118
|
+
<FRBRcountry value="za"/>
|
119
|
+
</FRBRWork>
|
120
|
+
<FRBRExpression>
|
121
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
|
122
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
123
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
124
|
+
<FRBRauthor href="#council"/>
|
125
|
+
<FRBRlanguage language="eng"/>
|
126
|
+
</FRBRExpression>
|
127
|
+
<FRBRManifestation>
|
128
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
|
129
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
130
|
+
<FRBRdate date="#{today}" name="Generation"/>
|
131
|
+
<FRBRauthor href="#slaw"/>
|
132
|
+
</FRBRManifestation>
|
133
|
+
</identification>
|
134
|
+
</meta>
|
135
|
+
<mainBody>
|
136
|
+
<article id="schedule2">
|
137
|
+
<heading>A Title</heading>
|
138
|
+
<section id="section-1">
|
139
|
+
<num>1.</num>
|
140
|
+
<heading>Foo</heading>
|
141
|
+
</section>
|
142
|
+
<section id="section-2">
|
143
|
+
<num>2.</num>
|
144
|
+
<heading>Bar</heading>
|
145
|
+
</section>
|
146
|
+
</article>
|
147
|
+
</mainBody>
|
148
|
+
</doc>
|
149
|
+
</component>
|
150
|
+
<component id="component-schedule3">
|
151
|
+
<doc name="schedule3">
|
152
|
+
<meta>
|
153
|
+
<identification source="#slaw">
|
154
|
+
<FRBRWork>
|
155
|
+
<FRBRthis value="/za/act/1980/01/schedule3"/>
|
156
|
+
<FRBRuri value="/za/act/1980/01"/>
|
157
|
+
<FRBRalias value="Schedule 3"/>
|
158
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
159
|
+
<FRBRauthor href="#council"/>
|
160
|
+
<FRBRcountry value="za"/>
|
161
|
+
</FRBRWork>
|
162
|
+
<FRBRExpression>
|
163
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule3"/>
|
164
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
165
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
166
|
+
<FRBRauthor href="#council"/>
|
167
|
+
<FRBRlanguage language="eng"/>
|
168
|
+
</FRBRExpression>
|
169
|
+
<FRBRManifestation>
|
170
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule3"/>
|
171
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
172
|
+
<FRBRdate date="#{today}" name="Generation"/>
|
173
|
+
<FRBRauthor href="#slaw"/>
|
174
|
+
</FRBRManifestation>
|
175
|
+
</identification>
|
176
|
+
</meta>
|
177
|
+
<mainBody>
|
178
|
+
<article id="schedule3">
|
179
|
+
<heading>Another Title</heading>
|
180
|
+
<paragraph id="schedule3.paragraph-0">
|
181
|
+
<content>
|
182
|
+
<p>Baz</p>
|
183
|
+
<p>Boom</p>
|
184
|
+
</content>
|
185
|
+
</paragraph>
|
186
|
+
</article>
|
187
|
+
</mainBody>
|
188
|
+
</doc>
|
189
|
+
</component>
|
190
|
+
</components>
|
191
|
+
EOS
|
192
|
+
.strip
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'should handle a schedule with a title and a number' do
|
197
|
+
node = parse :schedules, <<EOS
|
198
|
+
Schedule 1 - First Schedule
|
199
|
+
Schedule Heading
|
200
|
+
|
201
|
+
Subject to approval in terms of this By-Law, the erection:
|
202
|
+
1. Foo
|
203
|
+
2. Bar
|
204
|
+
EOS
|
205
|
+
s = to_xml(node)
|
206
|
+
today = Time.now.strftime('%Y-%m-%d')
|
207
|
+
s.should == '<component id="component-schedule1">
|
208
|
+
<doc name="schedule1">
|
209
|
+
<meta>
|
210
|
+
<identification source="#slaw">
|
211
|
+
<FRBRWork>
|
212
|
+
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
213
|
+
<FRBRuri value="/za/act/1980/01"/>
|
214
|
+
<FRBRalias value="First Schedule"/>
|
215
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
216
|
+
<FRBRauthor href="#council"/>
|
217
|
+
<FRBRcountry value="za"/>
|
218
|
+
</FRBRWork>
|
219
|
+
<FRBRExpression>
|
220
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
221
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
222
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
223
|
+
<FRBRauthor href="#council"/>
|
224
|
+
<FRBRlanguage language="eng"/>
|
225
|
+
</FRBRExpression>
|
226
|
+
<FRBRManifestation>
|
227
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
228
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
229
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
230
|
+
<FRBRauthor href="#slaw"/>
|
231
|
+
</FRBRManifestation>
|
232
|
+
</identification>
|
233
|
+
</meta>
|
234
|
+
<mainBody>
|
235
|
+
<article id="schedule1">
|
236
|
+
<heading>Schedule Heading</heading>
|
237
|
+
<paragraph id="schedule1.paragraph-0">
|
238
|
+
<content>
|
239
|
+
<p>Subject to approval in terms of this By-Law, the erection:</p>
|
240
|
+
</content>
|
241
|
+
</paragraph>
|
242
|
+
<section id="section-1">
|
243
|
+
<num>1.</num>
|
244
|
+
<heading>Foo</heading>
|
245
|
+
</section>
|
246
|
+
<section id="section-2">
|
247
|
+
<num>2.</num>
|
248
|
+
<heading>Bar</heading>
|
249
|
+
</section>
|
250
|
+
</article>
|
251
|
+
</mainBody>
|
252
|
+
</doc>
|
253
|
+
</component>'
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should handle a schedule with dot in the number' do
|
257
|
+
node = parse :schedules, <<EOS
|
258
|
+
Schedule 1. First Schedule
|
259
|
+
Schedule Heading
|
260
|
+
|
261
|
+
Subject to approval in terms of this By-Law, the erection:
|
262
|
+
1. Foo
|
263
|
+
2. Bar
|
264
|
+
EOS
|
265
|
+
s = to_xml(node)
|
266
|
+
today = Time.now.strftime('%Y-%m-%d')
|
267
|
+
s.should == '<component id="component-schedule1">
|
268
|
+
<doc name="schedule1">
|
269
|
+
<meta>
|
270
|
+
<identification source="#slaw">
|
271
|
+
<FRBRWork>
|
272
|
+
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
273
|
+
<FRBRuri value="/za/act/1980/01"/>
|
274
|
+
<FRBRalias value="First Schedule"/>
|
275
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
276
|
+
<FRBRauthor href="#council"/>
|
277
|
+
<FRBRcountry value="za"/>
|
278
|
+
</FRBRWork>
|
279
|
+
<FRBRExpression>
|
280
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
281
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
282
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
283
|
+
<FRBRauthor href="#council"/>
|
284
|
+
<FRBRlanguage language="eng"/>
|
285
|
+
</FRBRExpression>
|
286
|
+
<FRBRManifestation>
|
287
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
288
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
289
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
290
|
+
<FRBRauthor href="#slaw"/>
|
291
|
+
</FRBRManifestation>
|
292
|
+
</identification>
|
293
|
+
</meta>
|
294
|
+
<mainBody>
|
295
|
+
<article id="schedule1">
|
296
|
+
<heading>Schedule Heading</heading>
|
297
|
+
<paragraph id="schedule1.paragraph-0">
|
298
|
+
<content>
|
299
|
+
<p>Subject to approval in terms of this By-Law, the erection:</p>
|
300
|
+
</content>
|
301
|
+
</paragraph>
|
302
|
+
<section id="section-1">
|
303
|
+
<num>1.</num>
|
304
|
+
<heading>Foo</heading>
|
305
|
+
</section>
|
306
|
+
<section id="section-2">
|
307
|
+
<num>2.</num>
|
308
|
+
<heading>Bar</heading>
|
309
|
+
</section>
|
310
|
+
</article>
|
311
|
+
</mainBody>
|
312
|
+
</doc>
|
313
|
+
</component>'
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should handle a schedule with a title' do
|
317
|
+
node = parse :schedules, <<EOS
|
318
|
+
Schedule - First Schedule
|
319
|
+
|
320
|
+
Subject to approval in terms of this By-Law, the erection:
|
321
|
+
1. Foo
|
322
|
+
2. Bar
|
323
|
+
EOS
|
324
|
+
s = to_xml(node)
|
325
|
+
today = Time.now.strftime('%Y-%m-%d')
|
326
|
+
s.should == '<component id="component-firstschedule">
|
327
|
+
<doc name="firstschedule">
|
328
|
+
<meta>
|
329
|
+
<identification source="#slaw">
|
330
|
+
<FRBRWork>
|
331
|
+
<FRBRthis value="/za/act/1980/01/firstschedule"/>
|
332
|
+
<FRBRuri value="/za/act/1980/01"/>
|
333
|
+
<FRBRalias value="First Schedule"/>
|
334
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
335
|
+
<FRBRauthor href="#council"/>
|
336
|
+
<FRBRcountry value="za"/>
|
337
|
+
</FRBRWork>
|
338
|
+
<FRBRExpression>
|
339
|
+
<FRBRthis value="/za/act/1980/01/eng@/firstschedule"/>
|
340
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
341
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
342
|
+
<FRBRauthor href="#council"/>
|
343
|
+
<FRBRlanguage language="eng"/>
|
344
|
+
</FRBRExpression>
|
345
|
+
<FRBRManifestation>
|
346
|
+
<FRBRthis value="/za/act/1980/01/eng@/firstschedule"/>
|
347
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
348
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
349
|
+
<FRBRauthor href="#slaw"/>
|
350
|
+
</FRBRManifestation>
|
351
|
+
</identification>
|
352
|
+
</meta>
|
353
|
+
<mainBody>
|
354
|
+
<article id="firstschedule">
|
355
|
+
<paragraph id="firstschedule.paragraph-0">
|
356
|
+
<content>
|
357
|
+
<p>Subject to approval in terms of this By-Law, the erection:</p>
|
358
|
+
</content>
|
359
|
+
</paragraph>
|
360
|
+
<section id="section-1">
|
361
|
+
<num>1.</num>
|
362
|
+
<heading>Foo</heading>
|
363
|
+
</section>
|
364
|
+
<section id="section-2">
|
365
|
+
<num>2.</num>
|
366
|
+
<heading>Bar</heading>
|
367
|
+
</section>
|
368
|
+
</article>
|
369
|
+
</mainBody>
|
370
|
+
</doc>
|
371
|
+
</component>'
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should serialise a single schedule without a heading' do
|
375
|
+
node = parse :schedules, <<EOS
|
376
|
+
Schedule "1"
|
377
|
+
|
378
|
+
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.
|
379
|
+
1. Foo
|
380
|
+
2. Bar
|
381
|
+
EOS
|
382
|
+
|
383
|
+
s = to_xml(node)
|
384
|
+
today = Time.now.strftime('%Y-%m-%d')
|
385
|
+
s.should == <<EOS
|
386
|
+
<component id="component-schedule1">
|
387
|
+
<doc name="schedule1">
|
388
|
+
<meta>
|
389
|
+
<identification source="#slaw">
|
390
|
+
<FRBRWork>
|
391
|
+
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
392
|
+
<FRBRuri value="/za/act/1980/01"/>
|
393
|
+
<FRBRalias value="Schedule 1"/>
|
394
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
395
|
+
<FRBRauthor href="#council"/>
|
396
|
+
<FRBRcountry value="za"/>
|
397
|
+
</FRBRWork>
|
398
|
+
<FRBRExpression>
|
399
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
400
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
401
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
402
|
+
<FRBRauthor href="#council"/>
|
403
|
+
<FRBRlanguage language="eng"/>
|
404
|
+
</FRBRExpression>
|
405
|
+
<FRBRManifestation>
|
406
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
407
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
408
|
+
<FRBRdate date="#{today}" name="Generation"/>
|
409
|
+
<FRBRauthor href="#slaw"/>
|
410
|
+
</FRBRManifestation>
|
411
|
+
</identification>
|
412
|
+
</meta>
|
413
|
+
<mainBody>
|
414
|
+
<article id="schedule1">
|
415
|
+
<paragraph id="schedule1.paragraph-0">
|
416
|
+
<content>
|
417
|
+
<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>
|
418
|
+
</content>
|
419
|
+
</paragraph>
|
420
|
+
<section id="section-1">
|
421
|
+
<num>1.</num>
|
422
|
+
<heading>Foo</heading>
|
423
|
+
</section>
|
424
|
+
<section id="section-2">
|
425
|
+
<num>2.</num>
|
426
|
+
<heading>Bar</heading>
|
427
|
+
</section>
|
428
|
+
</article>
|
429
|
+
</mainBody>
|
430
|
+
</doc>
|
431
|
+
</component>
|
432
|
+
EOS
|
433
|
+
.strip
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'should support rich parts, chapters and sections in a schedule' do
|
437
|
+
node = parse :schedules, <<EOS
|
438
|
+
Schedule 1
|
439
|
+
Forms
|
440
|
+
|
441
|
+
Part I
|
442
|
+
Form of authentication statement
|
443
|
+
|
444
|
+
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.
|
445
|
+
|
446
|
+
Part II
|
447
|
+
Form of statement of the President’s assent.
|
448
|
+
|
449
|
+
I signify my assent to the bill and a whole bunch of other stuff.
|
450
|
+
EOS
|
451
|
+
|
452
|
+
s = to_xml(node)
|
453
|
+
today = Time.now.strftime('%Y-%m-%d')
|
454
|
+
s.should == <<EOS
|
455
|
+
<component id="component-schedule1">
|
456
|
+
<doc name="schedule1">
|
457
|
+
<meta>
|
458
|
+
<identification source="#slaw">
|
459
|
+
<FRBRWork>
|
460
|
+
<FRBRthis value="/za/act/1980/01/schedule1"/>
|
461
|
+
<FRBRuri value="/za/act/1980/01"/>
|
462
|
+
<FRBRalias value="Schedule 1"/>
|
463
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
464
|
+
<FRBRauthor href="#council"/>
|
465
|
+
<FRBRcountry value="za"/>
|
466
|
+
</FRBRWork>
|
467
|
+
<FRBRExpression>
|
468
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
469
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
470
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
471
|
+
<FRBRauthor href="#council"/>
|
472
|
+
<FRBRlanguage language="eng"/>
|
473
|
+
</FRBRExpression>
|
474
|
+
<FRBRManifestation>
|
475
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
|
476
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
477
|
+
<FRBRdate date="#{today}" name="Generation"/>
|
478
|
+
<FRBRauthor href="#slaw"/>
|
479
|
+
</FRBRManifestation>
|
480
|
+
</identification>
|
481
|
+
</meta>
|
482
|
+
<mainBody>
|
483
|
+
<article id="schedule1">
|
484
|
+
<heading>Forms</heading>
|
485
|
+
<part id="part-I">
|
486
|
+
<num>I</num>
|
487
|
+
<heading>Form of authentication statement</heading>
|
488
|
+
<paragraph id="part-I.paragraph-0">
|
489
|
+
<content>
|
490
|
+
<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>
|
491
|
+
</content>
|
492
|
+
</paragraph>
|
493
|
+
</part>
|
494
|
+
<part id="part-II">
|
495
|
+
<num>II</num>
|
496
|
+
<heading>Form of statement of the President’s assent.</heading>
|
497
|
+
<paragraph id="part-II.paragraph-0">
|
498
|
+
<content>
|
499
|
+
<p>I signify my assent to the bill and a whole bunch of other stuff.</p>
|
500
|
+
</content>
|
501
|
+
</paragraph>
|
502
|
+
</part>
|
503
|
+
</article>
|
504
|
+
</mainBody>
|
505
|
+
</doc>
|
506
|
+
</component>
|
507
|
+
EOS
|
508
|
+
.strip
|
509
|
+
end
|
510
|
+
|
511
|
+
it 'should not get confused by schedule headings in TOC' do
|
512
|
+
parse :schedules_container, <<EOS
|
513
|
+
Schedule 1. Summoning and procedure of Joint Sittings of Senate and House of Assembly.
|
514
|
+
Schedule 2. Oaths.
|
515
|
+
Schedule 3. Matters which shall continue to be regulated by Swazi Law and Custom.
|
516
|
+
Schedule 4. Specially entrenched provisions and entrenched provisions.
|
517
|
+
EOS
|
518
|
+
end
|
519
|
+
|
520
|
+
it 'should handle escaped schedules' do
|
521
|
+
node = parse :schedules, <<EOS
|
522
|
+
Schedule
|
523
|
+
|
524
|
+
Subject to approval in terms of this By-Law.
|
525
|
+
|
526
|
+
\\Schedule another
|
527
|
+
|
528
|
+
More stuff
|
529
|
+
EOS
|
530
|
+
s = to_xml(node)
|
531
|
+
today = Time.now.strftime('%Y-%m-%d')
|
532
|
+
s.should == '<component id="component-schedule">
|
533
|
+
<doc name="schedule">
|
534
|
+
<meta>
|
535
|
+
<identification source="#slaw">
|
536
|
+
<FRBRWork>
|
537
|
+
<FRBRthis value="/za/act/1980/01/schedule"/>
|
538
|
+
<FRBRuri value="/za/act/1980/01"/>
|
539
|
+
<FRBRalias value="Schedule"/>
|
540
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
541
|
+
<FRBRauthor href="#council"/>
|
542
|
+
<FRBRcountry value="za"/>
|
543
|
+
</FRBRWork>
|
544
|
+
<FRBRExpression>
|
545
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
546
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
547
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
548
|
+
<FRBRauthor href="#council"/>
|
549
|
+
<FRBRlanguage language="eng"/>
|
550
|
+
</FRBRExpression>
|
551
|
+
<FRBRManifestation>
|
552
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
553
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
554
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
555
|
+
<FRBRauthor href="#slaw"/>
|
556
|
+
</FRBRManifestation>
|
557
|
+
</identification>
|
558
|
+
</meta>
|
559
|
+
<mainBody>
|
560
|
+
<article id="schedule">
|
561
|
+
<paragraph id="schedule.paragraph-0">
|
562
|
+
<content>
|
563
|
+
<p>Subject to approval in terms of this By-Law.</p>
|
564
|
+
<p>Schedule another</p>
|
565
|
+
<p>More stuff</p>
|
566
|
+
</content>
|
567
|
+
</paragraph>
|
568
|
+
</article>
|
569
|
+
</mainBody>
|
570
|
+
</doc>
|
571
|
+
</component>'
|
572
|
+
end
|
573
|
+
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
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: 0.
|
4
|
+
version: 0.14.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: 2017-
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -216,7 +216,9 @@ files:
|
|
216
216
|
- spec/parse/cleanser_spec.rb
|
217
217
|
- spec/spec_helper.rb
|
218
218
|
- spec/xml_helpers.rb
|
219
|
-
- spec/za/
|
219
|
+
- spec/za/act_block_spec.rb
|
220
|
+
- spec/za/act_inline_spec.rb
|
221
|
+
- spec/za/act_schedules_spec.rb
|
220
222
|
homepage: ''
|
221
223
|
licenses:
|
222
224
|
- MIT
|
@@ -237,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
239
|
version: '0'
|
238
240
|
requirements: []
|
239
241
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
242
|
+
rubygems_version: 2.6.12
|
241
243
|
signing_key:
|
242
244
|
specification_version: 4
|
243
245
|
summary: A lightweight library for using Akoma Ntoso acts in Ruby.
|
@@ -251,4 +253,6 @@ test_files:
|
|
251
253
|
- spec/parse/cleanser_spec.rb
|
252
254
|
- spec/spec_helper.rb
|
253
255
|
- spec/xml_helpers.rb
|
254
|
-
- spec/za/
|
256
|
+
- spec/za/act_block_spec.rb
|
257
|
+
- spec/za/act_inline_spec.rb
|
258
|
+
- spec/za/act_schedules_spec.rb
|