isodoc 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -5
  3. data/README.adoc +34 -22
  4. data/isodoc.gemspec +1 -1
  5. data/lib/isodoc.rb +3 -1
  6. data/lib/isodoc/blocks.rb +1 -1
  7. data/lib/isodoc/cleanup.rb +1 -1
  8. data/lib/isodoc/convert.rb +9 -8
  9. data/lib/isodoc/{comments.rb → htmlconvert/comments.rb} +1 -1
  10. data/lib/isodoc/htmlconvert/convert.rb +13 -0
  11. data/lib/isodoc/{footnotes.rb → htmlconvert/footnotes.rb} +1 -1
  12. data/lib/isodoc/{html.rb → htmlconvert/html.rb} +29 -4
  13. data/lib/isodoc/i18n-en.yaml +5 -5
  14. data/lib/isodoc/i18n.rb +6 -2
  15. data/lib/isodoc/inline.rb +8 -8
  16. data/lib/isodoc/iso/convert.rb +4 -0
  17. data/lib/isodoc/iso/html/style-human.scss +3 -3
  18. data/lib/isodoc/iso/html/style-iso.scss +2 -2
  19. data/lib/isodoc/iso/html/wordstyle.scss +27 -0
  20. data/lib/isodoc/iso/wordconvert.rb +5 -2
  21. data/lib/isodoc/iso2wordhtml.rb +15 -16
  22. data/lib/isodoc/lists.rb +1 -1
  23. data/lib/isodoc/metadata.rb +66 -49
  24. data/lib/isodoc/references.rb +21 -11
  25. data/lib/isodoc/section.rb +3 -3
  26. data/lib/isodoc/table.rb +1 -1
  27. data/lib/isodoc/terms.rb +1 -1
  28. data/lib/isodoc/utils.rb +20 -21
  29. data/lib/isodoc/version.rb +1 -1
  30. data/lib/isodoc/wordconvert/comments.rb +122 -117
  31. data/lib/isodoc/wordconvert/convert.rb +5 -2
  32. data/lib/isodoc/wordconvert/footnotes.rb +14 -1
  33. data/lib/isodoc/wordconvert/postprocess.rb +7 -2
  34. data/lib/isodoc/wordconvert/wordconvertmodule.rb +12 -1
  35. data/lib/isodoc/xref_gen.rb +12 -2
  36. data/lib/isodoc/xref_sect_gen.rb +5 -4
  37. data/spec/isodoc/blocks_spec.rb +1 -1
  38. data/spec/isodoc/footnotes_spec.rb +3 -3
  39. data/spec/isodoc/i18n_spec.rb +10 -10
  40. data/spec/isodoc/inline_spec.rb +2 -2
  41. data/spec/isodoc/iso_spec.rb +79 -0
  42. data/spec/isodoc/metadata_spec.rb +12 -4
  43. data/spec/isodoc/postproc_spec.rb +7 -7
  44. data/spec/isodoc/ref_spec.rb +7 -19
  45. data/spec/isodoc/section_spec.rb +19 -84
  46. data/spec/isodoc/terms_spec.rb +1 -1
  47. data/spec/isodoc/xref_spec.rb +14 -14
  48. data/spec/spec_helper.rb +3 -3
  49. metadata +9 -8
@@ -128,7 +128,7 @@ main {
128
128
  padding-right: 2em;
129
129
  }
130
130
 
