isodoc 0.9.10 → 0.9.11

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
  SHA256:
3
- metadata.gz: 3369c7722ffc0923f81c46088f759c811375571e062877a7bfbf2d06f2bb126b
4
- data.tar.gz: 6112987ce5342f328f9c2cf376636258b5700f0eff46ee0297992339b46b8578
3
+ metadata.gz: '00160137956d6bf94a5ae197a7cb4b88ad74c0a4c60b421cb37bbe23abe8cd31'
4
+ data.tar.gz: aaeb75e3aecc1cf19729b046332dcab2ca732357f08c22f2631eddf65ec5bf5f
5
5
  SHA512:
6
- metadata.gz: 1dab35da108b9168fa49e32a36632a8781e9046cd65a066ea42a4fd6de82e7d7596ae000c33bb0ddd3c450541cbe749b5f97c9ed56f9bf12ffc1ecb7ad44f129
7
- data.tar.gz: 5fb411b350d0792a908d2444ad37f2d40ac8728d39943fe7925d6a7939949d635250434217d58f37c15cf37e0facca020de6af441ad91605e0365875f57c61e1
6
+ metadata.gz: f2ebe7192825e49355716ec580fc6da530d48475a6da2a9d4896c0a7d36927967b02f0f1f1a1cc198d91f0f4a1839d257bdc1b9d6e4d0b73ecc288ee08db3709
7
+ data.tar.gz: 01e04c0e9c669c5d6746fc5618f517bda045258202e234550223d37180d4db5d2dea873df2e651733f64cbf942d7963b5d4634a236f7e21949ee4467c536dcf1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- isodoc (0.9.10)
4
+ isodoc (0.9.11)
5
5
  asciimath
6
6
  html2doc (~> 0.8.6)
7
7
  htmlentities (~> 4.3.4)
@@ -61,7 +61,7 @@ GEM
61
61
  rb-inotify (~> 0.9, >= 0.9.7)
62
62
  ruby_dep (~> 1.2)
63
63
  lumberjack (1.0.13)
64
- metanorma (0.3.1)
64
+ metanorma (0.3.2)
65
65
  method_source (0.9.2)
66
66
  mime-types (3.2.2)
67
67
  mime-types-data (~> 3.2015)
@@ -3,24 +3,27 @@ require "yaml"
3
3
  # TODO: Cleanup and generalize
4
4
  module IsoDoc::Function
5
5
  module I18n
6
+ def load_yaml(lang, script)
7
+ if @i18nyaml then YAML.load_file(@i18nyaml)
8
+ elsif lang == "en"
9
+ YAML.load_file(File.join(File.dirname(__FILE__),
10
+ "../../isodoc-yaml/i18n-en.yaml"))
11
+ elsif lang == "fr"
12
+ YAML.load_file(File.join(File.dirname(__FILE__),
13
+ "../../isodoc-yaml/i18n-fr.yaml"))
14
+ elsif lang == "zh" && script == "Hans"
15
+ YAML.load_file(File.join(File.dirname(__FILE__),
16
+ "../../isodoc-yaml/i18n-zh-Hans.yaml"))
17
+ else
18
+ YAML.load_file(File.join(File.dirname(__FILE__),
19
+ "../../isodoc-yaml/i18n-en.yaml"))
20
+ end
21
+ end
22
+
6
23
  def i18n_init(lang, script)
7
24
  @lang = lang
8
25
  @script = script
9
- y = if @i18nyaml
10
- YAML.load_file(@i18nyaml)
11
- elsif lang == "en"
12
- YAML.load_file(File.join(File.dirname(__FILE__),
13
- "../../isodoc-yaml/i18n-en.yaml"))
14
- elsif lang == "fr"
15
- YAML.load_file(File.join(File.dirname(__FILE__),
16
- "../../isodoc-yaml/i18n-fr.yaml"))
17
- elsif lang == "zh" && script == "Hans"
18
- YAML.load_file(File.join(File.dirname(__FILE__),
19
- "../../isodoc-yaml/i18n-zh-Hans.yaml"))
20
- else
21
- YAML.load_file(File.join(File.dirname(__FILE__),
22
- "../../isodoc-yaml/i18n-en.yaml"))
23
- end
26
+ y = load_yaml(lang, script)
24
27
  @term_def_boilerplate = y["term_def_boilerplate"]
25
28
  @scope_lbl = y["scope"]
