isodoc 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -1
  3. data/Gemfile.lock +5 -3
  4. data/isodoc.gemspec +1 -0
  5. data/lib/isodoc.rb +1 -2
  6. data/lib/isodoc/convert.rb +3 -3
  7. data/lib/isodoc/function/i18n.rb +6 -3
  8. data/lib/isodoc/function/inline.rb +3 -4
  9. data/lib/isodoc/function/references.rb +2 -0
  10. data/lib/isodoc/function/section.rb +9 -11
  11. data/lib/isodoc/function/to_word_html.rb +1 -1
  12. data/lib/isodoc/function/xref_sect_gen.rb +22 -18
  13. data/lib/isodoc/headlesshtml_convert.rb +39 -0
  14. data/lib/isodoc/html_function/html.rb +1 -1
  15. data/lib/isodoc/metadata.rb +11 -78
  16. data/lib/isodoc/pdf_convert.rb +3 -2
  17. data/lib/isodoc/version.rb +1 -1
  18. data/lib/isodoc/word_function/postprocess.rb +1 -1
  19. data/spec/isodoc/blocks_spec.rb +2 -2
  20. data/spec/isodoc/i18n_spec.rb +8 -48
  21. data/spec/isodoc/inline_spec.rb +4 -0
  22. data/spec/isodoc/metadata_spec.rb +8 -31
  23. data/spec/isodoc/postproc_spec.rb +27 -13
  24. data/spec/isodoc/section_spec.rb +4 -24
  25. data/spec/isodoc/terms_spec.rb +8 -8
  26. data/spec/isodoc/xref_spec.rb +11 -19
  27. metadata +17 -16
  28. data/lib/isodoc/iso/html/header.html +0 -206
  29. data/lib/isodoc/iso/html/html_iso_intro.html +0 -34
  30. data/lib/isodoc/iso/html/html_iso_titlepage.html +0 -34
  31. data/lib/isodoc/iso/html/htmlstyle.scss +0 -46
  32. data/lib/isodoc/iso/html/isodoc.scss +0 -696
  33. data/lib/isodoc/iso/html/scripts.html +0 -174
  34. data/lib/isodoc/iso/html/style-human.scss +0 -1277
  35. data/lib/isodoc/iso/html/style-iso.scss +0 -1257
  36. data/lib/isodoc/iso/html/word_iso_intro.html +0 -72
  37. data/lib/isodoc/iso/html/word_iso_titlepage.html +0 -62
  38. data/lib/isodoc/iso/html/wordstyle.scss +0 -1175
  39. data/lib/isodoc/iso/html_convert.rb +0 -50
  40. data/lib/isodoc/iso/word_convert.rb +0 -53
  41. data/spec/isodoc/iso_spec.rb +0 -168
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7021ada69c40cacdfa9a54827a70bf9a949ea194a75c5a9bc9818cc76d458b95
4
- data.tar.gz: 2f046c37b8094b3288f257f22e7efea00513bdafc09b6f9b2fa1ec4848a9bbe8
3
+ metadata.gz: dede2446b862431d30638a1f7f05f1048d70b153a343bd5e0ebc021a35f34f83
4
+ data.tar.gz: bef3d35e5e3e09a384768c961e4360dab94ec5760a090876ee8754b924c8a3a7
5
5
  SHA512:
6
- metadata.gz: 0ae6effbeb78bce850bfe83a84bb311509e9f2f04ad7627e64f69c020974c6c6977768302b14ee13c5515f2da497dae17021aa9596e4525f58878e9b65b5d7a1
7
- data.tar.gz: ccb84fc0e38711603a797dfa2560d3066291122c6a9fc6b1f71407999936a06e24611f075df121115025af70800a0cbd4008f346c22807564c587433f5edcc7b
6
+ metadata.gz: ed5cc8a8cd5fe504f7c6696e905e650840017b358d0d99d90546bed01397cfe7217d19c6a1e852368dc846044fc0a3467229abdd3285ffeedf966d624c162b44
7
+ data.tar.gz: 1523ac224ab7527eefe744e352aff22c746fbbc52689b451590a38b62c41c317afb6b4594c2f4ea7e8f9b4ea914144dedd4394cd68a50dbf16f6d607cd889e12
data/.travis.yml CHANGED
@@ -6,7 +6,10 @@ rvm:
6
6
  - 2.4
7
7
  - ruby-head
8
8
 
9
- before_install: gem install bundler -v 1.16.2
9
+ before_install:
10
+ - gem install bundler -v 1.16.2
11
+ - npm install -g puppeteer
12
+ - npm install
10
13
 
11
14
  matrix:
12
15
  allow_failures:
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- isodoc (0.8.3)
4
+ isodoc (0.8.5)
5
5
  asciimath
6
6
  html2doc (~> 0.8.1)
7
7
  htmlentities (~> 4.3.4)
8
8
  liquid
9
+ metanorma (~> 0.2.6)
9
10
  nokogiri
10
11
  roman-numerals
11
12
  ruby-xslt
@@ -16,7 +17,7 @@ PATH
16
17
  GEM
17
18
  remote: https://rubygems.org/
18
19
  specs:
19
- asciimath (1.0.4)
20
+ asciimath (1.0.5)
20
21
  ast (2.4.0)
21
22
  byebug (9.1.0)
22
23
  coderay (1.1.2)
@@ -59,6 +60,7 @@ GEM
59
60
  rb-inotify (~> 0.9, >= 0.9.7)
60
61
  ruby_dep (~> 1.2)
61
62
  lumberjack (1.0.13)
63
+ metanorma (0.2.6)
62
64
  method_source (0.9.0)
63
65
  mime-types (3.1)
64
66
  mime-types-data (~> 3.2015)
@@ -107,7 +109,7 @@ GEM
107
109
  ruby-progressbar (1.9.0)
108
110
  ruby-xslt (0.9.10)
109
111
  ruby_dep (1.5.0)
110
- sass (3.5.6)
112
+ sass (3.5.7)
111
113
  sass-listen (~> 4.0.0)
112
114
  sass-listen (4.0.0)
113
115
  rb-fsevent (~> 0.9, >= 0.9.4)
data/isodoc.gemspec CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "liquid"
39
39
  spec.add_dependency "roman-numerals"
40
40
  spec.add_dependency "sass"
41
+ spec.add_dependency "metanorma", "~> 0.2.6"
41
42
 
42
43
  spec.add_development_dependency "bundler", "~> 1.15"
43
44
  spec.add_development_dependency "byebug", "~> 9.1"
data/lib/isodoc.rb CHANGED
@@ -20,8 +20,7 @@ require "isodoc/metadata"
20
20
  require "isodoc/html_convert"
21
21
  require "isodoc/word_convert"
22
22
  require "isodoc/pdf_convert"
23
- require "isodoc/iso/html_convert"
24
- require "isodoc/iso/word_convert"
23
+ require "isodoc/headlesshtml_convert"
25
24
 
26
25
  module IsoDoc
27
26
 
@@ -62,7 +62,7 @@ module IsoDoc
62
62
  stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
63
63
  engine = Sass::Engine.new(fontheader + stylesheet, syntax: :scss)
64
64
  outname = File.basename(filename, ".*") + ".css"
65
- File.open(outname, "w") { |f| f.write(engine.render) }
65
+ File.open(outname, "w:UTF-8") { |f| f.write(engine.render) }
66
66
  @files_to_delete << outname
67
67
  outname
68
68
  end
@@ -86,8 +86,8 @@ module IsoDoc
86
86
  docxml = Nokogiri::XML(file)
87
87
  filename, dir = init_file(filename, debug)
88
88
  docxml.root.default_namespace = ""
89
- lang = docxml&.at(ns("//bibdata/language"))&.text || "en"
90
- script = docxml&.at(ns("//bibdata/script"))&.text || "Latn"
89
+ lang = docxml&.at(ns("//bibdata/language"))&.text || @lang
90
+ script = docxml&.at(ns("//bibdata/script"))&.text || @script
91
91
  i18n_init(lang, script)