131
- .WordSection1, .WordSection2 {
131
+ .title-section, .prefatory-section {
132
132
  padding-left: 4em;
133
133
  padding-top: 2em;
134
134
  }
@@ -353,7 +353,7 @@ p.Terms {
353
353
  padding: 0;
354
354
  }
355
355
 
356
- .WordSection1, .WordSection2 {
356
+ .title-section, .prefatory-section {
357
357
  padding-left: 0;
358
358
  padding-top: 0;
359
359
  width: 100%;
@@ -794,6 +794,33 @@ p.Tablebody, li.Tablebody, div.Tablebody
794
794
  mso-paper-source:0;}
795
795
  div.WordSection1
796
796
  {page:WordSection1;}
797
+ @page WordSection2
798
+ {size:595.3pt 841.9pt;
799
+ margin:39.7pt 53.85pt 1.0cm 53.85pt;
800
+ mso-header-margin:35.45pt;
801
+ mso-footer-margin:14.2pt;
802
+ mso-page-numbers:roman-lower;
803
+ mso-even-header:url("file:///C:/Doc/FILENAME_files/header.html") eh2;
804
+ mso-header:url("file:///C:/Doc/FILENAME_files/header.html") h2;
805
+ mso-even-footer:url("file:///C:/Doc/FILENAME_files/header.html") ef2;
806
+ mso-footer:url("file:///C:/Doc/FILENAME_files/header.html") f2;
807
+ mso-paper-source:0;}
808
+ div.WordSection2
809
+ {page:WordSection2;}
810
+ @page WordSection3
811
+ {size:595.3pt 841.9pt;
812
+ margin:39.7pt 53.85pt 1.0cm 53.85pt;
813
+ mso-header-margin:35.45pt;
814
+ mso-footer-margin:14.2pt;
815
+ mso-page-numbers:1;
816
+ mso-even-header:url("file:///C:/Doc/FILENAME_files/header.html") eh2;
817
+ mso-header:url("file:///C:/Doc/FILENAME_files/header.html") h2;
818
+ mso-even-footer:url("file:///C:/Doc/FILENAME_files/header.html") ef3;
819
+ mso-footer:url("file:///C:/Doc/FILENAME_files/header.html") f3;
820
+ mso-paper-source:0;}
821
+ div.WordSection3
822
+ {page:WordSection3;}
823
+
797
824
  /* List Definitions */
798
825
  @list l0
799
826
  {mso-list-id:145051656;
@@ -1,7 +1,6 @@
1
1
  module IsoDoc
2
2
  module Iso
3
- class WordConvert < IsoDoc::Convert
4
- include IsoDoc::WordConvertModule
3
+ class WordConvert < IsoDoc::WordConvert
5
4
 
6
5
  def default_fonts(options)
7
6
  b = options[:bodyfont] ||
@@ -29,6 +28,10 @@ module IsoDoc
29
28
  @olstyle = "l2"
30
29
  end
31
30
 
31
+ def implicit_reference(b)
32
+ isocode = b.at(ns("./docidentifier")).text
33
+ isocode == "IEV"
34
+ end
32
35
  end
33
36
  end
34
37
  end
@@ -1,7 +1,7 @@
1
1
  require "pp"
2
2
 
3
3
  module IsoDoc
4
- class Convert
4
+ class Common
5
5
  def set_termdomain(termdomain)
6
6
  @termdomain = termdomain
7
7
  end
@@ -49,14 +49,14 @@ module IsoDoc
49
49
  end
50
50
 
51
51
  def make_body1(body, _docxml)
52
- body.div **{ class: "WordSection1" } do |div1|
52
+ body.div **{ class: "title-section" } do |div1|
53
53
  div1.p { |p| p << "&nbsp;" } # placeholder
54
54
  end
55
55
  section_break(body)
56
56
  end
57
57
 
58
58
  def make_body2(body, docxml)
59
- body.div **{ class: "WordSection2" } do |div2|
59
+ body.div **{ class: "prefatory-section" } do |div2|
60
60
  info docxml, div2
61
61
  div2.p { |p| p << "&nbsp;" } # placeholder
62
62
  end
@@ -64,7 +64,7 @@ module IsoDoc
64
64
  end
65
65
 
66
66
  def make_body3(body, docxml)
67
- body.div **{ class: "WordSection3" } do |div3|
67
+ body.div **{ class: "main-section" } do |div3|
68
68
  foreword docxml, div3
69
69
  introduction docxml, div3
70
70
  middle docxml, div3
@@ -74,21 +74,20 @@ module IsoDoc
74
74
  end
75
75
 
76
76
  def info(isoxml, out)
77
- title isoxml, out
78
- subtitle isoxml, out
79
- docstatus isoxml, out
80
- docid isoxml, out
81
- doctype isoxml, out
82
- author isoxml, out
83
- bibdate isoxml, out
84
- relations isoxml, out
85
- version isoxml, out
86
- get_metadata
77
+ @meta.title isoxml, out
78
+ @meta.subtitle isoxml, out
79
+ @meta.docstatus isoxml, out
80
+ @meta.docid isoxml, out
81
+ @meta.doctype isoxml, out
82
+ @meta.author isoxml, out
83
+ @meta.bibdate isoxml, out
84
+ @meta.relations isoxml, out
85
+ @meta.version isoxml, out
86
+ @meta.get
87
87
  end
88
88
 
89
89
  def middle_title(out)
90
- m = get_metadata
91
- out.p **{ class: "zzSTDTitle1" } { |p| p << m[:doctitle] }
90
+ out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
92
91
  end
93
92
 
94
93
  def middle(isoxml, out)
data/lib/isodoc/lists.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
- class Convert
2
+ class Common
3
3
  def ul_parse(node, out)
4
4
  out.ul do |ul|
5
5
  node.children.each { |n| parse(n, ul) }
@@ -1,25 +1,33 @@
1
1
  require "htmlentities"
2
2
 
3
3
  module IsoDoc
4
- class Convert
4
+ class Metadata
5
5
  DATETYPES = %w{published accessed created implemented obsoleted confirmed
6
6
  updated issued}.freeze
7
7
 
8
- def init_metadata
9
- @meta = { tc: "XXXX", sc: "XXXX", wg: "XXXX",
10
- editorialgroup: [],
11
- secretariat: "XXXX",
12
- obsoletes: nil,
13
- obsoletes_part: nil }
14
- DATETYPES.each { |w| @meta["#{w}date".to_sym] = "XXX" }
8
+ def ns(xpath)
9
+ Common::ns(xpath)
15
10
  end
16
11
 
17
- def get_metadata
18
- @meta
12
+ def initialize(lang, script, labels)
13
+ @metadata = { tc: "XXXX", sc: "XXXX", wg: "XXXX",
14
+ editorialgroup: [],
15
+ secretariat: "XXXX",
16
+ obsoletes: nil,
17
+ obsoletes_part: nil }
18
+ DATETYPES.each { |w| @metadata["#{w}date".to_sym] = "XXX" }
19
+ @lang = lang
20
+ @script = script
21
+ @c = HTMLEntities.new
22
+ @labels = labels
19
23
  end
20
24
 
21
- def set_metadata(key, value)
22
- @meta[key] = value
25
+ def get
26
+ @metadata
27
+ end
28
+
29
+ def set(key, value)
30
+ @metadata[key] = value
23
31
  end
24
32
 
25
33
  def author(xml, _out)
@@ -36,8 +44,8 @@ module IsoDoc
36
44
  text || "TC"
37
45
  if tc_num
38
46
  tcid = "#{tc_type} #{tc_num.text}"
39
- set_metadata(:tc, tcid)
40
- set_metadata(:editorialgroup, get_metadata[:editorialgroup] << tcid)
47
+ set(:tc, tcid)
48
+ set(:editorialgroup, get[:editorialgroup] << tcid)
41
49
  end
42
50
  end
43
51
 
@@ -46,8 +54,8 @@ module IsoDoc
46
54
  sc_type = xml.at(ns("//editorialgroup/subcommittee/@type"))&.text || "SC"
47
55
  if sc_num
48
56
  scid = "#{sc_type} #{sc_num.text}"
49
- set_metadata(:sc, scid)
50
- set_metadata(:editorialgroup, get_metadata[:editorialgroup] << scid)
57
+ set(:sc, scid)
58
+ set(:editorialgroup, get[:editorialgroup] << scid)
51
59
  end
52
60
  end
53
61
 
@@ -56,29 +64,19 @@ module IsoDoc
56
64
  wg_type = xml.at(ns("//editorialgroup/workgroup/@type"))&.text || "WG"
57
65
  if wg_num
58
66
  wgid = "#{wg_type} #{wg_num.text}"
59
- set_metadata(:wg, wgid)
60
- set_metadata(:editorialgroup, get_metadata[:editorialgroup] << wgid)
67
+ set(:wg, wgid)
68
+ set(:editorialgroup, get[:editorialgroup] << wgid)
61
69
  end
62
70
  end
63
71
 
64
72
  def secretariat(xml)
65
73
  sec = xml.at(ns("//editorialgroup/secretariat"))
66
- set_metadata(:secretariat, sec.text) if sec
67
- end
68
-
69
- def date_range(date)
70
- from = date.at(ns("./from"))
71
- to = date.at(ns("./to"))
72
- on = date.at(ns("./on"))
73
- return on.text if on
74
- ret = "#{from.text}&ndash;"
75
- ret += to.text if to
76
- ret
74
+ set(:secretariat, sec.text) if sec
77
75
  end
78
76
 
79
77
  def bibdate(isoxml, _out)
80
78
  isoxml.xpath(ns("//bibdata/date")).each do |d|
81
- set_metadata("#{d['type']}date".to_sym, date_range(d))
79
+ set("#{d['type']}date".to_sym, Common::date_range(d))
82
80
  end
83
81
  end
84
82
 
@@ -86,7 +84,7 @@ module IsoDoc
86
84
  b = isoxml.at(ns("//bibdata")) || return
87
85
  return unless b["type"]
88
86
  t = b["type"].split(/-/).map{ |w| w.capitalize }.join(" ")
89
- set_metadata(:doctype, t)
87
+ set(:doctype, t)
90
88
  end
91
89
 
92
90
  def iso?(org)
@@ -105,7 +103,7 @@ module IsoDoc
105
103
  agency1 = abbrev || name
106
104
  agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
107
105
  end
108
- set_metadata(:agency, agency.sub(%r{/$}, ""))
106
+ set(:agency, agency.sub(%r{/$}, ""))
109
107
  end
110
108
 
111
109
  def docnumber(isoxml)
@@ -118,43 +116,62 @@ module IsoDoc
118
116
  dn
119
117
  end
120
118
 
119
+ STAGE_ABBRS = {
120
+ "00": "PWI",
121
+ "10": "NWIP",
122
+ "20": "WD",
123
+ "30": "CD",
124
+ "40": "DIS",
125
+ "50": "FDIS",
126
+ "60": "IS",
127
+ "90": "(Review)",
128
+ "95": "(Withdrawal)",
129
+ }.freeze
130
+
131
+ def stage_abbrev(stage, iter, draft)
132
+ stage = STAGE_ABBRS[stage.to_sym] || "??"
133
+ stage += iter.text if iter
134
+ stage = "Pre" + stage if draft&.text =~ /^0\./
135
+ stage
136
+ end
137
+
121
138
  def docstatus(isoxml, _out)
122
139
  docstatus = isoxml.at(ns("//status/stage"))
123
140
  if docstatus
124
- set_metadata(:stage, docstatus.text)
141
+ set(:stage, docstatus.text)
125
142
  abbr = stage_abbrev(docstatus.text, isoxml.at(ns("//status/iteration")),
126
143
  isoxml.at(ns("//version/draft")))
127
- set_metadata(:stageabbr, abbr)
144
+ set(:stageabbr, abbr)
128
145
  end
129
146
  end
130
147
 
131
148
  def docid(isoxml, _out)
132
149
  dn = docnumber(isoxml)
133
- docstatus = get_metadata[:stage]
150
+ docstatus = get[:stage]
134
151
  if docstatus
135
- abbr = get_metadata[:stageabbr]
136
- docstatus = get_metadata[:stage]
152
+ abbr = get[:stageabbr]
153
+ docstatus = get[:stage]
137
154
  (docstatus.to_i < 60) && dn = abbr + " " + dn
138
155
  end
139
- set_metadata(:docnumber, dn)
156
+ set(:docnumber, dn)
140
157
  end
141
158
 
142
159
  def draftinfo(draft, revdate)
143
160
  draftinfo = ""
144
161
  if draft
145
- draftinfo = " (#{@draft_lbl} #{draft}"
162
+ draftinfo = " (#{@labels["draft"]} #{draft}"
146
163
  draftinfo += ", #{revdate}" if revdate
147
164
  draftinfo += ")"
148
165
  end
149
- l10n(draftinfo)
166
+ Common::l10n(draftinfo, @lang, @script)
150
167
  end
151
168
 
152
169
  def version(isoxml, _out)
153
- set_metadata(:docyear, isoxml&.at(ns("//copyright/from"))&.text)
154
- set_metadata(:draft, isoxml&.at(ns("//version/draft"))&.text)
155
- set_metadata(:revdate, isoxml&.at(ns("//version/revision-date"))&.text)
156
- set_metadata(:draftinfo,
157
- draftinfo(get_metadata[:draft], get_metadata[:revdate]))
170
+ set(:docyear, isoxml&.at(ns("//copyright/from"))&.text)
171
+ set(:draft, isoxml&.at(ns("//version/draft"))&.text)
172
+ set(:revdate, isoxml&.at(ns("//version/revision-date"))&.text)
173
+ set(:draftinfo,
174
+ draftinfo(get[:draft], get[:revdate]))
158
175
  end
159
176
 
160
177
  # we don't leave this to i18n.rb, because we have both English and
@@ -186,7 +203,7 @@ module IsoDoc
186
203
  partnumber = isoxml.at(ns("//project-number/@part"))
187
204
  subpartnumber = isoxml.at(ns("//project-number/@subpart"))
188
205
  main = compose_title(main, intro, part, partnumber, subpartnumber, "en")
189
- set_metadata(:doctitle, main)
206
+ set(:doctitle, main)
190
207
  end
191
208
 
192
209
  def subtitle(isoxml, _out)
@@ -196,15 +213,15 @@ module IsoDoc
196
213
  partnumber = isoxml.at(ns("//project-number/@part"))
197
214
  subpartnumber = isoxml.at(ns("//project-number/@subpart"))
198
215
  main = compose_title(main, intro, part, partnumber, subpartnumber, "fr")
199
- set_metadata(:docsubtitle, main)
216
+ set(:docsubtitle, main)
200
217
  end
201
218
 
202
219
  def relations(isoxml, _out)
203
220
  std = isoxml.at(ns("//bibdata/relation[@type = 'obsoletes']")) || return
204
221
  locality = std.at(ns(".//locality"))
205
222
  id = std.at(ns(".//docidentifier"))
206
- set_metadata(:obsoletes, id.text) if id
207
- set_metadata(:obsoletes_part, locality.text) if locality
223
+ set(:obsoletes, id.text) if id
224
+ set(:obsoletes_part, locality.text) if locality
208
225
  end
209
226
  end
210
227
  end
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
- class Convert
2
+ class Common
3
3
  def docid_l10n(x)
4
4
  return x if x.nil?
5
5
  x.gsub(/All Parts/, @all_parts_lbl)
@@ -8,8 +8,10 @@ module IsoDoc
8
8
  def iso_bibitem_ref_code(b)
9
9
  isocode = b.at(ns("./docidentifier")).text
10
10
  isodate = b.at(ns("./date[@type = 'published']"))
11
+ iso_allparts = b.at(ns("./allParts"))
11
12
  reference = docid_l10n(isocode)
12
13
  reference += ": #{date_range(isodate)}" if isodate
14
+ reference += " (all parts)" if iso_allparts&.text == "true"
13
15
  reference
14
16
  end
15
17
 
@@ -31,12 +33,21 @@ module IsoDoc
31
33
  title.text
32
34
  end
33
35
 
36
+ # reference not to be rendered because it is deemed implicit
37
+ # in the standards environment
38
+ def implicit_reference(b)
39
+ false
40
+ end
41
+
42
+ def prefix_bracketed_ref(ref, text)
43
+ ref << "[#{text}]"
44
+ insert_tab(ref, 1)
45
+ end
46
+
34
47
  def iso_bibitem_entry(list, b, ordinal, biblio)
48
+ return if implicit_reference(b)
35
49
  list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
36
- if biblio
37
- ref << "[#{ordinal}]"
38
- insert_tab(ref, 1)
39
- end
50
+ prefix_bracketed_ref(ref, ordinal) if biblio
40
51
  ref << iso_bibitem_ref_code(b)
41
52
  date_note_process(b, ref)
42
53
  ref << ", "
@@ -46,12 +57,10 @@ module IsoDoc
46
57
 
47
58
  def ref_entry_code(r, ordinal, t)
48
59
  if /^\d+$/.match?(t)
49
- r << "[#{t}]"
50
- insert_tab(r, 1)
60
+ prefix_bracketed_ref(r, t)
51
61
  else
52
- r << "[#{ordinal}]"
53
- insert_tab(r, 1)
54
- r << "#{t},"
62
+ prefix_bracketed_ref(r, ordinal)
63
+ r << "#{t}, "
55
64
  end
56
65
  end
57
66
 
@@ -115,7 +124,8 @@ module IsoDoc
115
124
  end
116
125
 
117
126
  def norm_ref(isoxml, out, num)
118
- q = "//bibliography/references[title = 'Normative References']"
127
+ q = "//bibliography/references[title = 'Normative References' or "\
128
+ "title = 'Normative references']"
119
129
  f = isoxml.at(ns(q)) or return num
120
130
  out.div do |div|
121
131
  num = num + 1
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
- class Convert
2
+ class Common
3
3
  def inline_header_title(out, node, c1)
4
4
  out.span **{ class: "zzMoveToFollowing" } do |s|
5
5
  s.b do |b|
@@ -166,7 +166,7 @@ module IsoDoc
166
166
  # subclause
167
167
  def symbols_parse(isoxml, out)
168
168
  isoxml.children.first.previous =
169
- "<title>Symbols and Abbreviated Terms</title>"
169
+ "<title>#{@symbols_lbl}</title>"
170
170
  clause_parse(isoxml, out)
171
171
  end
172
172
 
@@ -192,7 +192,7 @@ module IsoDoc
192
192
  f = isoxml.at(ns("//foreword")) || return
193
193
  page_break(out)
194
194
  out.div **attr_code(id: f["id"]) do |s|
195
- s.h1 **{ class: "ForewordTitle" } { |h1| h1 << @foreword_lbl }
195
+ s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
196
196
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
197
197
  end
198
198
  end