slaw 0.9.0 → 0.10.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 +7 -0
- data/bin/slaw +8 -0
- data/lib/slaw/generator.rb +8 -0
- data/lib/slaw/version.rb +1 -1
- data/lib/slaw/za/act.treetop +6 -3
- data/lib/slaw/za/act_text.xsl +225 -0
- data/slaw.gemspec +1 -1
- data/spec/generator_spec.rb +55 -0
- data/spec/za/act_spec.rb +218 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93a820ba2ec4e18e12c5a9935a954ad314dfc614
|
4
|
+
data.tar.gz: 6bed26afa25207e66575795a1f94b8504e040009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff709e7d9931573ae661cad219350917bb352120aa7507d18589df6c47f2bd5e1e2066cc924393e1a98f2a40884363603b8e0e73ef82a125cb942af238e4860
|
7
|
+
data.tar.gz: 0d8f14587a3d706cdf32450dafc0a28e0a28b6bf9f6ca968a64f0c044f0072a21d36e62061457011a5b68ca42b14be6863bf1b05a7a1e6b48b01c1684acc3749
|
data/README.md
CHANGED
@@ -157,6 +157,8 @@ in a document to indicate different levels of nesting.
|
|
157
157
|
|
158
158
|
During post-processing it works out how to nest these appropriately.
|
159
159
|
|
160
|
+
Special words, such as ``part`` and ``chapter`` are ignored if the line starts with a backslash ``\``.
|
161
|
+
|
160
162
|
For more information see the South African by-law grammar at
|
161
163
|
[lib/slaw/za/bylaw.treetop](lib/slaw/za/bylaw.treetop) and the list nesting
|
162
164
|
at [lib/slaw/parse/blocklists.rb](lib/slaw/parse/blocklists.rb).
|
@@ -216,6 +218,11 @@ Akoma Ntoso `component` elements at the end of the XML document, with a name of
|
|
216
218
|
|
217
219
|
## Changelog
|
218
220
|
|
221
|
+
### 0.10.0
|
222
|
+
|
223
|
+
* New command `unparse FILE` which transforms an Akoma Ntoso XML document into plain text, suitable for re-parsing
|
224
|
+
* Support escaping special words with a backslash
|
225
|
+
|
219
226
|
### 0.9.0
|
220
227
|
|
221
228
|
* This release makes reasonably significant changes to generated XML, particularly
|
data/bin/slaw
CHANGED
@@ -102,6 +102,14 @@ class SlawCLI < Thor
|
|
102
102
|
puts builder.to_xml(doc)
|
103
103
|
end
|
104
104
|
|
105
|
+
desc "unparse FILE", "Unparse FILE from Akoma Ntoso XML back into text suitable for re-parsing"
|
106
|
+
def unparse(name)
|
107
|
+
generator = Slaw::ActGenerator.new
|
108
|
+
|
109
|
+
doc = File.open(name, 'r') { |f| doc = generator.builder.parse_xml(f.read) }
|
110
|
+
puts generator.text_from_act(doc)
|
111
|
+
end
|
112
|
+
|
105
113
|
map %w(--version) => :__print_version
|
106
114
|
desc "--version", "Print slaw version info"
|
107
115
|
def __print_version
|
data/lib/slaw/generator.rb
CHANGED
@@ -62,5 +62,13 @@ module Slaw
|
|
62
62
|
|
63
63
|
before > after * 1.25
|
64
64
|
end
|
65
|
+
|
66
|
+
# Transform an Akoma Ntoso XML document back into a plain-text version
|
67
|
+
# suitable for re-parsing back into XML with no loss of structure.
|
68
|
+
def text_from_act(doc)
|
69
|
+
here = File.dirname(__FILE__)
|
70
|
+
xslt = Nokogiri::XSLT(File.read(File.join([here, 'za/act_text.xsl'])))
|
71
|
+
xslt.transform(doc).child.to_xml
|
72
|
+
end
|
65
73
|
end
|
66
74
|
end
|
data/lib/slaw/version.rb
CHANGED
data/lib/slaw/za/act.treetop
CHANGED
@@ -31,7 +31,7 @@ module Slaw
|
|
31
31
|
end
|
32
32
|
|
33
33
|
rule body
|
34
|
-
children:(chapter / part / section / subsection / block_paragraphs
|
34
|
+
children:(chapter / part / section / subsection / block_paragraphs)+ <Body>
|
35
35
|
end
|
36
36
|
|
37
37
|
rule chapter
|
@@ -173,14 +173,17 @@ module Slaw
|
|
173
173
|
|
174
174
|
##########
|
175
175
|
# statements - single lines of content
|
176
|
+
#
|
177
|
+
# If a statement starts with a backslash, it's considered to have escaped the subsequent word,
|
178
|
+
# and is ignored. This allows escaping of section headings, etc.
|
176
179
|
|
177
180
|
rule naked_statement
|
178
|
-
space? !(chapter_heading / part_heading / section_title / schedule_title / subsection_prefix) clauses eol
|
181
|
+
space? !(chapter_heading / part_heading / section_title / schedule_title / subsection_prefix) '\\'? clauses eol
|
179
182
|
<NakedStatement>
|
180
183
|
end
|
181
184
|
|
182
185
|
rule pre_body_statement
|
183
|
-
space? !(chapter_heading / part_heading / section_title / schedule_title) clauses eol
|
186
|
+
space? !(chapter_heading / part_heading / section_title / schedule_title) '\\'? clauses eol
|
184
187
|
<NakedStatement>
|
185
188
|
end
|
186
189
|
|
@@ -0,0 +1,225 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
3
|
+
xmlns:a="http://www.akomantoso.org/2.0"
|
4
|
+
exclude-result-prefixes="a">
|
5
|
+
|
6
|
+
<xsl:output method="text" indent="no" omit-xml-declaration="yes" />
|
7
|
+
<xsl:strip-space elements="*"/>
|
8
|
+
|
9
|
+
<xsl:template match="a:act">
|
10
|
+
<xsl:apply-templates select="a:coverPage" />
|
11
|
+
<xsl:apply-templates select="a:preface" />
|
12
|
+
<xsl:apply-templates select="a:preamble" />
|
13
|
+
<xsl:apply-templates select="a:body" />
|
14
|
+
<xsl:apply-templates select="a:conclusions" />
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
<xsl:template match="a:preface">
|
18
|
+
<xsl:text>PREFACE</xsl:text>
|
19
|
+
<xsl:text>
|
20
|
+
|
21
|
+
</xsl:text>
|
22
|
+
<xsl:apply-templates />
|
23
|
+
</xsl:template>
|
24
|
+
|
25
|
+
<xsl:template match="a:preamble">
|
26
|
+
<xsl:text>PREAMBLE</xsl:text>
|
27
|
+
<xsl:text>
|
28
|
+
|
29
|
+
</xsl:text>
|
30
|
+
<xsl:apply-templates />
|
31
|
+
</xsl:template>
|
32
|
+
|
33
|
+
<xsl:template match="a:part">
|
34
|
+
<xsl:text>Part </xsl:text>
|
35
|
+
<xsl:value-of select="./a:num" />
|
36
|
+
<xsl:text> - </xsl:text>
|
37
|
+
<xsl:value-of select="./a:heading" />
|
38
|
+
<xsl:text>
|
39
|
+
|
40
|
+
</xsl:text>
|
41
|
+
<xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
|
42
|
+
</xsl:template>
|
43
|
+
|
44
|
+
<xsl:template match="a:chapter">
|
45
|
+
<xsl:text>Chapter </xsl:text>
|
46
|
+
<xsl:value-of select="./a:num" />
|
47
|
+
<xsl:text> - </xsl:text>
|
48
|
+
<xsl:value-of select="./a:heading" />
|
49
|
+
<xsl:text>
|
50
|
+
|
51
|
+
</xsl:text>
|
52
|
+
<xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
|
53
|
+
</xsl:template>
|
54
|
+
|
55
|
+
<xsl:template match="a:section">
|
56
|
+
<xsl:value-of select="a:num" />
|
57
|
+
<xsl:text> </xsl:text>
|
58
|
+
<xsl:if test="a:heading != ''">
|
59
|
+
<xsl:value-of select="a:heading" />
|
60
|
+
</xsl:if>
|
61
|
+
<xsl:text>
|
62
|
+
|
63
|
+
</xsl:text>
|
64
|
+
<xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
|
65
|
+
</xsl:template>
|
66
|
+
|
67
|
+
<xsl:template match="a:subsection">
|
68
|
+
<xsl:if test="a:num != ''">
|
69
|
+
<xsl:value-of select="a:num" />
|
70
|
+
<xsl:text> </xsl:text>
|
71
|
+
</xsl:if>
|
72
|
+
<xsl:apply-templates select="./*[not(self::a:num) and not(self::a:heading)]" />
|
73
|
+
</xsl:template>
|
74
|
+
|
75
|
+
<!-- these are block elements and have a newline at the end -->
|
76
|
+
<xsl:template match="a:heading">
|
77
|
+
<xsl:apply-templates />
|
78
|
+
<xsl:text>
|
79
|
+
|
80
|
+
</xsl:text>
|
81
|
+
</xsl:template>
|
82
|
+
|
83
|
+
<xsl:template match="a:p">
|
84
|
+
<xsl:variable name="prefix" select="translate(substring(., 1, 10), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
|
85
|
+
<xsl:variable name="numprefix" select="translate(substring(., 1, 3), '1234567890', 'NNNNNNNNNN')" />
|
86
|
+
|
87
|
+
<!-- p tags must escape initial content that looks like a block element marker -->
|
88
|
+
<xsl:if test="starts-with($prefix, 'BODY') or
|
89
|
+
starts-with($prefix, 'CHAPTER') or
|
90
|
+
starts-with($prefix, 'PART') or
|
91
|
+
starts-with($prefix, 'PREAMBLE') or
|
92
|
+
starts-with($prefix, 'PREFACE') or
|
93
|
+
starts-with($prefix, 'SCHEDULE') or
|
94
|
+
starts-with($prefix, '{|') or
|
95
|
+
starts-with($numprefix, '(') or
|
96
|
+
starts-with($numprefix, 'N.')">
|
97
|
+
<xsl:text>\</xsl:text>
|
98
|
+
</xsl:if>
|
99
|
+
<xsl:value-of select="."/>
|
100
|
+
<!-- p tags must end with a newline -->
|
101
|
+
<xsl:text>
|
102
|
+
|
103
|
+
</xsl:text>
|
104
|
+
</xsl:template>
|
105
|
+
|
106
|
+
<xsl:template match="a:blockList">
|
107
|
+
<xsl:if test="a:listIntroduction != ''">
|
108
|
+
<xsl:apply-templates select="a:listIntroduction" />
|
109
|
+
<xsl:text>
|
110
|
+
|
111
|
+
</xsl:text>
|
112
|
+
</xsl:if>
|
113
|
+
<xsl:apply-templates select="./*[not(self::a:listIntroduction)]" />
|
114
|
+
</xsl:template>
|
115
|
+
|
116
|
+
<xsl:template match="a:item">
|
117
|
+
<xsl:value-of select="./a:num" />
|
118
|
+
<xsl:text> </xsl:text>
|
119
|
+
<xsl:apply-templates select="./*[not(self::a:num)]" />
|
120
|
+
</xsl:template>
|
121
|
+
|
122
|
+
<xsl:template match="a:list">
|
123
|
+
<xsl:if test="a:intro != ''">
|
124
|
+
<xsl:value-of select="a:intro" />
|
125
|
+
<xsl:text>
|
126
|
+
|
127
|
+
</xsl:text>
|
128
|
+
</xsl:if>
|
129
|
+
<xsl:apply-templates select="./*[not(self::a:intro)]" />
|
130
|
+
</xsl:template>
|
131
|
+
|
132
|
+
<!-- components/schedules -->
|
133
|
+
<xsl:template match="a:doc">
|
134
|
+
<xsl:text>Schedule - </xsl:text>
|
135
|
+
<xsl:value-of select="a:meta/a:identification/a:FRBRWork/a:FRBRalias/@value" />
|
136
|
+
|
137
|
+
<xsl:if test="a:mainBody/a:article/a:heading">
|
138
|
+
<xsl:text>
|
139
|
+
</xsl:text>
|
140
|
+
<xsl:value-of select="a:mainBody/a:article/a:heading" />
|
141
|
+
</xsl:if>
|
142
|
+
|
143
|
+
<xsl:text>
|
144
|
+
|
145
|
+
</xsl:text>
|
146
|
+
<xsl:apply-templates select="a:mainBody" />
|
147
|
+
</xsl:template>
|
148
|
+
|
149
|
+
<xsl:template match="a:mainBody/a:article/a:heading">
|
150
|
+
<!-- no-op, this is handled by the schedules template above -->
|
151
|
+
</xsl:template>
|
152
|
+
|
153
|
+
<!-- tables -->
|
154
|
+
<xsl:template match="a:table">
|
155
|
+
<xsl:text>{| </xsl:text>
|
156
|
+
|
157
|
+
<!-- attributes -->
|
158
|
+
<xsl:for-each select="@*[local-name()!='id']">
|
159
|
+
<xsl:value-of select="local-name(.)" />
|
160
|
+
<xsl:text>="</xsl:text>
|
161
|
+
<xsl:value-of select="." />
|
162
|
+
<xsl:text>" </xsl:text>
|
163
|
+
</xsl:for-each>
|
164
|
+
<xsl:text>
|
165
|
+
|-</xsl:text>
|
166
|
+
|
167
|
+
<xsl:apply-templates />
|
168
|
+
<xsl:text>
|
169
|
+
|}
|
170
|
+
|
171
|
+
</xsl:text>
|
172
|
+
</xsl:template>
|
173
|
+
|
174
|
+
<xsl:template match="a:tr">
|
175
|
+
<xsl:apply-templates />
|
176
|
+
<xsl:text>
|
177
|
+
|-</xsl:text>
|
178
|
+
</xsl:template>
|
179
|
+
|
180
|
+
<xsl:template match="a:th|a:td">
|
181
|
+
<xsl:choose>
|
182
|
+
<xsl:when test="local-name(.) = 'th'">
|
183
|
+
<xsl:text>
|
184
|
+
! </xsl:text>
|
185
|
+
</xsl:when>
|
186
|
+
<xsl:when test="local-name(.) = 'td'">
|
187
|
+
<xsl:text>
|
188
|
+
| </xsl:text>
|
189
|
+
</xsl:when>
|
190
|
+
</xsl:choose>
|
191
|
+
|
192
|
+
<!-- attributes -->
|
193
|
+
<xsl:if test="@*">
|
194
|
+
<xsl:for-each select="@*">
|
195
|
+
<xsl:value-of select="local-name(.)" />
|
196
|
+
<xsl:text>="</xsl:text>
|
197
|
+
<xsl:value-of select="." />
|
198
|
+
<xsl:text>" </xsl:text>
|
199
|
+
</xsl:for-each>
|
200
|
+
<xsl:text>| </xsl:text>
|
201
|
+
</xsl:if>
|
202
|
+
|
203
|
+
<xsl:apply-templates />
|
204
|
+
</xsl:template>
|
205
|
+
|
206
|
+
<!-- don't end p tags with newlines in tables -->
|
207
|
+
<xsl:template match="a:table//a:p">
|
208
|
+
<xsl:apply-templates />
|
209
|
+
</xsl:template>
|
210
|
+
|
211
|
+
<!-- END tables -->
|
212
|
+
|
213
|
+
<xsl:template match="a:remark">
|
214
|
+
<xsl:text>[</xsl:text>
|
215
|
+
<xsl:apply-templates />
|
216
|
+
<xsl:text>]</xsl:text>
|
217
|
+
</xsl:template>
|
218
|
+
|
219
|
+
|
220
|
+
<!-- for most nodes, just dump their text content -->
|
221
|
+
<xsl:template match="*">
|
222
|
+
<xsl:text/><xsl:apply-templates /><xsl:text/>
|
223
|
+
</xsl:template>
|
224
|
+
|
225
|
+
</xsl:stylesheet>
|
data/slaw.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3.1"
|
23
23
|
spec.add_development_dependency "rspec", "~> 2.14.1"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "nokogiri", "~> 1.6.0"
|
data/spec/generator_spec.rb
CHANGED
@@ -38,4 +38,59 @@ Some content.
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe 'unparse' do
|
43
|
+
it 'should escape keywards when unparsing' do
|
44
|
+
doc = xml2doc(section(<<XML
|
45
|
+
<num>1.</num>
|
46
|
+
<heading>Section</heading>
|
47
|
+
<paragraph id="section-1.paragraph-0">
|
48
|
+
<content>
|
49
|
+
<p>Chapter 2 ignored</p>
|
50
|
+
<p>Part 2 ignored</p>
|
51
|
+
<p>Schedule 2 ignored</p>
|
52
|
+
<p>BODY ignored</p>
|
53
|
+
<p>PREAMBLE ignored</p>
|
54
|
+
<p>PREFACE ignored</p>
|
55
|
+
<p>2. ignored</p>
|
56
|
+
<p>2.1 ignored</p>
|
57
|
+
<p>(2) ignored</p>
|
58
|
+
<p>(a) ignored</p>
|
59
|
+
<p>(2a) ignored</p>
|
60
|
+
<p>{| ignored</p>
|
61
|
+
</content>
|
62
|
+
</paragraph>
|
63
|
+
XML
|
64
|
+
))
|
65
|
+
|
66
|
+
text = subject.text_from_act(doc)
|
67
|
+
text.should == '1. Section
|
68
|
+
|
69
|
+
\Chapter 2 ignored
|
70
|
+
|
71
|
+
\Part 2 ignored
|
72
|
+
|
73
|
+
\Schedule 2 ignored
|
74
|
+
|
75
|
+
\BODY ignored
|
76
|
+
|
77
|
+
\PREAMBLE ignored
|
78
|
+
|
79
|
+
\PREFACE ignored
|
80
|
+
|
81
|
+
\2. ignored
|
82
|
+
|
83
|
+
\2.1 ignored
|
84
|
+
|
85
|
+
\(2) ignored
|
86
|
+
|
87
|
+
\(a) ignored
|
88
|
+
|
89
|
+
\(2a) ignored
|
90
|
+
|
91
|
+
\{| ignored
|
92
|
+
|
93
|
+
'
|
94
|
+
end
|
95
|
+
end
|
41
96
|
end
|
data/spec/za/act_spec.rb
CHANGED
@@ -91,6 +91,31 @@ EOS
|
|
91
91
|
</content>
|
92
92
|
</paragraph>
|
93
93
|
</section>
|
94
|
+
</body>'
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should handle escaped content' do
|
98
|
+
node = parse :body, <<EOS
|
99
|
+
\\1. ignored
|
100
|
+
|
101
|
+
1. Section
|
102
|
+
\\Chapter 2 ignored
|
103
|
+
EOS
|
104
|
+
to_xml(node).should == '<body>
|
105
|
+
<paragraph id="paragraph-0">
|
106
|
+
<content>
|
107
|
+
<p>1. ignored</p>
|
108
|
+
</content>
|
109
|
+
</paragraph>
|
110
|
+
<section id="section-1">
|
111
|
+
<num>1.</num>
|
112
|
+
<heading>Section</heading>
|
113
|
+
<paragraph id="section-1.paragraph-0">
|
114
|
+
<content>
|
115
|
+
<p>Chapter 2 ignored</p>
|
116
|
+
</content>
|
117
|
+
</paragraph>
|
118
|
+
</section>
|
94
119
|
</body>'
|
95
120
|
end
|
96
121
|
end
|
@@ -255,6 +280,29 @@ EOS
|
|
255
280
|
</table>
|
256
281
|
</content>
|
257
282
|
</paragraph>
|
283
|
+
</chapter>'
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should ignore escaped chapter headers' do
|
287
|
+
node = parse :chapter, <<EOS
|
288
|
+
Chapter 1 The Chapter
|
289
|
+
|
290
|
+
Stuff
|
291
|
+
|
292
|
+
\\Chapter 2 - Ignored
|
293
|
+
|
294
|
+
More stuff
|
295
|
+
EOS
|
296
|
+
to_xml(node).should == '<chapter id="chapter-1">
|
297
|
+
<num>1</num>
|
298
|
+
<heading>The Chapter</heading>
|
299
|
+
<paragraph id="chapter-1.paragraph-0">
|
300
|
+
<content>
|
301
|
+
<p>Stuff</p>
|
302
|
+
<p>Chapter 2 - Ignored</p>
|
303
|
+
<p>More stuff</p>
|
304
|
+
</content>
|
305
|
+
</paragraph>
|
258
306
|
</chapter>'
|
259
307
|
end
|
260
308
|
end
|
@@ -439,6 +487,24 @@ EOS
|
|
439
487
|
<num>3</num>
|
440
488
|
<heading>The Other Heading</heading>
|
441
489
|
</part>
|
490
|
+
</body>'
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'should handle escaped parts' do
|
494
|
+
node = parse :body, <<EOS
|
495
|
+
Part 2 The Part Heading
|
496
|
+
\\Part 3 ignored
|
497
|
+
EOS
|
498
|
+
to_xml(node).should == '<body>
|
499
|
+
<part id="part-2">
|
500
|
+
<num>2</num>
|
501
|
+
<heading>The Part Heading</heading>
|
502
|
+
<paragraph id="part-2.paragraph-0">
|
503
|
+
<content>
|
504
|
+
<p>Part 3 ignored</p>
|
505
|
+
</content>
|
506
|
+
</paragraph>
|
507
|
+
</part>
|
442
508
|
</body>'
|
443
509
|
end
|
444
510
|
end
|
@@ -629,6 +695,30 @@ EOS
|
|
629
695
|
</item>
|
630
696
|
</blockList>
|
631
697
|
</content>
|
698
|
+
</subsection>'
|
699
|
+
end
|
700
|
+
|
701
|
+
it 'should ignore escaped items' do
|
702
|
+
node = parse(:subsection, <<EOS
|
703
|
+
(1) a subsection
|
704
|
+
\\(1) ignored
|
705
|
+
\\9.9.2 item2
|
706
|
+
\\some text
|
707
|
+
\\(d) item 4
|
708
|
+
\\(b) (i) single
|
709
|
+
EOS
|
710
|
+
)
|
711
|
+
|
712
|
+
to_xml(node, '', 1).should == '<subsection id="1">
|
713
|
+
<num>(1)</num>
|
714
|
+
<content>
|
715
|
+
<p>a subsection</p>
|
716
|
+
<p>(1) ignored</p>
|
717
|
+
<p>9.9.2 item2</p>
|
718
|
+
<p>some text</p>
|
719
|
+
<p>(d) item 4</p>
|
720
|
+
<p>(b) (i) single</p>
|
721
|
+
</content>
|
632
722
|
</subsection>'
|
633
723
|
end
|
634
724
|
end
|
@@ -867,6 +957,18 @@ EOS
|
|
867
957
|
</preface>'
|
868
958
|
end
|
869
959
|
|
960
|
+
it 'should ignore escaped preface' do
|
961
|
+
node = parse :act, <<EOS
|
962
|
+
\\PREFACE
|
963
|
+
1. Section
|
964
|
+
(1) hello
|
965
|
+
EOS
|
966
|
+
|
967
|
+
to_xml(node.preface).should == '<preface>
|
968
|
+
<p>PREFACE</p>
|
969
|
+
</preface>'
|
970
|
+
end
|
971
|
+
|
870
972
|
it 'should support remarks in the preface' do
|
871
973
|
node = parse :act, <<EOS
|
872
974
|
PREFACE
|
@@ -993,10 +1095,29 @@ EOS
|
|
993
1095
|
|
994
1096
|
node.elements.first.text_value.should == ""
|
995
1097
|
end
|
1098
|
+
|
1099
|
+
it 'should ignore escaped preamble' do
|
1100
|
+
node = parse :act, <<EOS
|
1101
|
+
PREFACE
|
1102
|
+
|
1103
|
+
this is the preface
|
1104
|
+
|
1105
|
+
PREAMBLE
|
1106
|
+
|
1107
|
+
\\PREAMBLE
|
1108
|
+
|
1109
|
+
1. Section
|
1110
|
+
(1) hello
|
1111
|
+
EOS
|
1112
|
+
|
1113
|
+
to_xml(node.preamble).should == '<preamble>
|
1114
|
+
<p>PREAMBLE</p>
|
1115
|
+
</preamble>'
|
1116
|
+
end
|
996
1117
|
end
|
997
1118
|
|
998
1119
|
#-------------------------------------------------------------------------------
|
999
|
-
#
|
1120
|
+
# Sections
|
1000
1121
|
|
1001
1122
|
context 'section' do
|
1002
1123
|
it 'should handle section numbers after title' do
|
@@ -1160,6 +1281,29 @@ EOS
|
|
1160
1281
|
</blockList>
|
1161
1282
|
</content>
|
1162
1283
|
</paragraph>
|
1284
|
+
</section>'
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
it 'should ignore escaped section headings' do
|
1288
|
+
node = parse :section, <<EOS
|
1289
|
+
1. Section
|
1290
|
+
|
1291
|
+
\\1. ignored
|
1292
|
+
\\2. another line
|
1293
|
+
stuff
|
1294
|
+
\\3. a third
|
1295
|
+
EOS
|
1296
|
+
to_xml(node, "").should == '<section id="section-1">
|
1297
|
+
<num>1.</num>
|
1298
|
+
<heading>Section</heading>
|
1299
|
+
<paragraph id="section-1.paragraph-0">
|
1300
|
+
<content>
|
1301
|
+
<p>1. ignored</p>
|
1302
|
+
<p>2. another line</p>
|
1303
|
+
<p>stuff</p>
|
1304
|
+
<p>3. a third</p>
|
1305
|
+
</content>
|
1306
|
+
</paragraph>
|
1163
1307
|
</section>'
|
1164
1308
|
end
|
1165
1309
|
end
|
@@ -1653,6 +1797,61 @@ Schedule 3. Matters which shall continue to be regulated by Swazi Law and Custom
|
|
1653
1797
|
Schedule 4. Specially entrenched provisions and entrenched provisions.
|
1654
1798
|
EOS
|
1655
1799
|
end
|
1800
|
+
|
1801
|
+
it 'should handle escaped schedules' do
|
1802
|
+
node = parse :schedules, <<EOS
|
1803
|
+
Schedule
|
1804
|
+
|
1805
|
+
Subject to approval in terms of this By-Law.
|
1806
|
+
|
1807
|
+
\\Schedule another
|
1808
|
+
|
1809
|
+
More stuff
|
1810
|
+
EOS
|
1811
|
+
s = to_xml(node)
|
1812
|
+
today = Time.now.strftime('%Y-%m-%d')
|
1813
|
+
s.should == '<component id="component-schedule">
|
1814
|
+
<doc name="schedule">
|
1815
|
+
<meta>
|
1816
|
+
<identification source="#slaw">
|
1817
|
+
<FRBRWork>
|
1818
|
+
<FRBRthis value="/za/act/1980/01/schedule"/>
|
1819
|
+
<FRBRuri value="/za/act/1980/01"/>
|
1820
|
+
<FRBRalias value="Schedule"/>
|
1821
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
1822
|
+
<FRBRauthor href="#council"/>
|
1823
|
+
<FRBRcountry value="za"/>
|
1824
|
+
</FRBRWork>
|
1825
|
+
<FRBRExpression>
|
1826
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
1827
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
1828
|
+
<FRBRdate date="1980-01-01" name="Generation"/>
|
1829
|
+
<FRBRauthor href="#council"/>
|
1830
|
+
<FRBRlanguage language="eng"/>
|
1831
|
+
</FRBRExpression>
|
1832
|
+
<FRBRManifestation>
|
1833
|
+
<FRBRthis value="/za/act/1980/01/eng@/schedule"/>
|
1834
|
+
<FRBRuri value="/za/act/1980/01/eng@"/>
|
1835
|
+
<FRBRdate date="' + today + '" name="Generation"/>
|
1836
|
+
<FRBRauthor href="#slaw"/>
|
1837
|
+
</FRBRManifestation>
|
1838
|
+
</identification>
|
1839
|
+
</meta>
|
1840
|
+
<mainBody>
|
1841
|
+
<article id="schedule">
|
1842
|
+
<paragraph id="schedule.paragraph-0">
|
1843
|
+
<content>
|
1844
|
+
<p>Subject to approval in terms of this By-Law.</p>
|
1845
|
+
<p>Schedule another</p>
|
1846
|
+
<p>More stuff</p>
|
1847
|
+
</content>
|
1848
|
+
</paragraph>
|
1849
|
+
</article>
|
1850
|
+
</mainBody>
|
1851
|
+
</doc>
|
1852
|
+
</component>'
|
1853
|
+
end
|
1854
|
+
|
1656
1855
|
end
|
1657
1856
|
|
1658
1857
|
#-------------------------------------------------------------------------------
|
@@ -1768,6 +1967,24 @@ EOS
|
|
1768
1967
|
</doc>
|
1769
1968
|
</component>'
|
1770
1969
|
end
|
1970
|
+
|
1971
|
+
it 'should ignore an escaped table' do
|
1972
|
+
node = parse :block_paragraphs, <<EOS
|
1973
|
+
\\{|
|
1974
|
+
| r1c1
|
1975
|
+
| r1c2
|
1976
|
+
|}
|
1977
|
+
EOS
|
1978
|
+
|
1979
|
+
to_xml(node).should == '<paragraph id="paragraph-0">
|
1980
|
+
<content>
|
1981
|
+
<p>{|</p>
|
1982
|
+
<p>| r1c1</p>
|
1983
|
+
<p>| r1c2</p>
|
1984
|
+
<p>|}</p>
|
1985
|
+
</content>
|
1986
|
+
</paragraph>'
|
1987
|
+
end
|
1771
1988
|
end
|
1772
1989
|
|
1773
1990
|
#-------------------------------------------------------------------------------
|
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.10.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: 2016-
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.3.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.3.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/slaw/xml_support.rb
|
192
192
|
- lib/slaw/za/act.treetop
|
193
193
|
- lib/slaw/za/act_nodes.rb
|
194
|
+
- lib/slaw/za/act_text.xsl
|
194
195
|
- slaw.gemspec
|
195
196
|
- spec/act_spec.rb
|
196
197
|
- spec/bylaw_spec.rb
|