92
92
  metadata_init(lang, script, @labels)
93
93
  [docxml, filename, dir]
@@ -9,14 +9,17 @@ module IsoDoc::Function
9
9
  y = if @i18nyaml
10
10
  YAML.load_file(@i18nyaml)
11
11
  elsif lang == "en"
12
- YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-en.yaml"))
12
+ YAML.load_file(File.join(File.dirname(__FILE__),
13
+ "../../isodoc-yaml/i18n-en.yaml"))
13
14
  elsif lang == "fr"
14
- YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-fr.yaml"))
15
+ YAML.load_file(File.join(File.dirname(__FILE__),
16
+ "../../isodoc-yaml/i18n-fr.yaml"))
15
17
  elsif lang == "zh" && script == "Hans"
16
18
  YAML.load_file(File.join(File.dirname(__FILE__),
17
19
  "../../isodoc-yaml/i18n-zh-Hans.yaml"))
18
20
  else
19
- YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-en.yaml"))
21
+ YAML.load_file(File.join(File.dirname(__FILE__),
22
+ "../../isodoc-yaml/i18n-en.yaml"))
20
23
  end
21
24
  @term_def_boilerplate = y["term_def_boilerplate"]
22
25
  @scope_lbl = y["scope"]
@@ -9,11 +9,9 @@ module IsoDoc::Function
9
9
  end
10
10
 
11
11
  def link_parse(node, out)
12
- linktext = node.text
13
- linktext = node["target"] if linktext.empty?
14
12
  out.a(**{ "href": node["target"] }) do |l|
15
13
  if node.text.empty?
16
- l << linktext
14
+ l << node["target"].sub(/^mailto:/, "")
17
15
  else
18
16
  node.children.each { |n| parse(n, l) }
19
17
  end
@@ -25,7 +23,8 @@ module IsoDoc::Function
25
23
  end
26
24
 
27
25
  def anchor_linkend(node, linkend)
28
- if node["citeas"].nil? && node["bibitemid"] && get_anchors.has_key?(node["bibitemid"])
26
+ if node["citeas"].nil? && node["bibitemid"] &&
27
+ get_anchors.has_key?(node["bibitemid"])
29
28
  return get_anchors[node["bibitemid"]][:xref]
30
29
  elsif node["target"] && get_anchors.has_key?(node["target"])
31
30
  linkend = get_anchors[node["target"]][:xref]
@@ -1,6 +1,8 @@
1
1
  module IsoDoc::Function
2
2
  module References
3
3
 
4
+ # This is highly specific to ISO, but it's not a bad precedent for
5
+ # references anyway; keeping here instead of in IsoDoc::Iso for now
4
6
  def docid_l10n(x)
5
7
  return x if x.nil?
6
8
  x.gsub(/All Parts/, @all_parts_lbl)
@@ -1,10 +1,13 @@
1
1
  module IsoDoc::Function
2
2
  module Section
3
-
4
3
  def inline_header_title(out, node, c1)
5
4
  out.span **{ class: "zzMoveToFollowing" } do |s|
6
5
  s.b do |b|
7
- b << "#{get_anchors[node['id']][:label]}. #{c1.content} "
6
+ if get_anchors[node['id']][:label]
7
+ b << "#{get_anchors[node['id']][:label]}. #{c1.content} "
8
+ else
9
+ b << "#{c1.content} "
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -14,7 +17,8 @@ module IsoDoc::Function
14
17
  inline_header_title(out, node, c1)
15
18
  else
16
19
  div.send "h#{get_anchors[node['id']][:level]}" do |h|
17
- h << "#{get_anchors[node['id']][:label]}. "
20
+ lbl = get_anchors[node['id']][:label]
21
+ h << "#{lbl}. " if lbl
18
22
  c1.children.each { |c2| parse(c2, h) }
19
23
  end
20
24
  end
@@ -173,18 +177,12 @@ module IsoDoc::Function
173
177
 
174
178
  def introduction(isoxml, out)
175
179
  f = isoxml.at(ns("//introduction")) || return
176
- num = f.at(ns(".//clause")) ? "0." : nil
177
180
  title_attr = { class: "IntroTitle" }
178
181
  page_break(out)
179
182
  out.div **{ class: "Section3", id: f["id"] } do |div|
180
- # div.h1 "Introduction", **attr_code(title_attr)
181
- clause_name(num, @introduction_lbl, div, title_attr)
183
+ clause_name(nil, @introduction_lbl, div, title_attr)
182
184
  f.elements.each do |e|
183
- if e.name == "patent-notice"
184
- e.elements.each { |e1| parse(e1, div) }
185
- else
186
- parse(e, div) unless e.name == "title"
187
- end
185
+ parse(e, div) unless e.name == "title"
188
186
  end
189
187
  end
190
188
  end
@@ -137,7 +137,7 @@ module IsoDoc::Function
137
137
  when "stem" then stem_parse(node, out)
138
138
  when "clause" then clause_parse(node, out)
139
139
  # when "subclause" then clause_parse(node, out)
140
- when "appendix" then clause_parse(node, out)
140
+ #when "appendix" then clause_parse(node, out)
141
141
  when "xref" then xref_parse(node, out)
142
142
  when "eref" then eref_parse(node, out)
143
143
  when "origin" then eref_parse(node, out)
@@ -1,6 +1,5 @@
1
1
  module IsoDoc::Function
2
2
  module XrefSectGen
3
-
4
3
  def back_anchor_names(docxml)
5
4
  docxml.xpath(ns("//annex")).each_with_index do |c, i|
6
5
  annex_names(c, (65 + i).chr.to_s)
@@ -11,7 +10,8 @@ module IsoDoc::Function
11
10
  end
12
11
 
13
12
  def initial_anchor_names(d)
14
- introduction_names(d.at(ns("//introduction")))
13
+ preface_names(d.at(ns("//foreword")))
14
+ preface_names(d.at(ns("//introduction")))
15
15
  n = 0
16
16
  n = section_names(d.at(ns("//clause[title = 'Scope']")), n, 1)
17
17
  n = section_names(d.at(ns(
@@ -25,6 +25,25 @@ module IsoDoc::Function
25
25
  termexample_anchor_names(d)
26
26
  end
27
27
 
28
+ # in StanDoc, prefaces have no numbering; they are referenced only by title
29
+ def preface_names(clause)
30
+ return if clause.nil?
31
+ clause.xpath(ns("./clause")).each_with_index do |c, i|
32
+ preface_names1(c, c.at(ns("./title"))&.text, "#{clause.at(ns('./title'))&.text}, #{i+1}", 2)
33
+ end
34
+ end
35
+
36
+ def preface_names1(clause, title, parent_title, level)
37
+ label = title || parent_title
38
+ @anchors[clause["id"]] =
39
+ { label: nil, level: level, xref: label }
40
+ # subclauses are not prefixed with "Clause"
41
+ clause.xpath(ns("./clause | ./terms | ./term | ./definitions")).
42
+ each_with_index do |c, i|
43
+ preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i+1}", level + 1)
44
+ end
45
+ end
46
+
28
47
  def middle_section_asset_names(d)
29
48
  middle_sections = "//clause[title = 'Scope'] | "\
30
49
  "//foreword | //introduction | "\
@@ -42,13 +61,6 @@ module IsoDoc::Function
42
61
  end
43
62
  end
44
63
 
45
- def introduction_names(clause)
46
- return if clause.nil?
47
- clause.xpath(ns("./clause")).each_with_index do |c, i|
48
- section_names1(c, "0.#{i + 1}", 2)
49
- end
50
- end
51
-
52
64
  def section_names(clause, num, lvl)
53
65
  return num if clause.nil?
54
66
  num = num + 1
@@ -83,7 +95,7 @@ module IsoDoc::Function
83
95
  clause.xpath(ns("./clause")).each_with_index do |c, i|
84
96
  annex_names1(c, "#{num}.#{i + 1}", 2)
85
97
  end
86
- appendix_names(clause, num)
98
+ #appendix_names(clause, num)
87
99
  hierarchical_asset_names(clause, num)
88
100
  end
89
101
 
@@ -93,13 +105,5 @@ module IsoDoc::Function
93
105
  annex_names1(c, "#{num}.#{i + 1}", level + 1)
94
106
  end
95
107
  end
96
-
97
- def appendix_names(clause, num)
98
- clause.xpath(ns("./appendix")).each_with_index do |c, i|
99
- @anchors[c["id"]] = anchor_struct(i + 1, nil, @appendix_lbl)
100
- @anchors[c["id"]][:level] = 2
101
- @anchors[c["id"]][:container] = clause["id"]
102
- end
103
- end
104
108
  end
105
109
  end
@@ -0,0 +1,39 @@
1
+ require_relative "html_function/comments.rb"
2
+ require_relative "html_function/footnotes.rb"
3
+ require_relative "html_function/html.rb"
4
+
5
+ module IsoDoc
6
+ class HeadlessHtmlConvert < ::IsoDoc::Convert
7
+
8
+ include HtmlFunction::Comments
9
+ include HtmlFunction::Footnotes
10
+ include HtmlFunction::Html
11
+
12
+ def initialize(options)
13
+ super
14
+ @tmpimagedir = "_headlessimages"
15
+ end
16
+
17
+ def convert(filename, file = nil, debug = false)
18
+ file = File.read(filename, encoding: "utf-8") if file.nil?
19
+ @openmathdelim, @closemathdelim = extract_delims(file)
20
+ docxml, outname_html, dir = convert_init(file, filename, debug)
21
+ result = convert1(docxml, outname_html, dir)
22
+ return result if debug
23
+ postprocess(result, filename + ".tmp", dir)
24
+ system "rm -fr #{dir}"
25
+ strip_head(filename + ".tmp.html", outname_html + ".headless.html")
26
+ system "rm -r #{filename + '.tmp.html'} #{@tmpimagedir}"
27
+ end
28
+
29
+ def strip_head(input, output)
30
+ file = File.read(input, encoding: "utf-8")
31
+ doc = Nokogiri::XML(file)
32
+ doc.xpath("//head").each { |x| x.remove }
33
+ doc.xpath("//html").each { |x| x.name = "div" }
34
+ body = doc.at("//body")
35
+ body.replace(body.children)
36
+ File.open(output, "w") { |f| f.write(doc.to_xml) }
37
+ end
38
+ end
39
+ end
@@ -41,7 +41,7 @@ module IsoDoc::HtmlFunction
41
41
  def toHTML(result, filename)
42
42
  result = script_cdata(from_xhtml(html_cleanup(to_xhtml(result))))
43
43
  result = populate_template(result, :html)
44
- File.open("#{filename}.html", "w") do |f|
44
+ File.open("#{filename}.html", "w:UTF-8") do |f|
45
45
  f.write(result)
46
46
  end
47
47
  end
@@ -121,43 +121,22 @@ module IsoDoc
121
121
  dn
122
122
  end
123
123
 
124
- STAGE_ABBRS = {
125
- "00": "PWI",
126
- "10": "NWIP",
127
- "20": "WD",
128
- "30": "CD",
129
- "40": "DIS",
130
- "50": "FDIS",
131
- "60": "IS",
132
- "90": "(Review)",
133
- "95": "(Withdrawal)",
134
- }.freeze
135
-
136
- def stage_abbrev(stage, iter, draft)
137
- stage = STAGE_ABBRS[stage.to_sym] || "??"
138
- stage += iter.text if iter
139
- stage = "Pre" + stage if draft&.text =~ /^0\./
140
- stage
141
- end
142
-
143
124
  def docstatus(isoxml, _out)
144
- docstatus = isoxml.at(ns("//status/stage"))
125
+ docstatus = isoxml.at(ns("//bibdata/status"))
145
126
  if docstatus
146
- set(:stage, docstatus.text)
147
- set(:stage_int, docstatus.text.to_i)
148
- abbr = stage_abbrev(docstatus.text, isoxml.at(ns("//status/iteration")),
149
- isoxml.at(ns("//version/draft")))
150
- set(:stageabbr, abbr)
127
+ set(:status, status_print(docstatus.text))
151
128
  end
152
129
  end
153
130
 
131
+ def status_print(status)
132
+ status.split(/-/).map{ |w| w.capitalize }.join(" ")
133
+ end
134
+
154
135
  def docid(isoxml, _out)
155
136
  dn = docnumber(isoxml)
156
- docstatus = get[:stage]
157
- if docstatus
158
- abbr = get[:stageabbr]
159
- docstatus = get[:stage]
160
- (docstatus.to_i < 60) && dn = abbr + " " + dn
137
+ docstatus = get[:status]
138
+ if docstatus && docstatus != "Published"
139
+ dn = "#{dn} #{docstatus}"
161
140
  end
162
141
  set(:docnumber, dn)
163
142
  end
@@ -180,59 +159,13 @@ module IsoDoc
180
159
  draftinfo(get[:draft], get[:revdate]))
181
160
  end
182
161
 
183
- # we don't leave this to i18n.rb, because we have both English and
184
- # French titles in the same document
185
- def part_label(lang)
186
- case lang
187
- when "en" then "Part"
188
- when "fr" then "Partie"
189
- end
190
- end
191
-
192
- def part_title(part, partnum, subpartnum, lang)
193
- return "" unless part
194
- suffix = @c.encode(part.text, :hexadecimal)
195
- partnum = "#{partnum}&ndash;#{subpartnum}" if partnum && subpartnum
196
- suffix = "#{part_label(lang)}&nbsp;#{partnum}: " + suffix if partnum
197
- suffix
198
- end
199
-
200
- def compose_title(main, intro, part, partnum, subpartnum, lang)
201
- main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
202
- intro &&
203
- main = "#{@c.encode(intro.text, :hexadecimal)}&nbsp;&mdash; #{main}"
204
- if part
205
- suffix = part_title(part, partnum, subpartnum, lang)
206
- main = "#{main}&nbsp;&mdash; #{suffix}"
207
- end
208
- main
209
- end
210
-
211
162
  def title(isoxml, _out)
212
- intro = isoxml.at(ns("//title-intro[@language='en']"))
213
- main = isoxml.at(ns("//title-main[@language='en']"))
214
- part = isoxml.at(ns("//title-part[@language='en']"))
215
- partnumber = isoxml.at(ns("//project-number/@part"))
216
- subpartnumber = isoxml.at(ns("//project-number/@subpart"))
217
-
218
- set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
219
- main = compose_title(main, intro, part, partnumber, subpartnumber, "en")
163
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
220
164
  set(:doctitle, main)
221
- set(:doctitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
222
- set(:doctitlepart, part_title(part, partnumber, subpartnumber, "en"))
223
165
  end
224
166
 
225
167
  def subtitle(isoxml, _out)
226
- intro = isoxml.at(ns("//title-intro[@language='fr']"))
227
- main = isoxml.at(ns("//title-main[@language='fr']"))
228
- part = isoxml.at(ns("//title-part[@language='fr']"))
229
- partnumber = isoxml.at(ns("//project-number/@part"))
230
- subpartnumber = isoxml.at(ns("//project-number/@subpart"))
231
- set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
232
- main = compose_title(main, intro, part, partnumber, subpartnumber, "fr")
233
- set(:docsubtitle, main)
234
- set(:docsubtitleintro, @c.encode(intro ? intro.text : "", :hexadecimal)) if intro
235
- set(:docsubtitlepart, part_title(part, partnumber, subpartnumber, "fr"))
168
+ nil
236
169
  end
237
170
 
238
171
  def relations(isoxml, _out)