isodoc 0.9.1 → 0.9.2

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: 14a2b122e4618bfd1d6ef74231405ad9b28d18bb7a8b812df2381c65f3443ca9
4
- data.tar.gz: 47ee8c2b1bc90444256371e188ffec407ca79facafe199684ac8693c1254dd80
3
+ metadata.gz: 271b0b210ccc7da3e9b0a09cf49fb248ff4708fd4f92adfb5529683db655fe63
4
+ data.tar.gz: 4345484709eba0f0ac06dc772fd62455c0f601c2f36c57b0ae1d8fdade47dbdd
5
5
  SHA512:
6
- metadata.gz: a6d74be6c585040de05deb7aeb5d92ec39651dc5a77f4f210479b77ef9cbb6fb82013ac87dfa77863853132b4026c3946039e79e51aad691243ca8fbfa86c5cf
7
- data.tar.gz: '010093e4801400b6308c204cdd9745944def9a405b98934f57f16529e0cd1272cdcaf03ef85befe4acb91392d694161af5a38ea35d67dffeeda2ccede0ea1298'
6
+ metadata.gz: 80a4d6a127130129671f6553283d7a09b2afb8f69756435cc5e20381309a92b5edd055eda730b10cf025fa6bb5169db65e38cff64cdfbf9d0dc20de415fe1f20
7
+ data.tar.gz: b90a49e79bf3b1d03c15adfcaed42b2e64293ab161b6e585448487db29e40129f8994da57d8429130c54bc66dc73640f5ca929d285c7d3528e44b341150ca2b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- isodoc (0.9.0)
4
+ isodoc (0.9.1)
5
5
  asciimath
6
6
  html2doc (~> 0.8.1)
7
7
  htmlentities (~> 4.3.4)
@@ -60,7 +60,7 @@ GEM
60
60
  rb-inotify (~> 0.9, >= 0.9.7)
61
61
  ruby_dep (~> 1.2)
62
62
  lumberjack (1.0.13)
63
- metanorma (0.2.8)
63
+ metanorma (0.2.9)
64
64
  method_source (0.9.0)
65
65
  mime-types (3.2.2)
66
66
  mime-types-data (~> 3.2015)
@@ -98,7 +98,7 @@ GEM
98
98
  diff-lcs (>= 1.2.0, < 2.0)
99
99
  rspec-support (~> 3.8.0)
100
100
  rspec-support (3.8.0)
101
- rubocop (0.58.2)
101
+ rubocop (0.59.1)
102
102
  jaro_winkler (~> 1.5.1)
103
103
  parallel (~> 1.10)
104
104
  parser (>= 2.5, != 2.5.1.1)
data/README.adoc CHANGED
@@ -32,6 +32,7 @@ wordcoverpage:: Cover page for Word output
32
32
  wordintropage:: Introductory page for Word output
33
33
  ulstyle:: Style identifier in Word stylesheet for unordered lists
34
34
  olstyle:: Style identifier in Word stylesheet for ordered list
35
+ suppressheadingnumbers:: Suppress heading numbers for clauses (does not apply to annexes)
35
36
 
36
37
  The IsoDoc gem classes themselves are abstract (though their current implementation contains rendering specific to the ISO standard.) Subclasses of the Isodoc gem classes are specific to different standards, and are associated with templates and stylesheets speciific to the rendering of those standards. Subclasses also provide the default values for the rendering parameters above; they should be used only as overrides.
37
38
 
@@ -19,6 +19,10 @@ module IsoDoc
19
19
  # bodyfont: font to use for body text
20
20
  # headerfont: font to use for header text
21
21
  # monospace: font to use for monospace text
22
+ # suppressheadingnumbers: suppress heading numbers for clauses
23
+ # scripts: Scripts file for HTML
24
+ # scripts_pdf: Scripts file for PDF
25
+ # datauriimage: Encode images in HTML output as data URIs
22
26
  def initialize(options)
23
27
  @libdir = File.dirname(__FILE__) unless @libdir
24
28
  options.merge!(default_fonts(options)) { |_, old, new| old || new }.
@@ -38,6 +42,8 @@ module IsoDoc
38
42
  @i18nyaml = options[:i18nyaml]
39
43
  @ulstyle = options[:ulstyle]
40
44
  @olstyle = options[:olstyle]
45
+ @datauriimage = options[:datauriimage]
46
+ @suppressheadingnumbers = options[:suppressheadingnumbers]
41
47
  @termdomain = ""