26
29
  @symbols_lbl = y["symbols"]
@@ -50,8 +50,9 @@ module IsoDoc::Function
50
50
  end
51
51
 
52
52
  def xref_parse(node, out)
53
- linkend = get_linkend(node)
54
- out.a(**{ "href": "#" + node["target"] }) { |l| l << linkend }
53
+ target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".html#") :
54
+ "##{node["target"]}"
55
+ out.a(**{ "href": target }) { |l| l << get_linkend(node) }
55
56
  end
56
57
 
57
58
  def eref_localities(refs, target)
@@ -93,6 +93,7 @@ module IsoDoc::Function
93
93
  @meta.bibdate isoxml, out
94
94
  @meta.relations isoxml, out
95
95
  @meta.version isoxml, out
96
+ @meta.url isoxml, out
96
97
  @meta.get
97
98
  end
98
99
 
@@ -128,6 +129,12 @@ module IsoDoc::Function
128
129
  out.a **attr_code(id: node["id"])
129
130
  end
130
131
 
132
+ def keyword_parse(node, out)
133
+ out.span **{ class: "keyword" } do |s|
134
+ s << node.inner_html
135
+ end
136
+ end
137
+
131
138
  def parse(node, out)
132
139
  if node.text?
133
140
  text_parse(node, out)
@@ -139,6 +146,7 @@ module IsoDoc::Function
139
146
  when "sub" then out.sub { |e| e << node.inner_html }
140
147
  when "tt" then out.tt { |e| e << node.inner_html }
141
148
  when "strike" then out.s { |e| e << node.inner_html }
149
+ when "keyword" then keyword_parse(node, out)
142
150
  when "smallcap" then smallcap_parse(node, out)
143
151
  when "br" then out.br
144
152
  when "hr" then out.hr
@@ -221,7 +221,22 @@ module IsoDoc::HtmlFunction
221
221
  i["width"], i["height"] = Html2Doc.image_resize(i, local_filename, @maxheight, @maxwidth)
222
222
  end
223
223
 
224
+ def html_toc_entry(level, header)
225
+ %(<li class="h#{level}"><a href="##{header['id']}">#{header_strip(header)}</a></li>)
226
+ end
227
+
224
228
  def html_toc(docxml)
229
+ =begin
230
+ idx = docxml.at("//div[@id = 'toc']") or return docxml
231
+ toc = "<ul>"
232
+ tocidx = 0
233
+ docxml.xpath("//main//h1 | //main//h2[not(@class = 'TermNum')]").each do |h|
234
+ h["id"] ||= "toc#{tocidx}"
235
+ toc += html_toc_entry(h.name == "h1" ? 1 : 2, h)
236
+ tocidx += 1
237
+ end
238
+ idx.children = "#{toc}</ul>"
239
+ =end
225
240
  docxml
226
241
  end
227
242
  end
@@ -1,7 +1,7 @@
1
1
  module IsoDoc
2
2
  class Metadata
3
3
  DATETYPES = %w{published accessed created implemented obsoleted confirmed
4
- updated issued}.freeze
4
+ updated issued received}.freeze
5
5
 
6
6
  def ns(xpath)
7
7
  Common::ns(xpath)
@@ -113,11 +113,17 @@ module IsoDoc
113
113
 
114
114
  def docstatus(isoxml, _out)
115
115
  docstatus = isoxml.at(ns("//bibdata/status"))
116
+ set(:unpublished, true)
116
117
  if docstatus
117
118
  set(:status, status_print(docstatus.text))
119
+ set(:unpublished, unpublished(docstatus.text))
118
120
  end
119
121
  end
120
122
 
123
+ def unpublished(status)
124
+ status.downcase == "published"
125
+ end
126
+
121
127
  def status_print(status)
122
128
  status.split(/-/).map{ |w| w.capitalize }.join(" ")
123
129
  end
@@ -161,5 +167,13 @@ module IsoDoc
161
167
  set(:obsoletes, id.text) if id
162
168
  set(:obsoletes_part, locality.text) if locality
163
169
  end
170
+
171
+ def url(xml, _out)
172
+ a = xml.at(ns("//bibdata/source[not(@type)]")) and set(:url, a.text)
173
+ a = xml.at(ns("//bibdata/source[@type = 'html']")) and set(:html, a.text)
174
+ a = xml.at(ns("//bibdata/source[@type = 'xml']")) and set(:xml, a.text)
175
+ a = xml.at(ns("//bibdata/source[@type = 'pdf']")) and set(:pdf, a.text)
176
+ a = xml.at(ns("//bibdata/source[@type = 'doc']")) and set(:doc, a.text)
177
+ end
164
178
  end
165
179
  end
@@ -30,5 +30,11 @@ module IsoDoc
30
30
  ::Metanorma::Output::Pdf.new.convert(filename + ".html", outname_html + ".pdf")
31
31
  FileUtils.rm_r ["#{filename}.html", tmpimagedir]
32
32
  end
33
+
34
+ def xref_parse(node, out)
35
+ target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".pdf#") :
36
+ "##{node["target"]}"
37
+ out.a(**{ "href": target }) { |l| l << get_linkend(node) }
38
+ end
33
39
  end
34
40
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "0.9.10".freeze
2
+ VERSION = "0.9.11".freeze
3
3
  end
@@ -202,5 +202,11 @@ module IsoDoc::WordFunction
202
202
  out.img **attr_code(attrs)
203
203
  image_title_parse(out, caption)
204
204
  end
205
+
206
+ def xref_parse(node, out)
207
+ target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".doc#") :
208
+ "##{node["target"]}"
209
+ out.a(**{ "href": target }) { |l| l << get_linkend(node) }
210
+ end
205
211
  end
206
212
  end
@@ -7,7 +7,7 @@ RSpec.describe IsoDoc do
7
7
  <preface><foreword>
8
8
  <p>
9
9
  <em>A</em> <strong>B</strong> <sup>C</sup> <sub>D</sub> <tt>E</tt>
10
- <strike>F</strike> <smallcap>G</smallcap> <br/> <hr/>
10
+ <strike>F</strike> <smallcap>G</smallcap> <keyword>I</keyword> <br/> <hr/>
11
11
  <bookmark id="H"/> <pagebreak/>
12
12
  </p>
13
13
  </foreword></preface>
@@ -20,7 +20,7 @@ RSpec.describe IsoDoc do
20
20
  <h1 class="ForewordTitle">Foreword</h1>
21
21
  <p>
22
22
  <i>A</i> <b>B</b> <sup>C</sup> <sub>D</sub> <tt>E</tt>
23
- <s>F</s> <span style="font-variant:small-caps;">G</span> <br/> <hr/>
23
+ <s>F</s> <span style="font-variant:small-caps;">G</span> <span class="keyword">I</span> <br/> <hr/>
24
24
  <a id="H"/> <br/>
25
25
  </p>
26
26
  </div>
@@ -12,6 +12,11 @@ RSpec.describe IsoDoc do
12
12
  <bibdata type="international-standard">
13
13
  <title>The Incredible Mr Ripley</title>
14
14
  <title language="en">Cereals and pulses</title>
15
+ <source>URL A</source>
16
+ <source type="html">URL B</source>
17
+ <source type="xml">URL C</source>
18
+ <source type="pdf">URL D</source>
19
+ <source type="doc">URL E</source>
15
20
  <docidentifier>17301-1</docidentifier>
16
21
  <docnumber>17301</docnumber>
17
22
  <date type="published"><on>2011</on></date>
@@ -55,7 +60,7 @@ RSpec.describe IsoDoc do
55
60
  </version>
56
61
  </iso-standard>
57
62
  INPUT
58
- {:accesseddate=>"2012", :activateddate=>"2013", :agency=>"ISO", :confirmeddate=>"XXX", :createddate=>"2010&ndash;2011", :docnumber=>"17301-1", :doctitle=>"Cereals and pulses", :doctype=>"International Standard", :docyear=>"2016", :draft=>"0.4", :draftinfo=>" (draft 0.4, 2016-05-01)", :editorialgroup=>["TC 34", "SC 4", "WG 3"], :ics=>"XXX", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"2014", :obsoletes=>nil, :obsoletes_part=>nil, :publisheddate=>"2011", :revdate=>"2016-05-01", :sc=>"SC 4", :secretariat=>"GB", :status=>"Committee draft", :tc=>"TC 34", :updateddate=>"XXX", :wg=>"WG 3"}
63
+ {:accesseddate=>"2012", :activateddate=>"2013", :agency=>"ISO", :confirmeddate=>"XXX", :createddate=>"2010&ndash;2011", :doc=>"URL E", :docnumber=>"17301-1", :doctitle=>"Cereals and pulses", :doctype=>"International Standard", :docyear=>"2016", :draft=>"0.4", :draftinfo=>" (draft 0.4, 2016-05-01)", :editorialgroup=>["TC 34", "SC 4", "WG 3"], :html=>"URL B", :ics=>"XXX", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"2014", :obsoletes=>nil, :obsoletes_part=>nil, :pdf=>"URL D", :publisheddate=>"2011", :receiveddate=>"XXX", :revdate=>"2016-05-01", :sc=>"SC 4", :secretariat=>"GB", :status=>"Committee draft", :tc=>"TC 34", :unpublished=>false, :updateddate=>"XXX", :url=>"URL A", :wg=>"WG 3", :xml=>"URL C"}
59
64
  OUTPUT
60
65
  end
61
66
 
@@ -118,7 +123,7 @@ OUTPUT
118
123
  </version>
119
124
  </iso-standard>
120
125
  INPUT
121
- {:accesseddate=>"XXX", :agency=>"ISO/IEC", :confirmeddate=>"XXX", :createddate=>"XXX", :docnumber=>"17301-1-3", :doctitle=>"Cereals and pulses", :doctype=>"International Standard", :docyear=>"2016", :draft=>"12", :draftinfo=>" (draft 12, 2016-05-01)", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"XXX", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisheddate=>"XXX", :revdate=>"2016-05-01", :sc=>"DEF 4", :secretariat=>"XXXX", :status=>"Published", :tc=>"ABC 34", :updateddate=>"XXX", :wg=>"GHI 3"}
126
+ {:accesseddate=>"XXX", :agency=>"ISO/IEC", :confirmeddate=>"XXX", :createddate=>"XXX", :docnumber=>"17301-1-3", :doctitle=>"Cereals and pulses", :doctype=>"International Standard", :docyear=>"2016", :draft=>"12", :draftinfo=>" (draft 12, 2016-05-01)", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :implementeddate=>"XXX", :issueddate=>"XXX", :obsoleteddate=>"XXX", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisheddate=>"XXX", :receiveddate=>"XXX", :revdate=>"2016-05-01", :sc=>"DEF 4", :secretariat=>"XXXX", :status=>"Published", :tc=>"ABC 34", :unpublished=>true, :updateddate=>"XXX", :wg=>"GHI 3"}
122
127
  OUTPUT
123
128
  end
124
129
 
@@ -1,6 +1,57 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe IsoDoc do
4
+ it "cross-references external documents in HTML" do
5
+ expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
6
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
7
+ <preface>
8
+ <foreword>
9
+ <p>
10
+ <xref target="a#b"/>
11
+ </p>
12
+ </foreword>
13
+ </preface>
14
+ </iso-standard
15
+ INPUT
16
+ #{HTML_HDR}
17
+ <br/>
18
+ <div>
19
+ <h1 class="ForewordTitle">Foreword</h1>
20
+ <p>
21
+ <a href="a.html#b">a#b</a>
22
+ </p>
23
+ </div>
24
+ <p class="zzSTDTitle1"/>
25
+ </div>
26
+ </body>
27
+ </html>
28
+ OUTPUT
29
+ end
30
+
31
+ it "cross-references external documents in DOC" do
32
+ expect(IsoDoc::WordConvert.new({}).convert("test", <<~"INPUT", true).sub(/^.*<div class="WordSection2">/m, '<div class="WordSection2">').sub(%r{</div>.*$}m, "</div>")).to be_equivalent_to <<~"OUTPUT"
33
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
34
+ <preface>
35
+ <foreword>
36
+ <p>
37
+ <xref target="a#b"/>
38
+ </p>
39
+ </foreword>
40
+ </preface>
41
+ </iso-standard
42
+ INPUT
43
+ <div class="WordSection2">
44
+ <br clear="all" style="mso-special-character:line-break;page-break-before:always"/>
45
+ <div>
46
+ <h1 class="ForewordTitle">Foreword</h1>
47
+ <p>
48
+ <a href="a.doc#b">a#b</a>
49
+ </p>
50
+ </div>
51
+ OUTPUT
52
+ end
53
+
54
+
4
55
  it "cross-references notes" do
5
56
  expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)). to be_equivalent_to <<~"OUTPUT"
6
57
  <iso-standard xmlns="http://riboseinc.com/isoxml">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath