slaw 3.3.2 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8ee67f5faf27fbf0798c473d13ed04fdb23f50e84fd5da699688e91a9243c81
4
- data.tar.gz: fa1e18df9ddece8b4e81604a9697e711b846fae2dfac465ddce7efdedb3e6e7a
3
+ metadata.gz: 82626011b387d28e9bdf0228b027fc2fcd643a8644fa0556c03c5ee7461dc7dd
4
+ data.tar.gz: f2e8cd8e854a5bcb3cd29b14acb9f7f48fa3461dc0e7627caec70c16d7c7d194
5
5
  SHA512:
6
- metadata.gz: 71e49ed835dad5c8d8e1663ec1df605c41bf43fb9e6691d41854be88f60923da7b425522c527bd154cc200b5c42bbf0f7db8bf3e46593f334b4c7ec209cb5d7a
7
- data.tar.gz: 1a55315fa951c9208438ecea2718da71e9e2ab70bf23adbc16bb7d910855a6b8e9bad56e74f0d43474e56ad542f1f9d1124d84f4695f1f8d7c2bb11fbe81ef5e
6
+ metadata.gz: 5b854023c84d5c07696fdb8ca62c92774afdd9ad52ede40657e40bf6d280683a000c8d4a2d58ad09a8d4c87ef1d8f621050fdfc46d422c45306b0964da284177
7
+ data.tar.gz: 5359da9d43cd6ebf8e1351a6004db43eb644fab20b312bc86df47361a9b4e267bc9b43e2eacc0014149e5ee898f75e65ff658ea5cf7f6ddd6e37314aa7f51d54
data/README.md CHANGED
@@ -81,6 +81,14 @@ You can create your own grammar by creating a gem that provides these files and
81
81
 
82
82
  ## Changelog
83
83
 
84
+ ### 3.4.0 (20 May 2019)
85
+
86
+ * Restructure subsections to support generic block elements, starting with an inline block element
87
+
88
+ ### 3.3.3 (17 May 2019)
89
+
90
+ * FIX bug where unparse was returning XML, not text
91
+
84
92
  ### 3.3.2 (15 May 2019)
85
93
 
86
94
  * Internal adjustments to make rules easier to override
@@ -87,7 +87,7 @@ module Slaw
87
87
 
88
88
  if dir = $LOAD_PATH.find { |p| File.exist?(p + filename) }
89
89
  xslt = Nokogiri::XSLT(File.read(dir + filename))
90
- xslt.transform(doc).child.to_xml
90
+ xslt.apply_to(doc).gsub(/^( *\n){2,}/, "\n")
91
91
  else
92
92
  raise "Unable to find text XSL for grammar #{@grammar}: #{fragment}"
93
93
  end
@@ -60,12 +60,7 @@ module Slaw
60
60
  end
61
61
 
62
62
  rule subsection
63
- space? subsection_prefix space?
64
- # eg: (2) (a) foo
65
- first_child:inline_block_element?
66
- # eg: (2)
67
- eol?
68
- children:block_element* <Subsection>
63
+ space? subsection_prefix space? block_elements_with_inline <Subsection>
69
64
  end
70
65
 
71
66
  rule generic_container
@@ -77,6 +72,18 @@ module Slaw
77
72
  <Crossheading>
78
73
  end
79
74
 
75
+ # An option inline block element, followed by consecutive non-structured content.
76
+ # This is useful after a rule that can start a new container and have
77
+ # the first element of the container on the same line, eg.:
78
+ #
79
+ # (1) subsection with content
80
+ # (a) list a...
81
+ #
82
+ rule block_elements_with_inline
83
+ first_child:inline_block_element?
84
+ children:block_element* <BlockElementsWithInline>
85
+ end
86
+
80
87
  # Consecutive non-structured content. We allow many elements
81
88
  # here so that we wrap consecutive block elements in one <content> tag,
82
89
  # rather than multiple containers for each.
@@ -262,6 +262,22 @@ module Slaw
262
262
  end
263
263
  end
264
264
 
265
+ class BlockElementsWithInline < Treetop::Runtime::SyntaxNode
266
+ def to_xml(b, idprefix='')
267
+ b.content { |b|
268
+ kids = [first_child] + children.elements
269
+ kids = kids.select { |k| k and !k.text_value.strip.empty? }
270
+
271
+ if kids.empty?
272
+ # schema requires a non-empty content element
273
+ b.p
274
+ else
275
+ kids.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
276
+ end
277
+ }
278
+ end
279
+ end
280
+
265
281
  class BlockElements < Treetop::Runtime::SyntaxNode
266
282
  @@counters = {}
267
283
 
@@ -292,19 +308,9 @@ module Slaw
292
308
  id = idprefix + num.gsub(/[()]/, '')
293
309
  idprefix = id + "."
294
310
 
295
- kids = children.elements
296
- kids = [first_child] + kids if first_child and !first_child.empty?
297
-
298
311
  b.subsection(id: id) { |b|
299
312
  b.num(num)
300
- b.content { |b|
301
- if kids.empty?
302
- # schema requires a non-empty content element
303
- b.p
304
- else
305
- kids.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
306
- end
307
- }
313
+ block_elements_with_inline.to_xml(b, idprefix)
308
314
  }
309
315
  end
310
316
  end
data/lib/slaw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "3.3.2"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -222,7 +222,6 @@ baz
222
222
  two
223
223
  three
224
224
 
225
-
226
225
  |-
227
226
  |}
228
227
 
@@ -245,7 +244,6 @@ EOS
245
244
  SCHEDULE - First Schedule [[remark]]
246
245
  Subheading [[another]]
247
246
 
248
-
249
247
  Subject to approval in terms of this By-Law.
250
248
 
251
249
  '
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: 3.3.2
4
+ version: 3.4.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: 2019-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake