slaw 0.6.2 → 0.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75915642fffe0d65b3d4386745c12cd019e3d715
4
- data.tar.gz: fb183f90a301b479fd4d422d7da479f8796e808d
3
+ metadata.gz: aa99a0d10c55f90c3cc64dc38caf91b986b94ab1
4
+ data.tar.gz: afd8583f42680e2caa287d5ebc993b616e4eeac8
5
5
  SHA512:
6
- metadata.gz: acf9d6a07f1a927461394721228a8ebd6548fe79c5604e59f36463bdb4bd0a25df1bafa8aa391a937ed45756f1a70f85e9c48469d752c92817c04f392f62c169
7
- data.tar.gz: 4ada4ce9e47e9d71bdcf55f1fc8c94c7977e03711b46d0ec86ceae17f8df5a2efcc7a23aa171adf967a0c24a3fd889d80f2aefdee3ebd6c6fb0f0893f14598d6
6
+ metadata.gz: 617cfdd201458cf85da6ea524e8e97ee955473825e1064fc86684adfcd9418faca2c9a4626c8c0654e3ecdcd2705199ab154c7cd1bd8a018380e8654ccaae842
7
+ data.tar.gz: 6c987cb5f14663c1e5ad5fa73af06554afc2b1cd4a6ea2732592ab5b7180aa3834799e449f68c315ed1e0d1396f5b4b7b5371bd31e682011924e56b29308adc7
data/bin/slaw CHANGED
@@ -37,8 +37,16 @@ class SlawCLI < Thor
37
37
 
38
38
  if options[:fragment]
39
39
  generator.document_class = Slaw::Fragment
40
+
40
41
  fragment = options[:fragment]
41
- fragment = 'act' if fragment.downcase == 'akomantoso'
42
+ fragment = case fragment.downcase
43
+ when 'akomantoso'
44
+ 'act'
45
+ when 'doc'
46
+ 'schedule'
47
+ else
48
+ fragment
49
+ end
42
50
  generator.builder.parse_options[:root] = fragment
43
51
 
44
52
  if options[:id_prefix]
@@ -48,7 +56,12 @@ class SlawCLI < Thor
48
56
  end
49
57
  end
50
58
 
51
- act = generator.generate_from_text(text)
59
+ begin
60
+ act = generator.generate_from_text(text)
61
+ rescue Slaw::Parse::ParseError => e
62
+ error e.message
63
+ exit 1
64
+ end
52
65
 
53
66
  # definitions?
54
67
  generator.builder.link_definitions(act.doc) if options[:definitions]
data/lib/slaw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -110,7 +110,7 @@ module Slaw
110
110
  # statements
111
111
 
112
112
  rule numbered_statement
113
- space? numbered_statement_prefix whitespace? (!blocklist_item_prefix content eol)? <NumberedStatement>
113
+ space? numbered_statement_prefix whitespace (!blocklist_item_prefix content eol)? <NumberedStatement>
114
114
  end
115
115
 
116
116
  rule naked_statement
@@ -126,7 +126,7 @@ module Slaw
126
126
  # prefixes
127
127
 
128
128
  rule part_heading_prefix
129
- 'part'i space alphanums ':'?
129
+ 'part'i space alphanums whitespace [:-]?
130
130
  end
131
131
 
132
132
  rule chapter_heading_prefix
@@ -173,7 +173,7 @@ module Slaw
173
173
  end
174
174
 
175
175
  rule blocklist_item
176
- space? blocklist_item_prefix whitespace? item_content:(!blocklist_item_prefix content eol)?
176
+ space? blocklist_item_prefix whitespace item_content:(!blocklist_item_prefix content eol)?
177
177
  <BlocklistItem>
178
178
  end
179
179
 
@@ -318,43 +318,10 @@ module Slaw
318
318
  return if schedules.elements.empty?
319
319
 
320
320
  b.components { |b|
321
- schedules.elements.each_with_index { |e, i| write_schedule(e, i+1, b) }
322
- }
323
- end
324
-
325
- def write_schedule(element, i, b)
326
- # component name
327
- comp = "schedule#{i}"
328
-
329
- b.component(id: "component-#{i}") { |b|
330
- b.doc(name: "schedule#{i}") { |b|
331
- b.meta { |b|
332
- b.identification(source: "#slaw") { |b|
333
- b.FRBRWork { |b|
334
- b.FRBRthis(value: "#{Act::WORK_URI}/#{comp}")
335
- b.FRBRuri(value: Act::WORK_URI)
336
- b.FRBRalias(value: element.alias)
337
- b.FRBRdate(date: '1980-01-01', name: 'Generation')
338
- b.FRBRauthor(href: '#council', as: '#author')
339
- b.FRBRcountry(value: 'za')
340
- }
341
- b.FRBRExpression { |b|
342
- b.FRBRthis(value: "#{Act::EXPRESSION_URI}/#{comp}")
343
- b.FRBRuri(value: Act::EXPRESSION_URI)
344
- b.FRBRdate(date: '1980-01-01', name: 'Generation')
345
- b.FRBRauthor(href: '#council', as: '#author')
346
- b.FRBRlanguage(language: 'eng')
347
- }
348
- b.FRBRManifestation { |b|
349
- b.FRBRthis(value: "#{Act::MANIFESTATION_URI}/#{comp}")
350
- b.FRBRuri(value: Act::MANIFESTATION_URI)
351
- b.FRBRdate(date: Time.now.strftime('%Y-%m-%d'), name: 'Generation')
352
- b.FRBRauthor(href: '#slaw', as: '#author')
353
- }
354
- }
321
+ schedules.elements.each_with_index { |e, i|
322
+ b.component(id: "component-#{i+1}") { |b|
323
+ e.to_xml(b, "", i+1)
355
324
  }
356
-
357
- b.mainBody { |b| element.to_xml(b, i) }
358
325
  }
359
326
  }
360
327
  end
@@ -382,16 +349,49 @@ module Slaw
382
349
  end
383
350
  end
384
351
 
385
- def to_xml(b, idprefix, i=0)
352
+ def to_xml(b, idprefix, i=1)
386
353
  n = num.nil? ? i : num
387
- id = "schedule-#{n}"
388
-
389
- # there is no good AKN hierarchy container for schedules, so we
390
- # just use article because we don't use it anywhere else.
391
- b.article(id: id) { |b|
392
- b.heading(heading) if heading
393
- b.content { |b|
394
- statements.elements.each { |e| b.p(e.content.text_value) }
354
+
355
+ # component name
356
+ comp = "schedule#{n}"
357
+ id = "#{idprefix}schedule-#{n}"
358
+
359
+ b.doc(name: "schedule#{n}") { |b|
360
+ b.meta { |b|
361
+ b.identification(source: "#slaw") { |b|
362
+ b.FRBRWork { |b|
363
+ b.FRBRthis(value: "#{Act::WORK_URI}/#{comp}")
364
+ b.FRBRuri(value: Act::WORK_URI)
365
+ b.FRBRalias(value: self.alias)
366
+ b.FRBRdate(date: '1980-01-01', name: 'Generation')
367
+ b.FRBRauthor(href: '#council', as: '#author')
368
+ b.FRBRcountry(value: 'za')
369
+ }
370
+ b.FRBRExpression { |b|
371
+ b.FRBRthis(value: "#{Act::EXPRESSION_URI}/#{comp}")
372
+ b.FRBRuri(value: Act::EXPRESSION_URI)
373
+ b.FRBRdate(date: '1980-01-01', name: 'Generation')
374
+ b.FRBRauthor(href: '#council', as: '#author')
375
+ b.FRBRlanguage(language: 'eng')
376
+ }
377
+ b.FRBRManifestation { |b|
378
+ b.FRBRthis(value: "#{Act::MANIFESTATION_URI}/#{comp}")
379
+ b.FRBRuri(value: Act::MANIFESTATION_URI)
380
+ b.FRBRdate(date: Time.now.strftime('%Y-%m-%d'), name: 'Generation')
381
+ b.FRBRauthor(href: '#slaw', as: '#author')
382
+ }
383
+ }
384
+ }
385
+
386
+ b.mainBody { |b|
387
+ # there is no good AKN hierarchy container for schedules, so we
388
+ # just use article because we don't use it anywhere else.
389
+ b.article(id: id) { |b|
390
+ b.heading(heading) if heading
391
+ b.content { |b|
392
+ statements.elements.each { |e| b.p(e.content.text_value) }
393
+ }
394
+ }
395
395
  }
396
396
  }
397
397
  end
data/spec/za/act_spec.rb CHANGED
@@ -61,6 +61,28 @@ EOS
61
61
  to_xml(node).should == "<part id=\"part-2\"><num>2</num><heading>The Part Heading</heading><section id=\"section-1\"><num>1.</num><heading>Section</heading><subsection id=\"section-1.subsection-0\"><content><p>Hello there</p></content></subsection></section></part>"
62
62
  end
63
63
 
64
+ it 'should handle part headers with dashes' do
65
+ node = parse :part, <<EOS
66
+ Part 2 - The Part Heading
67
+ 1. Section
68
+ Hello there
69
+ EOS
70
+ node.num.should == "2"
71
+ node.heading.title.should == 'The Part Heading'
72
+ to_xml(node).should == "<part id=\"part-2\"><num>2</num><heading>The Part Heading</heading><section id=\"section-1\"><num>1.</num><heading>Section</heading><subsection id=\"section-1.subsection-0\"><content><p>Hello there</p></content></subsection></section></part>"
73
+ end
74
+
75
+ it 'should handle part headers with colons' do
76
+ node = parse :part, <<EOS
77
+ Part 2: The Part Heading
78
+ 1. Section
79
+ Hello there
80
+ EOS
81
+ node.num.should == "2"
82
+ node.heading.title.should == 'The Part Heading'
83
+ to_xml(node).should == "<part id=\"part-2\"><num>2</num><heading>The Part Heading</heading><section id=\"section-1\"><num>1.</num><heading>Section</heading><subsection id=\"section-1.subsection-0\"><content><p>Hello there</p></content></subsection></section></part>"
84
+ end
85
+
64
86
  it 'should handle parts and odd section numbers' do
65
87
  subject.parser.options = {section_number_after_title: false}
66
88
  node = parse :act, <<EOS
@@ -367,11 +389,11 @@ EOS
367
389
 
368
390
  it 'should serialise many schedules correctly' do
369
391
  node = parse :schedules, <<EOS
370
- Schedule "1"
392
+ Schedule "2"
371
393
  A Title
372
394
  1. Foo
373
395
  2. Bar
374
- Schedule 2
396
+ Schedule 3
375
397
  Another Title
376
398
  Baz
377
399
  Boom
@@ -387,26 +409,26 @@ EOS
387
409
  s.should == <<EOS
388
410
  <components>
389
411
  <component id="component-1">
390
- <doc name="schedule1">
412
+ <doc name="schedule2">
391
413
  <meta>
392
414
  <identification source="#slaw">
393
415
  <FRBRWork>
394
- <FRBRthis value="/za/act/1980/01/schedule1"/>
416
+ <FRBRthis value="/za/act/1980/01/schedule2"/>
395
417
  <FRBRuri value="/za/act/1980/01"/>
396
- <FRBRalias value="Schedule 1"/>
418
+ <FRBRalias value="Schedule 2"/>
397
419
  <FRBRdate date="1980-01-01" name="Generation"/>
398
420
  <FRBRauthor href="#council" as="#author"/>
399
421
  <FRBRcountry value="za"/>
400
422
  </FRBRWork>
401
423
  <FRBRExpression>
402
- <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
424
+ <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
403
425
  <FRBRuri value="/za/act/1980/01/eng@"/>
404
426
  <FRBRdate date="1980-01-01" name="Generation"/>
405
427
  <FRBRauthor href="#council" as="#author"/>
406
428
  <FRBRlanguage language="eng"/>
407
429
  </FRBRExpression>
408
430
  <FRBRManifestation>
409
- <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
431
+ <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
410
432
  <FRBRuri value="/za/act/1980/01/eng@"/>
411
433
  <FRBRdate date="#{today}" name="Generation"/>
412
434
  <FRBRauthor href="#slaw" as="#author"/>
@@ -414,7 +436,7 @@ EOS
414
436
  </identification>
415
437
  </meta>
416
438
  <mainBody>
417
- <article id="schedule-1">
439
+ <article id="schedule-2">
418
440
  <heading>A Title</heading>
419
441
  <content>
420
442
  <p>1. Foo</p>
@@ -425,26 +447,26 @@ EOS
425
447
  </doc>
426
448
  </component>
427
449
  <component id="component-2">
428
- <doc name="schedule2">
450
+ <doc name="schedule3">
429
451
  <meta>
430
452
  <identification source="#slaw">
431
453
  <FRBRWork>
432
- <FRBRthis value="/za/act/1980/01/schedule2"/>
454
+ <FRBRthis value="/za/act/1980/01/schedule3"/>
433
455
  <FRBRuri value="/za/act/1980/01"/>
434
- <FRBRalias value="Schedule 2"/>
456
+ <FRBRalias value="Schedule 3"/>
435
457
  <FRBRdate date="1980-01-01" name="Generation"/>
436
458
  <FRBRauthor href="#council" as="#author"/>
437
459
  <FRBRcountry value="za"/>
438
460
  </FRBRWork>
439
461
  <FRBRExpression>
440
- <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
462
+ <FRBRthis value="/za/act/1980/01/eng@/schedule3"/>
441
463
  <FRBRuri value="/za/act/1980/01/eng@"/>
442
464
  <FRBRdate date="1980-01-01" name="Generation"/>
443
465
  <FRBRauthor href="#council" as="#author"/>
444
466
  <FRBRlanguage language="eng"/>
445
467
  </FRBRExpression>
446
468
  <FRBRManifestation>
447
- <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
469
+ <FRBRthis value="/za/act/1980/01/eng@/schedule3"/>
448
470
  <FRBRuri value="/za/act/1980/01/eng@"/>
449
471
  <FRBRdate date="#{today}" name="Generation"/>
450
472
  <FRBRauthor href="#slaw" as="#author"/>
@@ -452,7 +474,7 @@ EOS
452
474
  </identification>
453
475
  </meta>
454
476
  <mainBody>
455
- <article id="schedule-2">
477
+ <article id="schedule-3">
456
478
  <heading>Another Title</heading>
457
479
  <content>
458
480
  <p>Baz</p>
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.2
4
+ version: 0.6.3
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-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler