isodoc 0.7.1 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -6
  3. data/README.adoc +3 -3
  4. data/lib/{isodoc → isodoc-yaml}/i18n-en.yaml +0 -0
  5. data/lib/{isodoc → isodoc-yaml}/i18n-fr.yaml +0 -0
  6. data/lib/{isodoc → isodoc-yaml}/i18n-zh-Hans.yaml +0 -0
  7. data/lib/isodoc.rb +13 -6
  8. data/lib/isodoc/class_utils.rb +24 -0
  9. data/lib/isodoc/common.rb +34 -0
  10. data/lib/isodoc/convert.rb +3 -16
  11. data/lib/isodoc/function.rb +4 -0
  12. data/lib/isodoc/{blocks.rb → function/blocks.rb} +2 -2
  13. data/lib/isodoc/{cleanup.rb → function/cleanup.rb} +4 -9
  14. data/lib/isodoc/{i18n.rb → function/i18n.rb} +13 -10
  15. data/lib/isodoc/{inline.rb → function/inline.rb} +2 -4
  16. data/lib/isodoc/{lists.rb → function/lists.rb} +5 -4
  17. data/lib/isodoc/{references.rb → function/references.rb} +4 -3
  18. data/lib/isodoc/{section.rb → function/section.rb} +4 -3
  19. data/lib/isodoc/{table.rb → function/table.rb} +3 -2
  20. data/lib/isodoc/{terms.rb → function/terms.rb} +3 -2
  21. data/lib/isodoc/{iso2wordhtml.rb → function/to_word_html.rb} +2 -3
  22. data/lib/isodoc/{utils.rb → function/utils.rb} +6 -22
  23. data/lib/isodoc/{xref_gen.rb → function/xref_gen.rb} +4 -3
  24. data/lib/isodoc/{xref_sect_gen.rb → function/xref_sect_gen.rb} +4 -3
  25. data/lib/isodoc/html_convert.rb +12 -0
  26. data/lib/isodoc/html_function.rb +4 -0
  27. data/lib/isodoc/{htmlconvert → html_function}/comments.rb +2 -3
  28. data/lib/isodoc/{htmlconvert → html_function}/footnotes.rb +3 -4
  29. data/lib/isodoc/{htmlconvert → html_function}/html.rb +5 -5
  30. data/lib/isodoc/iso/html/html_iso_titlepage.html +2 -2
  31. data/lib/isodoc/iso/{convert.rb → html_convert.rb} +1 -1
  32. data/lib/isodoc/iso/{wordconvert.rb → word_convert.rb} +0 -0
  33. data/lib/isodoc/metadata.rb +27 -12
  34. data/lib/isodoc/version.rb +1 -1
  35. data/lib/isodoc/{wordconvert/convert.rb → word_convert.rb} +9 -11
  36. data/lib/isodoc/word_function.rb +4 -0
  37. data/lib/isodoc/word_function/body.rb +149 -0
  38. data/lib/isodoc/{wordconvert → word_function}/comments.rb +2 -2
  39. data/lib/isodoc/word_function/footnotes.rb +81 -0
  40. data/lib/isodoc/word_function/postprocess.rb +116 -0
  41. data/spec/isodoc/blocks_spec.rb +17 -17
  42. data/spec/isodoc/cleanup_spec.rb +8 -8
  43. data/spec/isodoc/footnotes_spec.rb +2 -2
  44. data/spec/isodoc/i18n_spec.rb +4 -4
  45. data/spec/isodoc/inline_spec.rb +7 -7
  46. data/spec/isodoc/iso_spec.rb +5 -5
  47. data/spec/isodoc/lists_spec.rb +4 -4
  48. data/spec/isodoc/metadata_spec.rb +2 -2
  49. data/spec/isodoc/postproc_spec.rb +9 -9
  50. data/spec/isodoc/ref_spec.rb +3 -3
  51. data/spec/isodoc/section_spec.rb +6 -6
  52. data/spec/isodoc/table_spec.rb +1 -1
  53. data/spec/isodoc/terms_spec.rb +1 -1
  54. data/spec/isodoc/xref_spec.rb +11 -11
  55. metadata +35 -30
  56. data/lib/isodoc/htmlconvert/convert.rb +0 -13
  57. data/lib/isodoc/wordconvert/footnotes.rb +0 -81
  58. data/lib/isodoc/wordconvert/postprocess.rb +0 -115
  59. data/lib/isodoc/wordconvert/wordconvertmodule.rb +0 -150
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2307d0897bc261ade077a3550818f09a5d008640f2711809d0daf173f57e40c
4
- data.tar.gz: 1a26f9322f6277cbc7534b8161d5798777a2e7683b782c402a5c1c8a4825cd6d
3
+ metadata.gz: a95d693408f9924a873e894eddf95b98fa2f3c1b689f1f2d68e0dc6be5a3ad0f
4
+ data.tar.gz: 1d5ecf55343cdc70c4e83238ee887446295b02d0c5dcf0d005e7e03f2260a80c
5
5
  SHA512:
6
- metadata.gz: 322b6d4ea3fbc7aedb90fddbeeae80347058e1a78b55e0b4fb7fea4fbbd4a26251cdd72fb664eb8bd36a082ca70e8bc39ad0e34eaec2143ed6b6ce9b9eed5af9
7
- data.tar.gz: cf491aa85b5b08741027d50379be5c1be9a0ad252c20a56380429b828a2a6a6a899747830aaf1cf20bddb6a19ca5fabc7944fde58f11a1c908f9181d2feb095f
6
+ metadata.gz: bd3033cb703cf7483e99760c5a9b9baf6b13eb98f92f7218aee037b4062ce0a76e1c7f5203c3a784a3c966d54f573268337d99999b358de32146925d9c225994
7
+ data.tar.gz: 5b4031816ce73f837abf30b421792eb3501f24c8b09c3c59daa2884312b2402a82dffe5d445ebab00630fe75aab323e50043c32374ab9284defc4a5cc1a74e1b
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: https://github.com/riboseinc/html2doc.git
3
- revision: f8bd693d8748c622bbe8f24ab30ac142b2543a0a
3
+ revision: ae15cfc0a4c8ebeb74193a8aa4a7884938a08434
4
4
  specs:
5
5
  html2doc (0.8.0)
6
6
  asciimath
@@ -15,7 +15,7 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- isodoc (0.7.0)
18
+ isodoc (0.7.1)
19
19
  asciimath
20
20
  html2doc (>= 0.7.1)
21
21
  htmlentities (~> 4.3.4)
@@ -58,6 +58,7 @@ GEM
58
58
  rspec (>= 2.99.0, < 4.0)
59
59
  htmlentities (4.3.4)
60
60
  image_size (2.0.0)
61
+ jaro_winkler (1.5.1)
61
62
  json (2.1.0)
62
63
  liquid (4.0.0)
63
64
  listen (3.1.5)
@@ -71,7 +72,7 @@ GEM
71
72
  mime-types-data (3.2016.0521)
72
73
  mini_portile2 (2.3.0)
73
74
  nenv (0.3.0)
74
- nokogiri (1.8.2)
75
+ nokogiri (1.8.3)
75
76
  mini_portile2 (~> 2.3.0)
76
77
  notiffany (0.1.1)
77
78
  nenv (~> 0.1)
@@ -79,7 +80,7 @@ GEM
79
80
  parallel (1.12.1)
80
81
  parser (2.5.1.0)
81
82
  ast (~> 2.4.0)
82
- powerpack (0.1.1)
83
+ powerpack (0.1.2)
83
84
  pry (0.11.3)
84
85
  coderay (~> 1.1.0)
85
86
  method_source (~> 0.9.0)
@@ -102,7 +103,8 @@ GEM
102
103
  diff-lcs (>= 1.2.0, < 2.0)
103
104
  rspec-support (~> 3.7.0)
104
105
  rspec-support (3.7.1)
105
- rubocop (0.56.0)
106
+ rubocop (0.57.2)
107
+ jaro_winkler (~> 1.5.1)
106
108
  parallel (~> 1.10)
107
109
  parser (>= 2.5)
108
110
  powerpack (~> 0.1)
@@ -126,7 +128,7 @@ GEM
126
128
  thor (0.20.0)
127
129
  thread_safe (0.3.6)
128
130
  timecop (0.9.1)
129
- unicode-display_width (1.3.3)
131
+ unicode-display_width (1.4.0)
130
132
  uuidtools (2.1.5)
131
133
 
132
134
  PLATFORMS
@@ -41,16 +41,16 @@ The conversion takes place with a `convert` method, with three arguments: the fi
41
41
  [source,ruby]
42
42
  ----
43
43
  # generates test.html
44
- IsoDoc::Iso::Convert.new({}).convert("test.xml")
44
+ IsoDoc::Iso::HtmlConvert.new({}).convert("test.xml")
45
45
 
46
46
  # generates test.doc, with Chinese font defaults rather than Roman
47
47
  IsoDoc::Iso::WordConvert.new({script: "Hans"}).convert("test.xml")
48
48
 
49
49
  # generates test.html, based on file1.xml
50
- IsoDoc::Iso::Convert.new({}).convert("test", File.read("file1.xml"))
50
+ IsoDoc::Iso::HtmlConvert.new({}).convert("test", File.read("file1.xml"))
51
51
 
52
52
  # generates HTML output for the given input string, but does not save it to disk.
53
- IsoDoc::Iso::Convert.new({}).convert("test", <<~"INPUT", true)
53
+ IsoDoc::Iso::HtmlConvert.new({}).convert("test", <<~"INPUT", true)
54
54
  <iso-standard xmlns="http://riboseinc.com/isoxml">
55
55
  <preface><foreword>
56
56
  <note>
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- module IsoDoc
2
-
3
1
  require_relative "isodoc/version"
4
2
 
5
3
  require "nokogiri"
@@ -11,10 +9,19 @@ require "mime/types"
11
9
  require "image_size"
12
10
  require "set"
13
11
  require "pp"
12
+ require "uuidtools"
13
+ require "html2doc"
14
+ require "liquid"
15
+ require "htmlentities"
16
+
17
+ require "isodoc/common"
14
18
  require "isodoc/convert"
15
19
  require "isodoc/metadata"
16
- require "isodoc/htmlconvert/convert"
17
- require "isodoc/wordconvert/convert"
18
- require "isodoc/iso/convert"
19
- require "isodoc/iso/wordconvert"
20
+ require "isodoc/html_convert"
21
+ require "isodoc/word_convert"
22
+ require "isodoc/iso/html_convert"
23
+ require "isodoc/iso/word_convert"
24
+
25
+ module IsoDoc
26
+
20
27
  end
@@ -0,0 +1,24 @@
1
+
2
+ module IsoDoc
3
+ module ClassUtils
4
+
5
+ def date_range(date)
6
+ from = date.at(ns("./from"))
7
+ to = date.at(ns("./to"))
8
+ on = date.at(ns("./on"))
9
+ return on.text if on
10
+ ret = "#{from.text}&ndash;"
11
+ ret += to.text if to
12
+ ret
13
+ end
14
+
15
+ def ns(xpath)
16
+ xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1").
17
+ gsub(%r{::([a-zA-z])}, "::xmlns:\\1").
18
+ gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1").
19
+ gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "./function/blocks"
2
+ require_relative "./function/cleanup"
3
+ require_relative "./function/i18n"
4
+ require_relative "./function/inline"
5
+ require_relative "./function/lists"
6
+ require_relative "./function/references"
7
+ require_relative "./function/section"
8
+ require_relative "./function/table"
9
+ require_relative "./function/terms"
10
+ require_relative "./function/to_word_html"
11
+ require_relative "./function/utils"
12
+ require_relative "./function/xref_gen"
13
+ require_relative "./function/xref_sect_gen"
14
+ require_relative "./class_utils"
15
+
16
+ module IsoDoc
17
+ class Common
18
+ include Function::Blocks
19
+ include Function::Cleanup
20
+ include Function::I18n
21
+ include Function::Inline
22
+ include Function::Lists
23
+ include Function::References
24
+ include Function::Section
25
+ include Function::Table
26
+ include Function::Terms
27
+ include Function::ToWordHtml
28
+ include Function::Utils
29
+ include Function::XrefGen
30
+ include Function::XrefSectGen
31
+
32
+ extend ::IsoDoc::ClassUtils
33
+ end
34
+ end
@@ -1,21 +1,8 @@
1
- require "isodoc/iso2wordhtml"
2
- require "isodoc/cleanup"
3
- require "isodoc/utils"
4
- require "isodoc/metadata"
5
- require "isodoc/section"
6
- require "isodoc/references"
7
- require "isodoc/terms"
8
- require "isodoc/blocks"
9
- require "isodoc/lists"
10
- require "isodoc/table"
11
- require "isodoc/inline"
12
- require "isodoc/xref_gen"
13
- require "isodoc/xref_sect_gen"
14
- require "isodoc/i18n"
1
+ require "isodoc/common"
15
2
  require "sass"
16
3
 
17
4
  module IsoDoc
18
- class Common
5
+ class Convert < ::IsoDoc::Common
19
6
 
20
7
  # htmlstylesheet: Generic stylesheet for HTML
21
8
  # wordstylesheet: Generic stylesheet for Word
@@ -87,7 +74,7 @@ module IsoDoc
87
74
  end
88
75
 
89
76
  def metadata_init(lang, script, labels)
90
- @meta = Metadata.new(lang, script, labels)
77
+ @meta = Metadata.new(lang, script, labels)
91
78
  end
92
79
 
93
80
  def convert_init(file, filename, debug)
@@ -0,0 +1,4 @@
1
+ module IsoDoc
2
+ module Function
3
+ end
4
+ end
@@ -1,5 +1,5 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module Blocks
3
3
  @annotation = false
4
4
 
5
5
  def note_label(node)
@@ -1,10 +1,5 @@
1
- require "html2doc"
2
- require "htmlentities"
3
- require "nokogiri"
4
- require "pp"
5
-
6
- module IsoDoc
7
- class Common
1
+ module IsoDoc::Function
2
+ module Cleanup
8
3
  def cleanup(docxml)
9
4
  comment_cleanup(docxml)
10
5
  footnote_cleanup(docxml)
@@ -134,7 +129,7 @@ module IsoDoc
134
129
  t.at(".//tr").xpath("./td | ./th").each do |td|
135
130
  cols += (td["colspan"] ? td["colspan"].to_i : 1)
136
131
  end
137
- style = %{border-top:0pt;border-bottom:#{SW} 1.5pt;}
132
+ style = %{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
138
133
  tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
139
134
  tfoot.xpath(".//td").last
140
135
  end
@@ -161,7 +156,7 @@ module IsoDoc
161
156
  docxml
162
157
  end
163
158
 
164
- # We assume AsciiMath is being used in the terms & definitions.
159
+ # We assume AsciiMath is being used in the terms & definitions.
165
160
  # Indices sort after letter but before any following
166
161
  # letter (x, x_m, x_1, xa); we use colon to force that sort order.
167
162
  # Numbers sort *after* letters; we use thorn to force that sort order.
@@ -1,21 +1,22 @@
1
1
  require "yaml"
2
2
 
3
- module IsoDoc
4
- class Common
3
+ # TODO: Cleanup and generalize
4
+ module IsoDoc::Function
5
+ module I18n
5
6
  def i18n_init(lang, script)
6
7
  @lang = lang
7
8
  @script = script
8
9
  y = if @i18nyaml
9
10
  YAML.load_file(@i18nyaml)
10
11
  elsif lang == "en"
11
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
12
+ YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-en.yaml"))
12
13
  elsif lang == "fr"
13
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-fr.yaml"))
14
+ YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-fr.yaml"))
14
15
  elsif lang == "zh" && script == "Hans"
15
16
  YAML.load_file(File.join(File.dirname(__FILE__),
16
- "i18n-zh-Hans.yaml"))
17
+ "../../isodoc-yaml/i18n-zh-Hans.yaml"))
17
18
  else
18
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
19
+ YAML.load_file(File.join(File.dirname(__FILE__), "../../isodoc-yaml/i18n-en.yaml"))
19
20
  end
20
21
  @term_def_boilerplate = y["term_def_boilerplate"]
21
22
  @scope_lbl = y["scope"]
@@ -64,6 +65,7 @@ module IsoDoc
64
65
  @labels["script"] = @script
65
66
  end
66
67
 
68
+ # TODO: move to localization file
67
69
  def eref_localities1_zh(type, from, to)
68
70
  ret = ", 第#{from.text}" if from
69
71
  ret += "&ndash;#{to}" if to
@@ -71,6 +73,7 @@ module IsoDoc
71
73
  ret
72
74
  end
73
75
 
76
+ # TODO: move to localization file
74
77
  def eref_localities1(type, from, to, lang = "en")
75
78
  subsection = from&.text&.match?(/\./)
76
79
  return l10n(eref_localities1_zh(type, from, to)) if lang == "zh"
@@ -82,9 +85,10 @@ module IsoDoc
82
85
  l10n(ret)
83
86
  end
84
87
 
88
+ # TODO: move to localization file
85
89
  # function localising spaces and punctuation.
86
90
  # Not clear if period needs to be localised for zh
87
- def self.l10n(x, lang, script)
91
+ def l10n(x, lang = @lang, script = @script)
88
92
  if lang == "zh" && script == "Hans"
89
93
  x.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、").
90
94
  gsub(/\(/, "(").gsub(/\)/, ")").
@@ -95,8 +99,7 @@ module IsoDoc
95
99
  end
96
100
  end
97
101
 
98
- def l10n(x, lang = @lang, script = @script)
99
- Common::l10n(x, lang, script)
100
- end
102
+ module_function :l10n
103
+
101
104
  end
102
105
  end
@@ -1,7 +1,5 @@
1
- require "uuidtools"
2
-
3
- module IsoDoc
4
- class Common
1
+ module IsoDoc::Function
2
+ module Inline
5
3
  def section_break(body)
6
4
  body.br
7
5
  end
@@ -1,5 +1,6 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module Lists
3
+
3
4
  def ul_parse(node, out)
4
5
  out.ul do |ul|
5
6
  node.children.each { |n| parse(n, ul) }
@@ -21,8 +22,8 @@ module IsoDoc
21
22
 
22
23
  # We don't really want users to specify type of ordered list;
23
24
  # we will use a fixed hierarchy as practiced by ISO (though not
24
- # fully spelled out): a) 1) i) A) I)
25
-
25
+ # fully spelled out): a) 1) i) A) I)
26
+
26
27
  def ol_depth(node)
27
28
  depth = node.ancestors("ul, ol").size + 1
28
29
  type = :alphabet
@@ -1,5 +1,6 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module References
3
+
3
4
  def docid_l10n(x)
4
5
  return x if x.nil?
5
6
  x.gsub(/All Parts/, @all_parts_lbl)
@@ -65,7 +66,7 @@ module IsoDoc
65
66
  end
66
67
 
67
68
  def reference_format(b, r)
68
- title = b.at(ns("./formattedref")) ||
69
+ title = b.at(ns("./formattedref")) ||
69
70
  b.at(ns("./title[@language = '#{@language}']")) || b.at(ns("./title"))
70
71
  title&.children&.each { |n| parse(n, r) }
71
72
  end
@@ -1,5 +1,6 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module Section
3
+
3
4
  def inline_header_title(out, node, c1)
4
5
  out.span **{ class: "zzMoveToFollowing" } do |s|
5
6
  s.b do |b|
@@ -43,7 +44,7 @@ module IsoDoc
43
44
  div.parent.at(".//h1")
44
45
  end
45
46
 
46
- MIDDLE_CLAUSE =
47
+ MIDDLE_CLAUSE =
47
48
  "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
48
49
  "[not(descendant::terms)]".freeze
49
50
 
@@ -1,5 +1,6 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module Table
3
+
3
4
  def table_title_parse(node, out)
4
5
  name = node.at(ns("./name"))
5
6
  out.p **{ class: "TableTitle", align: "center" } do |p|
@@ -1,5 +1,6 @@
1
- module IsoDoc
2
- class Common
1
+ module IsoDoc::Function
2
+ module Terms
3
+
3
4
  def definition_parse(node, out)
4
5
  node.children.each { |n| parse(n, out) }
5
6
  end
@@ -1,7 +1,6 @@
1
- require "pp"
1
+ module IsoDoc::Function
2
+ module ToWordHtml
2
3
 
3
- module IsoDoc
4
- class Common
5
4
  def set_termdomain(termdomain)
6
5
  @termdomain = termdomain
7
6
  end
@@ -1,28 +1,12 @@
1
- module IsoDoc
2
- class Common
3
- def self.ns(xpath)
4
- xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1").
5
- gsub(%r{::([a-zA-z])}, "::xmlns:\\1").
6
- gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1").
7
- gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
8
- end
9
-
10
- def ns(xpath)
11
- Common::ns(xpath)
12
- end
1
+ module IsoDoc::Function
2
+ module Utils
13
3
 
14
- def self.date_range(date)
15
- from = date.at(ns("./from"))
16
- to = date.at(ns("./to"))
17
- on = date.at(ns("./on"))
18
- return on.text if on
19
- ret = "#{from.text}&ndash;"
20
- ret += to.text if to
21
- ret
4
+ def date_range(date)
5
+ self.class.date_range(date)
22
6
  end
23
7
 
24
- def date_range(date)
25
- Common::date_range(date)
8
+ def ns(xpath)
9
+ self.class.ns(xpath)
26
10
  end
27
11
 
28
12
  def insert_tab(out, n)