42
48
  @termexample = false
43
49
  @note = false
@@ -5,10 +5,9 @@ module IsoDoc::Function
5
5
  out.span **{ class: "zzMoveToFollowing" } do |s|
6
6
  s.b do |b|
7
7
  if get_anchors[node['id']][:label]
8
- b << "#{get_anchors[node['id']][:label]}. #{title} "
9
- else
10
- b << "#{title} "
8
+ b << "#{get_anchors[node['id']][:label]}. " unless @suppressheadingnumbers
11
9
  end
10
+ b << "#{title} "
12
11
  end
13
12
  end
14
13
  end
@@ -19,7 +18,7 @@ module IsoDoc::Function
19
18
  else
20
19
  div.send "h#{get_anchors[node['id']][:level]}" do |h|
21
20
  lbl = get_anchors[node['id']][:label]
22
- h << "#{lbl}. " if lbl
21
+ h << "#{lbl}. " if lbl && !@suppressheadingnumbers
23
22
  c1&.children&.each { |c2| parse(c2, h) }
24
23
  end
25
24
  end
@@ -37,7 +36,7 @@ module IsoDoc::Function
37
36
  def clause_name(num, title, div, header_class)
38
37
  header_class = {} if header_class.nil?
39
38
  div.h1 **attr_code(header_class) do |h1|
40
- if num
39
+ if num && !@suppressheadingnumbers
41
40
  h1 << "#{num}."
42
41
  insert_tab(h1, 1)
43
42
  end
@@ -114,7 +113,6 @@ module IsoDoc::Function
114
113
  end
115
114
 
116
115
  def term_defs_boilerplate_cont(src, term)
117
- #sources = sentence_join(src.map { |s| @anchors[s["bibitemid"]][:xref] })
118
116
  sources = sentence_join(src.map { |s| @anchors.dig(s["bibitemid"], :xref) })
119
117
  if src.empty? then @internal_terms_boilerplate
120
118
  elsif term.nil? then external_terms_boilerplate(sources)
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "base64"
2
3
 
3
4
  module IsoDoc::HtmlFunction
4
5
  module Html
@@ -195,15 +196,23 @@ module IsoDoc::HtmlFunction
195
196
  system "rm -r #{tmpimagedir}; mkdir #{tmpimagedir}"
196
197
  docxml.xpath("//*[local-name() = 'img']").each do |i|
197
198
  next if /^data:image/.match i["src"]
198
- matched = /\.(?<suffix>\S+)$/.match i["src"]
199
- uuid = UUIDTools::UUID.random_create.to_s
200
- new_full_filename = File.join(tmpimagedir, "#{uuid}.#{matched[:suffix]}")
201
- move_image1(i, new_full_filename)
199
+ @datauriimage ? datauri(i) : move_image1(i)
202
200
  end
203
201
  docxml
204
202
  end
205
203
 
206
- def move_image1(i, new_full_filename)
204
+ def datauri(i)
205
+ type = i["src"].split(".")[-1]
206
+ #bin = open(i["src"]).read(encoding: "utf-8")
207
+ bin = File.read(i["src"], encoding: "utf-8")
208
+ data = Base64.strict_encode64(bin)
209
+ i["src"] = "data:image/#{type};base64,#{data}"
210
+ end
211
+
212
+ def move_image1(i)
213
+ matched = /\.(?<suffix>\S+)$/.match i["src"]
214
+ uuid = UUIDTools::UUID.random_create.to_s
215
+ new_full_filename = File.join(tmpimagedir, "#{uuid}.#{matched[:suffix]}")
207
216
  FileUtils.cp i["src"], new_full_filename
208
217
  i["src"] = new_full_filename
209
218
  i["width"], i["height"] = Html2Doc.image_resize(i, @maxheight, @maxwidth)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "0.9.1".freeze
2
+ VERSION = "0.9.2".freeze
3
3
  end
@@ -501,6 +501,36 @@ CkZJTEVOQU1FOiB0ZXN0Cgo=
501
501
 
502
502
  end
503
503
 
504
+ it "encodes images in HTML as data URIs" do
505
+ system "rm -f test.html"
506
+ system "rm -rf test_images"
507
+ IsoDoc::HtmlConvert.new({htmlstylesheet: "spec/assets/html.css", datauriimage: true}).convert("test", <<~"INPUT", false)
508
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
509
+ <preface><foreword>
510
+ <figure id="_">
511
+ <name>Split-it-right sample divider</name>
512
+ <image src="spec/assets/rice_image1.png" id="_" imagetype="PNG"/>
513
+ </figure>
514
+ </foreword></preface>
515
+ </iso-standard>
516
+ INPUT
517
+ html = File.read("test.html").sub(/^.*<main class="main-section">/m, '<main class="main-section">').
518
+ sub(%r{</main>.*$}m, "</main>")
519
+ expect(html.gsub(%r{src="data:image/png;base64,[^"]+"}, %{src="data:image/png;base64,_"})).to be_equivalent_to <<~"OUTPUT"
520
+ <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
521
+ <br />
522
+ <div>
523
+ <h1 class="ForewordTitle">Foreword</h1>
524
+ <div id="_" class="figure">
525
+ <img src="data:image/png;base64,_" height="auto" width="auto" />
526
+ <p class="FigureTitle" align="center">Figure 1&#xA0;&#x2014; Split-it-right sample divider</p></div>
527
+ </div>
528
+ <p class="zzSTDTitle1"></p>
529
+ </main>
530
+ OUTPUT
531
+
532
+ end
533
+
504
534
  it "processes IsoXML terms for HTML" do
505
535
  system "rm -f test.doc"
506
536
  system "rm -f test.html"
@@ -315,6 +315,155 @@ OUTPUT
315
315
  OUTPUT
316
316
  end
317
317
 
318
+ it "processes section names suppressing section numbering" do
319
+ expect(IsoDoc::HtmlConvert.new({suppressheadingnumbers: true}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
320
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
321
+ <preface>
322
+ <foreword obligation="informative">
323
+ <title>Foreword</title>
324
+ <p id="A">This is a preamble</p>
325
+ </foreword>
326
+ <introduction id="B" obligation="informative"><title>Introduction</title><clause id="C" inline-header="false" obligation="informative">
327
+ <title>Introduction Subsection</title>
328
+ </clause>
329
+ </introduction></preface><sections>
330
+ <clause id="D" obligation="normative">
331
+ <title>Scope</title>
332
+ <p id="E">Text</p>
333
+ </clause>
334
+
335
+ <clause id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title><terms id="I" obligation="normative">
336
+ <title>Normal Terms</title>
337
+ <term id="J">
338
+ <preferred>Term2</preferred>
339
+ </term>
340
+ </terms>
341
+ <definitions id="K">
342
+ <dl>
343
+ <dt>Symbol</dt>
344
+ <dd>Definition</dd>
345
+ </dl>
346
+ </definitions>
347
+ </clause>
348
+ <definitions id="L">
349
+ <dl>
350
+ <dt>Symbol</dt>
351
+ <dd>Definition</dd>
352
+ </dl>
353
+ </definitions>
354
+ <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
355
+ <title>Introduction</title>
356
+ </clause>
357
+ <clause id="O" inline-header="false" obligation="normative">
358
+ <title>Clause 4.2</title>
359
+ </clause>
360
+ <clause id="O1" inline-header="false" obligation="normative">
361
+ </clause>
362
+ </clause>
363
+
364
+ </sections><annex id="P" inline-header="false" obligation="normative">
365
+ <title>Annex</title>
366
+ <clause id="Q" inline-header="false" obligation="normative">
367
+ <title>Annex A.1</title>
368
+ <clause id="Q1" inline-header="false" obligation="normative">
369
+ <title>Annex A.1a</title>
370
+ </clause>
371
+ </clause>
372
+ </annex><bibliography><references id="R" obligation="informative">
373
+ <title>Normative References</title>
374
+ </references><clause id="S" obligation="informative">
375
+ <title>Bibliography</title>
376
+ <references id="T" obligation="informative">
377
+ <title>Bibliography Subsection</title>
378
+ </references>
379
+ </clause>
380
+ </bibliography>
381
+ </iso-standard>
382
+ INPUT
383
+ #{HTML_HDR}
384
+ <br/>
385
+ <div>
386
+ <h1 class="ForewordTitle">Foreword</h1>
387
+ <p id="A">This is a preamble</p>
388
+ </div>
389
+ <br/>
390
+ <div class="Section3" id="B">
391
+ <h1 class="IntroTitle">Introduction</h1>
392
+ <div id="C"><h2>Introduction Subsection</h2>
393
+
394
+ </div>
395
+ </div>
396
+ <p class="zzSTDTitle1"/>
397
+ <div id="D">
398
+ <h1>Scope</h1>
399
+ <p id="E">Text</p>
400
+ </div>
401
+ <div>
402
+ <h1>Normative references</h1>
403
+ <p>There are no normative references in this document.</p>
404
+ </div>
405
+ <div id="H"><h1>Terms, definitions, symbols and abbreviated terms</h1><p>For the purposes of this document,
406
+ the following terms and definitions apply.</p>
407
+ <p>ISO and IEC maintain terminological databases for use in
408
+ standardization at the following addresses:</p>
409
+
410
+ <ul>
411
+ <li> <p>ISO Online browsing platform: available at
412
+ <a href="http://www.iso.org/obp">http://www.iso.org/obp</a></p> </li>
413
+ <li> <p>IEC Electropedia: available at
414
+ <a href="http://www.electropedia.org">http://www.electropedia.org</a>
415
+ </p> </li> </ul>
416
+ <div id="I"><h2>Normal Terms</h2>
417
+
418
+ <p class="TermNum" id="J">3.1.1</p>
419
+ <p class="Terms" style="text-align:left;">Term2</p>
420
+
421
+ </div><div id="K"><h2>Symbols and abbreviated terms</h2>
422
+ <dl><dt><p>Symbol</p></dt><dd>Definition</dd></dl>
423
+ </div></div>
424
+ <div id="L" class="Symbols">
425
+ <h1>Symbols and abbreviated terms</h1>
426
+ <dl>
427
+ <dt>
428
+ <p>Symbol</p>
429
+ </dt>
430
+ <dd>Definition</dd>
431
+ </dl>
432
+ </div>
433
+ <div id="M">
434
+ <h1>Clause 4</h1>
435
+ <div id="N"><h2>Introduction</h2>
436
+
437
+ </div>
438
+ <div id="O"><h2>Clause 4.2</h2>
439
+
440
+ </div>
441
+ <div id="O1"><h2/>
442
+ </div>
443
+ </div>
444
+ <br/>
445
+ <div id="P" class="Section3">
446
+ <h1 class="Annex"><b>Annex A</b><br/>(normative)<br/><br/><b>Annex</b></h1>
447
+ <div id="Q"><h2>Annex A.1</h2>
448
+
449
+ <div id="Q1"><h3>Annex A.1a</h3>
450
+
451
+ </div>
452
+ </div>
453
+ </div>
454
+ <br/>
455
+ <div>
456
+ <h1 class="Section3">Bibliography</h1>
457
+ <div>
458
+ <h2 class="Section3">Bibliography Subsection</h2>
459
+ </div>
460
+ </div>
461
+ </div>
462
+ </body>
463
+ </html>
464
+ OUTPUT
465
+ end
466
+
318
467
  it "processes simple terms & definitions" do
319
468
  expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
320
469
  <iso-standard xmlns="http://riboseinc.com/isoxml">
@@ -364,7 +513,6 @@ OUTPUT
364
513
  INPUT
365
514
  end
366
515
 
367
-
368
516
  it "processes terms & definitions with external source" do
369
517
  expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
370
518
  <iso-standard xmlns="http://riboseinc.com/isoxml">
@@ -528,6 +676,37 @@ end
528
676
  OUTPUT
529
677
  end
530
678
 
679
+ it "processes inline section headers with suppressed heading numbering" do
680
+ expect(IsoDoc::HtmlConvert.new({suppressheadingnumbers: true}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
681
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
682
+ <sections>
683
+ <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
684
+ <title>Introduction</title>
685
+ </clause>
686
+ <clause id="O" inline-header="true" obligation="normative">
687
+ <title>Clause 4.2</title>
688
+ </clause></clause>
689
+
690
+ </sections>
691
+ </iso-standard>
692
+ INPUT
693
+ #{HTML_HDR}
694
+ <p class="zzSTDTitle1"/>
695
+ <div id="M">
696
+ <h1>Clause 4</h1>
697
+ <div id="N">
698
+ <h2>Introduction</h2>
699
+ </div>
700
+ <div id="O">
701
+ <span class="zzMoveToFollowing"><b>Clause 4.2 </b></span>
702
+ </div>
703
+ </div>
704
+ </div>
705
+ </body>
706
+ </html>
707
+ OUTPUT
708
+ end
709
+
531
710
  it "processes sections without titles" do
532
711
  expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
533
712
  <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.1
4
+ version: 0.9.2
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-09-15 00:00:00.000000000 Z
11
+ date: 2018-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath