slaw 0.11.0 → 0.12.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 +4 -4
- data/README.md +5 -0
- data/lib/slaw/version.rb +1 -1
- data/lib/slaw/za/act.treetop +9 -2
- data/lib/slaw/za/act_nodes.rb +11 -12
- data/lib/slaw/za/act_text.xsl +8 -0
- data/spec/generator_spec.rb +19 -0
- data/spec/za/act_spec.rb +126 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657367d2055974b4c1e986050ef45bf27e625bec
|
4
|
+
data.tar.gz: 5b90b89cbc9bd4a3a546d4b2b7cd80e85ff9bc46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4f9f19d7f74e1721e5ef43daf946120ac0b518155d7167ef5d0677d249bc1cd47efb3e542d4288837c51561675850beb0591291dea9baa858827f3aedee7bd0
|
7
|
+
data.tar.gz: ec3b48956ed66ed38b309e6b60e7108d5bd89e90b018ca3f3472806de4ee1f2a4d636149922749b89e6503e9f5ae253c6dcab1765eaeec903a4ad164f01e95bf
|
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.12.0
|
222
|
+
|
223
|
+
* Support links/references using Markdown-like \[text](href) syntax.
|
224
|
+
* FIX allow remarks in blocklist items
|
225
|
+
|
221
226
|
### 0.11.0
|
222
227
|
|
223
228
|
* Support newlines in table cells as EOL (or BR in HTML)
|
data/lib/slaw/version.rb
CHANGED
data/lib/slaw/za/act.treetop
CHANGED
@@ -150,7 +150,7 @@ module Slaw
|
|
150
150
|
end
|
151
151
|
|
152
152
|
rule blocklist_item
|
153
|
-
space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix
|
153
|
+
space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix clauses eol)? eol?
|
154
154
|
<BlocklistItem>
|
155
155
|
end
|
156
156
|
|
@@ -192,7 +192,7 @@ module Slaw
|
|
192
192
|
|
193
193
|
# one or more words, allowing inline elements
|
194
194
|
rule clauses
|
195
|
-
(
|
195
|
+
(remark / ref / [^\n])*
|
196
196
|
<Clauses>
|
197
197
|
end
|
198
198
|
|
@@ -201,6 +201,13 @@ module Slaw
|
|
201
201
|
<Remark>
|
202
202
|
end
|
203
203
|
|
204
|
+
rule ref
|
205
|
+
# links like markdown
|
206
|
+
# eg. [link text](link url)
|
207
|
+
'[' content:(!'](' [^\n])+ '](' href:([^)\n]+) ')'
|
208
|
+
<Ref>
|
209
|
+
end
|
210
|
+
|
204
211
|
##########
|
205
212
|
# prefixes
|
206
213
|
|
data/lib/slaw/za/act_nodes.rb
CHANGED
@@ -289,12 +289,10 @@ module Slaw
|
|
289
289
|
class Clauses < Treetop::Runtime::SyntaxNode
|
290
290
|
def to_xml(b, idprefix=nil)
|
291
291
|
for e in elements
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
b << e2.text_value
|
297
|
-
end
|
292
|
+
if e.respond_to? :to_xml
|
293
|
+
e.to_xml(b, idprefix)
|
294
|
+
else
|
295
|
+
b << e.text_value
|
298
296
|
end
|
299
297
|
end
|
300
298
|
end
|
@@ -306,6 +304,12 @@ module Slaw
|
|
306
304
|
end
|
307
305
|
end
|
308
306
|
|
307
|
+
class Ref < Treetop::Runtime::SyntaxNode
|
308
|
+
def to_xml(b, idprefix)
|
309
|
+
b.ref(content.text_value, href: href.text_value)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
309
313
|
class Blocklist < Treetop::Runtime::SyntaxNode
|
310
314
|
# Render a block list to xml. If a block is given,
|
311
315
|
# yield to it a builder to insert a listIntroduction node
|
@@ -326,15 +330,10 @@ module Slaw
|
|
326
330
|
blocklist_item_prefix.text_value
|
327
331
|
end
|
328
332
|
|
329
|
-
def content
|
330
|
-
# TODO this really seems a bit odd
|
331
|
-
item_content.content.text_value if respond_to? :item_content and item_content.respond_to? :content
|
332
|
-
end
|
333
|
-
|
334
333
|
def to_xml(b, idprefix)
|
335
334
|
b.item(id: idprefix + num.gsub(/[()]/, '')) { |b|
|
336
335
|
b.num(num)
|
337
|
-
b.p(
|
336
|
+
b.p { |b| item_content.clauses.to_xml(b, idprefix) } if respond_to? :item_content and item_content.respond_to? :clauses
|
338
337
|
}
|
339
338
|
end
|
340
339
|
end
|
data/lib/slaw/za/act_text.xsl
CHANGED
@@ -230,6 +230,14 @@
|
|
230
230
|
<xsl:text>]</xsl:text>
|
231
231
|
</xsl:template>
|
232
232
|
|
233
|
+
<xsl:template match="a:ref">
|
234
|
+
<xsl:text>[</xsl:text>
|
235
|
+
<xsl:apply-templates />
|
236
|
+
<xsl:text>](</xsl:text>
|
237
|
+
<xsl:value-of select="@href" />
|
238
|
+
<xsl:text>)</xsl:text>
|
239
|
+
</xsl:template>
|
240
|
+
|
233
241
|
<xsl:template match="a:eol">
|
234
242
|
<xsl:text>
|
235
243
|
</xsl:text>
|
data/spec/generator_spec.rb
CHANGED
@@ -166,6 +166,25 @@ XML
|
|
166
166
|
|
167
167
|
Section 1 [[ foo ]]
|
168
168
|
|
169
|
+
'
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should unparse refs correctly' do
|
173
|
+
doc = xml2doc(section(<<XML
|
174
|
+
<num>1.</num>
|
175
|
+
<paragraph id="section-19.paragraph-0">
|
176
|
+
<content>
|
177
|
+
<p>Hello <ref href="/za/act/123">there</ref> friend.</p>
|
178
|
+
</content>
|
179
|
+
</paragraph>
|
180
|
+
XML
|
181
|
+
))
|
182
|
+
|
183
|
+
text = subject.text_from_act(doc)
|
184
|
+
text.should == '1.
|
185
|
+
|
186
|
+
Hello [there](/za/act/123) friend.
|
187
|
+
|
169
188
|
'
|
170
189
|
end
|
171
190
|
|
data/spec/za/act_spec.rb
CHANGED
@@ -795,6 +795,37 @@ EOS
|
|
795
795
|
</section>'
|
796
796
|
end
|
797
797
|
|
798
|
+
it 'should handle a remark in a blocklist' do
|
799
|
+
node = parse :section, <<EOS
|
800
|
+
1. Section title
|
801
|
+
Some text is a long line.
|
802
|
+
|
803
|
+
(1) something
|
804
|
+
(a) with a remark [[Section 1 amended by Act 23 of 2004]]
|
805
|
+
EOS
|
806
|
+
to_xml(node).should == '<section id="section-1">
|
807
|
+
<num>1.</num>
|
808
|
+
<heading>Section title</heading>
|
809
|
+
<paragraph id="section-1.paragraph-0">
|
810
|
+
<content>
|
811
|
+
<p>Some text is a long line.</p>
|
812
|
+
</content>
|
813
|
+
</paragraph>
|
814
|
+
<subsection id="section-1.1">
|
815
|
+
<num>(1)</num>
|
816
|
+
<content>
|
817
|
+
<p>something</p>
|
818
|
+
<blockList id="section-1.1.list1">
|
819
|
+
<item id="section-1.1.list1.a">
|
820
|
+
<num>(a)</num>
|
821
|
+
<p>with a remark <remark status="editorial">[Section 1 amended by Act 23 of 2004]</remark></p>
|
822
|
+
</item>
|
823
|
+
</blockList>
|
824
|
+
</content>
|
825
|
+
</subsection>
|
826
|
+
</section>'
|
827
|
+
end
|
828
|
+
|
798
829
|
it 'should handle a remark in a schedule' do
|
799
830
|
node = parse :schedule, <<EOS
|
800
831
|
Schedule 1
|
@@ -851,6 +882,98 @@ EOS
|
|
851
882
|
end
|
852
883
|
end
|
853
884
|
|
885
|
+
#-------------------------------------------------------------------------------
|
886
|
+
# Refs
|
887
|
+
|
888
|
+
describe 'ref' do
|
889
|
+
it 'should handle a plain ref' do
|
890
|
+
node = parse :block_paragraphs, <<EOS
|
891
|
+
Hello [there](/za/act/123) friend.
|
892
|
+
EOS
|
893
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
894
|
+
<content>
|
895
|
+
<p>Hello <ref href="/za/act/123">there</ref> friend.</p>
|
896
|
+
</content>
|
897
|
+
</paragraph>'
|
898
|
+
end
|
899
|
+
|
900
|
+
it 'should work many on a line' do
|
901
|
+
node = parse :block_paragraphs, <<EOS
|
902
|
+
Hello [there](/za/act/123) friend [and](http://foo.bar.com/with space) you too.
|
903
|
+
EOS
|
904
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
905
|
+
<content>
|
906
|
+
<p>Hello <ref href="/za/act/123">there</ref> friend <ref href="http://foo.bar.com/with space">and</ref> you too.</p>
|
907
|
+
</content>
|
908
|
+
</paragraph>'
|
909
|
+
end
|
910
|
+
|
911
|
+
it 'should handle brackets' do
|
912
|
+
node = parse :block_paragraphs, <<EOS
|
913
|
+
Hello ([there](/za/act/123)).
|
914
|
+
EOS
|
915
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
916
|
+
<content>
|
917
|
+
<p>Hello (<ref href="/za/act/123">there</ref>).</p>
|
918
|
+
</content>
|
919
|
+
</paragraph>'
|
920
|
+
end
|
921
|
+
|
922
|
+
it 'should handle many clauses on a line' do
|
923
|
+
node = parse :block_paragraphs, <<EOS
|
924
|
+
Hello [there](/za/act/123)[[remark one]] my[friend](/za) [[remark 2]][end](/foo).
|
925
|
+
EOS
|
926
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
927
|
+
<content>
|
928
|
+
<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>
|
929
|
+
</content>
|
930
|
+
</paragraph>'
|
931
|
+
end
|
932
|
+
|
933
|
+
it 'text should not cross end of line' do
|
934
|
+
node = parse :block_paragraphs, <<EOS
|
935
|
+
Hello [there
|
936
|
+
|
937
|
+
my](/za/act/123) friend.
|
938
|
+
EOS
|
939
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
940
|
+
<content>
|
941
|
+
<p>Hello [there</p>
|
942
|
+
<p>my](/za/act/123) friend.</p>
|
943
|
+
</content>
|
944
|
+
</paragraph>'
|
945
|
+
end
|
946
|
+
|
947
|
+
it 'href should not cross end of line' do
|
948
|
+
node = parse :block_paragraphs, <<EOS
|
949
|
+
Hello [there](/za/act
|
950
|
+
/123) friend.
|
951
|
+
EOS
|
952
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
953
|
+
<content>
|
954
|
+
<p>Hello [there](/za/act</p>
|
955
|
+
<p>/123) friend.</p>
|
956
|
+
</content>
|
957
|
+
</paragraph>'
|
958
|
+
end
|
959
|
+
|
960
|
+
it 'href should handle refs in a list' do
|
961
|
+
node = parse :block_paragraphs, <<EOS
|
962
|
+
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;
|
963
|
+
EOS
|
964
|
+
to_xml(node, "").should == '<paragraph id="paragraph-0">
|
965
|
+
<content>
|
966
|
+
<blockList id="paragraph-0.list0">
|
967
|
+
<item id="paragraph-0.list0.2.18.1">
|
968
|
+
<num>2.18.1</num>
|
969
|
+
<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>
|
970
|
+
</item>
|
971
|
+
</blockList>
|
972
|
+
</content>
|
973
|
+
</paragraph>'
|
974
|
+
end
|
975
|
+
end
|
976
|
+
|
854
977
|
#-------------------------------------------------------------------------------
|
855
978
|
# Numbered statements
|
856
979
|
|
@@ -2025,12 +2148,12 @@ EOS
|
|
2025
2148
|
it 'should handle a clause with a remark' do
|
2026
2149
|
node = parse :clauses, "simple [[remark]]. text"
|
2027
2150
|
node.text_value.should == "simple [[remark]]. text"
|
2028
|
-
node.elements[
|
2151
|
+
node.elements[7].is_a?(Slaw::ZA::Act::Remark).should be_true
|
2029
2152
|
|
2030
2153
|
node = parse :clauses, "simple [[remark]][[another]] text"
|
2031
2154
|
node.text_value.should == "simple [[remark]][[another]] text"
|
2032
|
-
node.elements[
|
2033
|
-
node.elements[
|
2155
|
+
node.elements[7].is_a?(Slaw::ZA::Act::Remark).should be_true
|
2156
|
+
node.elements[7].is_a?(Slaw::ZA::Act::Remark).should be_true
|
2034
2157
|
end
|
2035
2158
|
end
|
2036
2159
|
end
|
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.12.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-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|