require "spec_helper" require "fileutils" RSpec.describe IsoDoc do it "generates file based on string input" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", filename: "test"}).convert("test", <<~"INPUT", false) test

These results are based on a study carried out on three different types of kernel.

INPUT expect(File.exist?("test.html")).to be true html = File.read("test.html") expect(html).to match(%r{test}) expect(html).to match(/another empty stylesheet/) expect(html).to match(%r{cdnjs\.cloudflare\.com/ajax/libs/mathjax/2\.7\.1/MathJax\.js}) expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/) end it "generates HTML output docs with null configuration" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css"}).convert("test", <<~"INPUT", false)

These results are based on a study carried out on three different types of kernel.

INPUT expect(File.exist?("test.html")).to be true html = File.read("test.html") expect(html).not_to match(%r{test}) expect(html).not_to match(/another empty stylesheet/) expect(html).to match(%r{cdnjs\.cloudflare\.com/ajax/libs/mathjax/2\.7\.1/MathJax\.js}) expect(html).to match(/delimiters: \[\['\(#\(', '\)#\)'\]\]/) end it "generates Word output docs with null configuration" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)

These results are based on a study carried out on three different types of kernel.

INPUT expect(File.exist?("test.doc")).to be true word = File.read("test.doc") expect(word).to match(/one empty stylesheet/) end it "generates HTML output docs with null configuration from file" do FileUtils.rm_f "spec/assets/iso.doc" FileUtils.rm_f "spec/assets/iso.html" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("spec/assets/iso.xml", nil, false) expect(File.exist?("spec/assets/iso.html")).to be true html = File.read("spec/assets/iso.html") expect(html).to match(/another empty stylesheet/) expect(html).to match(%r{https://use.fontawesome.com}) expect(html).to match(%r{libs/jquery}) end it "generates Headless HTML output docs with null configuration from file" do FileUtils.rm_f "spec/assets/iso.html" IsoDoc::HeadlessHtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("spec/assets/iso.xml", nil, false) expect(File.exist?("spec/assets/iso.headless.html")).to be true html = File.read("spec/assets/iso.headless.html") expect(html).not_to match(/another empty stylesheet/) expect(html).not_to match(%r{https://use.fontawesome.com}) expect(html).not_to match(%r{libs/jquery}) expect(html).not_to match(%r{

These results are based on a study carried out on three different types of kernel.

INPUT html = File.read("test.html") expect(html).to match(/another empty stylesheet/) expect(html).to match(/font-family: Zapf/) expect(html).to match(/an empty html cover page/) expect(html).to match(/an empty html intro page/) expect(html).to match(/This is > a script/) expect(html).not_to match(/CDATA/) expect(html).to match(%r{Enkonduko}) end it "generates HTML output docs with default fonts" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::HtmlConvert.new({htmlstylesheet: "spec/assets/html.css", htmlcoverpage: "spec/assets/htmlcover.html", htmlintropage: "spec/assets/htmlintro.html", scripts: "spec/assets/scripts.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)

These results are based on a study carried out on three different types of kernel.

INPUT html = File.read("test.html") expect(html).to match(/another empty stylesheet/) expect(html).to match(/font-family: Arial/) expect(html).to match(/an empty html cover page/) expect(html).to match(/an empty html intro page/) expect(html).to match(/This is > a script/) expect(html).not_to match(/CDATA/) expect(html).to match(%r{Enkonduko}) end it "generates Word output docs with complete configuration" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({bodyfont: "Zapf", wordstylesheet: "spec/assets/html.css", standardstylesheet: "spec/assets/std.css", header: "spec/assets/header.html", wordcoverpage: "spec/assets/wordcover.html", wordintropage: "spec/assets/wordintro.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false)

These results are based on a study carried out on three different types of kernel.

INPUT word = File.read("test.doc") expect(word).to match(/another empty stylesheet/) expect(word).to match(/font-family: Zapf/) expect(word).to match(/a third empty stylesheet/) #expect(word).to match(/test<\/title>/) expect(word).to match(/test_files\/header.html/) expect(word).to match(/an empty word cover page/) expect(word).to match(/an empty word intro page/) expect(word).to match(%r{Enkonduko</h1>}) end it "generates Word output docs with default fonts" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/html.css", standardstylesheet: "spec/assets/std.css", header: "spec/assets/header.html", wordcoverpage: "spec/assets/wordcover.html", wordintropage: "spec/assets/wordintro.html", i18nyaml: "spec/assets/i18n.yaml", ulstyle: "l1", olstyle: "l2"}).convert("test", <<~"INPUT", false) <iso-standard xmlns="http://riboseinc.com/isoxml"> <preface><foreword> <note> <p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a study carried out on three different types of kernel.</p> </note> </foreword></preface> </iso-standard> INPUT word = File.read("test.doc") expect(word).to match(/another empty stylesheet/) expect(word).to match(/font-family: Arial/) expect(word).to match(/a third empty stylesheet/) #expect(word).to match(/<title>test<\/title>/) expect(word).to match(/test_files\/header.html/) expect(word).to match(/an empty word cover page/) expect(word).to match(/an empty word intro page/) expect(word).to match(%r{Enkonduko</h1>}) end it "converts definition lists to tables for Word" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false) <iso-standard xmlns="http://riboseinc.com/isoxml"> <preface><foreword> <dl> <dt>Term</dt> <dd>Definition</dd> <dt>Term 2</dt> <dd>Definition 2</dd> </dl> </foreword></preface> </iso-standard> INPUT word = File.read("test.doc").sub(/^.*<div class="WordSection2">/m, '<div class="WordSection2">'). sub(%r{<br clear="all" class="section"/>\s*<div class="WordSection3">.*$}m, "") expect(word).to be_equivalent_to <<~"OUTPUT" <div class="WordSection2"> <br clear="all" style="mso-special-character:line-break;page-break-before:always"/> <div> <h1 class="ForewordTitle">Foreword</h1> <table class="dl"> <tr> <td valign="top" align="left"> <p align="left" style="margin-left:0pt;text-align:left;" class="MsoNormal">Term</p> </td> <td valign="top">Definition</td> </tr> <tr> <td valign="top" align="left"> <p align="left" style="margin-left:0pt;text-align:left;" class="MsoNormal">Term 2</p> </td> <td valign="top">Definition 2</td> </tr> </table> </div> <p class="MsoNormal"> </p> </div> OUTPUT end it "converts annex subheadings to h2Annex class for Word" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false) <iso-standard xmlns="http://riboseinc.com/isoxml"> <annex id="P" inline-header="false" obligation="normative"> <title>Annex Annex A.1 INPUT word = File.read("test.doc").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "") expect(word).to be_equivalent_to <<~"OUTPUT"


Annex A
(normative)

Annex

A.1. Annex A.1

OUTPUT end it "inserts default paragraph between two tables for Word" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)

'1M', '01M', and '0001M' all describe the calendar month January.

'2M', '02M', and '0002M' all describe the calendar month February.

INPUT word = File.read("test.doc").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "") expect(word).to be_equivalent_to <<~"OUTPUT"


EXAMPLE 1

'1M', '01M', and '0001M' all describe the calendar month January.

 

EXAMPLE 2

'2M', '02M', and '0002M' all describe the calendar month February.

OUTPUT end it "populates Word template with terms reference labels" do FileUtils.rm_f "test.doc" FileUtils.rm_f "test.html" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false) Terms and Definitions paddy

rice retaining its husk after threshing

3.1

The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here

INPUT word = File.read("test.doc").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "") expect(word).to be_equivalent_to <<~"OUTPUT"

1.  Terms and definitions

For the purposes of this document, the following terms and definitions apply.

ISO and IEC maintain terminological databases for use in standardization at the following addresses:

ISO Online browsing platform: available at http://www.iso.org/obp

IEC Electropedia: available at http://www.electropedia.org

1.1

paddy

rice retaining its husk after threshing

[SOURCE: ISO 7301:2011, Clause 3.1, modified — The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]

OUTPUT end it "populates Word header" do FileUtils.rm_f "test.doc" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", header: "spec/assets/header.html"}).convert("test", <<~"INPUT", false) 1000 INPUT word = File.read("test.doc").sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}m, "Content-Location: file:///C:/Doc/test_files/header.html"). sub(/------=_NextPart.*$/m, "") expect(word).to be_equivalent_to <<~"OUTPUT" Content-Location: file:///C:/Doc/test_files/header.html Content-Transfer-Encoding: base64 Content-Type: text/html charset="utf-8" Ci8qIGFuIGVtcHR5IGhlYWRlciAqLwoKU1RBUlQgRE9DIElEOiAKICAgICAgICAgICAxMDAwCiAg ICAgICAgIDogRU5EIERPQyBJRAoKRklMRU5BTUU6IHRlc3QKCg== OUTPUT end it "populates Word ToC" do FileUtils.rm_f "test.doc" IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", wordintropage: "spec/assets/wordintro.html"}).convert("test", <<~"INPUT", false) Clause 4 Introduction<bookmark id="Q"/> to this<fn reference="1"> <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p> </fn> Clause 4.2

A

Formerly denoted as 15 % (m/m).

INPUT word = File.read("test.doc").sub(/^.*
/m, '
'). sub(%r{
\s*
.*$}m, "") expect(word.gsub(/_Toc\d\d+/, "_Toc")).to be_equivalent_to <<~'OUTPUT' OUTPUT end it "reorders footnote numbers in HTML" do FileUtils.rm_f "test.html" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css", wordintropage: "spec/assets/wordintro.html"}).convert("test", <<~"INPUT", false) Clause 4

This is a footnote.

Introduction to this<fn reference="2"> <p id="_ff27c067-2785-4551-96cf-0a73530ff1e6">Formerly denoted as 15 % (m/m).</p> </fn> Clause 4.2

A

Formerly denoted as 15 % (m/m).

INPUT html = File.read("test.html").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "
") expect(html).to be_equivalent_to <<~"OUTPUT"

1.  Clause 4

1

1.1. Introduction to this2

1.2. Clause 4.2

A2

OUTPUT end it "moves images in HTML" do FileUtils.rm_f "test.html" FileUtils.rm_rf "test_images" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
Split-it-right sample divider
INPUT html = File.read("test.html").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "
") expect(`ls test_images`).to match(/\.png$/) expect(html.gsub(/\/[0-9a-f-]+\.png/, "/_.png")).to be_equivalent_to <<~"OUTPUT"

Foreword

Figure 1 — Split-it-right sample divider

OUTPUT end it "moves images in HTML, using relative file location" do FileUtils.rm_f "spec/test.html" FileUtils.rm_rf "spec/test_images" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("spec/test", <<~"INPUT", false)
Split-it-right sample divider
INPUT html = File.read("spec/test.html").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "
") expect(`ls test_images`).to match(/\.png$/) expect(html.gsub(/\/[0-9a-f-]+\.png/, "/_.png")).to be_equivalent_to <<~"OUTPUT"

Foreword

Figure 1 — Split-it-right sample divider

OUTPUT end it "encodes images in HTML as data URIs" do FileUtils.rm_f "test.html" FileUtils.rm_rf "test_images" IsoDoc::HtmlConvert.new({htmlstylesheet: "spec/assets/html.css", datauriimage: true}).convert("test", <<~"INPUT", false)
Split-it-right sample divider
INPUT html = File.read("test.html").sub(/^.*
/m, '
'). sub(%r{
.*$}m, "
") expect(html.gsub(%r{src="data:image/png;base64,[^"]+"}, %{src="data:image/png;base64,_"})).to be_equivalent_to <<~"OUTPUT"

Foreword

Figure 1 — Split-it-right sample divider

OUTPUT end it "processes IsoXML terms for HTML" do FileUtils.rm_f "test.html" FileUtils.rm_f "test.doc" IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false) Terms and Definitions paddy rice

rice retaining its husk after threshing

Foreign seeds, husks, bran, sand, dust.

  • A
  • A
3.1

The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here

paddypaddy rice rough rice cargo rice

rice retaining its husk after threshing

  • A

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

  • A

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

3.1
INPUT expect(File.exist?("test.html")).to be true html = File.read("test.html") expect(html).to match(%r{

1\.1

}) expect(html).to match(%r{

1\.2

}) end end