slaw 0.6.3 → 0.6.4
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/lib/slaw/version.rb +1 -1
- data/lib/slaw/za/act.treetop +19 -2
- data/lib/slaw/za/act_nodes.rb +42 -2
- data/slaw.gemspec +1 -0
- data/spec/za/act_spec.rb +66 -2
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c18d054d1825b20bfc2dcf608a445e2d4b3a0c6a
|
|
4
|
+
data.tar.gz: 73cc58395c8f2d8dda8117d592f7c9faf48e57b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b91f7c896b92dcd42cf81bb23118921db55653695c9f65093a917f9e3d0fc3b849f11f9ce1e6b494cd85df5ac8ba84d871bd6c472c001fffa3f4c41c1fecdcbd
|
|
7
|
+
data.tar.gz: 317aba38148c36f8753009ff417e8bca9550e101a0ef4e5f18e923170ddf4a7f121b312eadf98b9b8b33d626f703c7b65696e0bae5cad4f3adbc6efa03b1ce2e
|
data/lib/slaw/version.rb
CHANGED
data/lib/slaw/za/act.treetop
CHANGED
|
@@ -38,7 +38,7 @@ module Slaw
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
rule subsection
|
|
41
|
-
statement:(numbered_statement / naked_statement)
|
|
41
|
+
statement:(numbered_statement / table / naked_statement)
|
|
42
42
|
blocklist:blocklist? <Subsection>
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -48,7 +48,7 @@ module Slaw
|
|
|
48
48
|
|
|
49
49
|
rule schedule
|
|
50
50
|
schedule_heading
|
|
51
|
-
statements:schedule_statement* <Schedule>
|
|
51
|
+
statements:(table / schedule_statement)* <Schedule>
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
##########
|
|
@@ -120,6 +120,23 @@ module Slaw
|
|
|
120
120
|
|
|
121
121
|
rule schedule_statement
|
|
122
122
|
space? (!schedule_heading) content eol
|
|
123
|
+
<ScheduleStatement>
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
##########
|
|
127
|
+
# tables
|
|
128
|
+
|
|
129
|
+
rule table
|
|
130
|
+
space? table_start eol? (!table_end content eol)* table_end eol
|
|
131
|
+
<Table>
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
rule table_start
|
|
135
|
+
space? '{|'
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
rule table_end
|
|
139
|
+
space? '|}'
|
|
123
140
|
end
|
|
124
141
|
|
|
125
142
|
##########
|
data/lib/slaw/za/act_nodes.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'wikicloth'
|
|
2
|
+
|
|
1
3
|
module Slaw
|
|
2
4
|
module ZA
|
|
3
5
|
module Act
|
|
@@ -252,7 +254,7 @@ module Slaw
|
|
|
252
254
|
end
|
|
253
255
|
else
|
|
254
256
|
# raw content
|
|
255
|
-
|
|
257
|
+
statement.to_xml(b, idprefix)
|
|
256
258
|
end
|
|
257
259
|
}
|
|
258
260
|
}
|
|
@@ -275,9 +277,16 @@ module Slaw
|
|
|
275
277
|
elements[3].content
|
|
276
278
|
end
|
|
277
279
|
end
|
|
280
|
+
|
|
281
|
+
def to_xml(b, idprefix)
|
|
282
|
+
b.p(content.text_value) if content
|
|
283
|
+
end
|
|
278
284
|
end
|
|
279
285
|
|
|
280
286
|
class NakedStatement < Treetop::Runtime::SyntaxNode
|
|
287
|
+
def to_xml(b, idprefix)
|
|
288
|
+
b.p(content.text_value) if content
|
|
289
|
+
end
|
|
281
290
|
end
|
|
282
291
|
|
|
283
292
|
class Blocklist < Treetop::Runtime::SyntaxNode
|
|
@@ -313,6 +322,31 @@ module Slaw
|
|
|
313
322
|
end
|
|
314
323
|
end
|
|
315
324
|
|
|
325
|
+
class Table < Treetop::Runtime::SyntaxNode
|
|
326
|
+
def to_xml(b, idprefix)
|
|
327
|
+
# parse the table using wikicloth
|
|
328
|
+
html = WikiCloth::Parser.new({data: self.text_value}).to_html
|
|
329
|
+
|
|
330
|
+
# we need to strip any surrounding p tags and add
|
|
331
|
+
# an id to the table
|
|
332
|
+
html = Nokogiri::HTML(html)
|
|
333
|
+
table = html.css("table").first
|
|
334
|
+
table['id'] = "#{idprefix}table0"
|
|
335
|
+
|
|
336
|
+
# wrap td and th content in p tags
|
|
337
|
+
table.css("td, th").each do |cell|
|
|
338
|
+
p = Nokogiri::XML::Node.new("p", html)
|
|
339
|
+
p.children = cell.children
|
|
340
|
+
p.parent = cell
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
table.xpath('//text()[1]').each{ |t| t.content = t.content.lstrip }
|
|
344
|
+
table.xpath('//text()[last()]').each{ |t| t.content = t.content.rstrip }
|
|
345
|
+
|
|
346
|
+
b << table.to_html
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
316
350
|
class ScheduleContainer < Treetop::Runtime::SyntaxNode
|
|
317
351
|
def to_xml(b)
|
|
318
352
|
return if schedules.elements.empty?
|
|
@@ -389,13 +423,19 @@ module Slaw
|
|
|
389
423
|
b.article(id: id) { |b|
|
|
390
424
|
b.heading(heading) if heading
|
|
391
425
|
b.content { |b|
|
|
392
|
-
statements.elements.each { |e|
|
|
426
|
+
statements.elements.each { |e| e.to_xml(b, id + '.') }
|
|
393
427
|
}
|
|
394
428
|
}
|
|
395
429
|
}
|
|
396
430
|
}
|
|
397
431
|
end
|
|
398
432
|
end
|
|
433
|
+
|
|
434
|
+
class ScheduleStatement < Treetop::Runtime::SyntaxNode
|
|
435
|
+
def to_xml(b, idprefix)
|
|
436
|
+
b.p(content.text_value) if content
|
|
437
|
+
end
|
|
438
|
+
end
|
|
399
439
|
end
|
|
400
440
|
end
|
|
401
441
|
end
|
data/slaw.gemspec
CHANGED
data/spec/za/act_spec.rb
CHANGED
|
@@ -21,10 +21,10 @@ describe Slaw::ActGenerator do
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def to_xml(node)
|
|
24
|
+
def to_xml(node, *args)
|
|
25
25
|
s = ""
|
|
26
26
|
b = Builder::XmlMarkup.new(target: s)
|
|
27
|
-
node.to_xml(b)
|
|
27
|
+
node.to_xml(b, *args)
|
|
28
28
|
s
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -548,4 +548,68 @@ EOS
|
|
|
548
548
|
EOS
|
|
549
549
|
end
|
|
550
550
|
end
|
|
551
|
+
|
|
552
|
+
describe 'tables' do
|
|
553
|
+
it 'should parse basic tables' do
|
|
554
|
+
node = parse :table, <<EOS
|
|
555
|
+
{|
|
|
556
|
+
| r1c1
|
|
557
|
+
| r1c2
|
|
558
|
+
|-
|
|
559
|
+
| r2c1
|
|
560
|
+
| r2c2
|
|
561
|
+
|}
|
|
562
|
+
EOS
|
|
563
|
+
|
|
564
|
+
node.text_value.should == "{|\n| r1c1\n| r1c2\n|-\n| r2c1\n| r2c2\n|}\n"
|
|
565
|
+
to_xml(node, "prefix.").should == '<table id="prefix.table0"><tr><td><p>r1c1</p></td>
|
|
566
|
+
<td><p>r1c2</p></td></tr>
|
|
567
|
+
<tr><td><p>r2c1</p></td>
|
|
568
|
+
<td><p>r2c2</p></td></tr></table>'
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
it 'should parse a table in a section' do
|
|
572
|
+
node = parse :section, <<EOS
|
|
573
|
+
10. A section title
|
|
574
|
+
|
|
575
|
+
Heres a table:
|
|
576
|
+
|
|
577
|
+
{|
|
|
578
|
+
| r1c1
|
|
579
|
+
| r1c2
|
|
580
|
+
|-
|
|
581
|
+
| r2c1
|
|
582
|
+
| r2c2
|
|
583
|
+
|}
|
|
584
|
+
EOS
|
|
585
|
+
|
|
586
|
+
xml = to_xml(node)
|
|
587
|
+
xml.should == '<section id="section-10"><num>10.</num><heading>A section title</heading><subsection id="section-10.subsection-0"><content><p>Heres a table:</p></content></subsection><subsection id="section-10.subsection-1"><content><table id="section-10.subsection-1.table0"><tr><td><p>r1c1</p></td>
|
|
588
|
+
<td><p>r1c2</p></td></tr>
|
|
589
|
+
<tr><td><p>r2c1</p></td>
|
|
590
|
+
<td><p>r2c2</p></td></tr></table></content></subsection></section>'
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
it 'should parse a table in a schedule' do
|
|
594
|
+
node = parse :schedule, <<EOS
|
|
595
|
+
Schedule 1
|
|
596
|
+
|
|
597
|
+
Heres a table:
|
|
598
|
+
|
|
599
|
+
{|
|
|
600
|
+
| r1c1
|
|
601
|
+
| r1c2
|
|
602
|
+
|-
|
|
603
|
+
| r2c1
|
|
604
|
+
| r2c2
|
|
605
|
+
|}
|
|
606
|
+
EOS
|
|
607
|
+
|
|
608
|
+
xml = to_xml(node, "")
|
|
609
|
+
xml.should == '<doc name="schedule1"><meta><identification source="#slaw"><FRBRWork><FRBRthis value="/za/act/1980/01/schedule1"/><FRBRuri value="/za/act/1980/01"/><FRBRalias value="Schedule 1"/><FRBRdate date="1980-01-01" name="Generation"/><FRBRauthor href="#council" as="#author"/><FRBRcountry value="za"/></FRBRWork><FRBRExpression><FRBRthis value="/za/act/1980/01/eng@/schedule1"/><FRBRuri value="/za/act/1980/01/eng@"/><FRBRdate date="1980-01-01" name="Generation"/><FRBRauthor href="#council" as="#author"/><FRBRlanguage language="eng"/></FRBRExpression><FRBRManifestation><FRBRthis value="/za/act/1980/01/eng@/schedule1"/><FRBRuri value="/za/act/1980/01/eng@"/><FRBRdate date="2015-05-13" name="Generation"/><FRBRauthor href="#slaw" as="#author"/></FRBRManifestation></identification></meta><mainBody><article id="schedule-1"><content><p>Heres a table:</p><table id="schedule-1.table0"><tr><td><p>r1c1</p></td>
|
|
610
|
+
<td><p>r1c2</p></td></tr>
|
|
611
|
+
<tr><td><p>r2c1</p></td>
|
|
612
|
+
<td><p>r2c2</p></td></tr></table></content></article></mainBody></doc>'
|
|
613
|
+
end
|
|
614
|
+
end
|
|
551
615
|
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.6.
|
|
4
|
+
version: 0.6.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Greg Kempe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-05-
|
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -150,6 +150,20 @@ dependencies:
|
|
|
150
150
|
- - "~>"
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
152
|
version: 0.2.2
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: wikicloth
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - "~>"
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: 0.8.3
|
|
160
|
+
type: :runtime
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - "~>"
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: 0.8.3
|
|
153
167
|
description: Slaw is a lightweight library for rendering and generating Akoma Ntoso
|
|
154
168
|
acts from plain text and PDF documents.
|
|
155
169
|
email:
|