isodoc 1.1.0 → 1.1.3.pre.alpha3
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 +4 -4
- data/.github/workflows/macos.yml +6 -12
- data/.github/workflows/ubuntu.yml +18 -20
- data/.github/workflows/windows.yml +6 -12
- data/Rakefile +3 -1
- data/isodoc.gemspec +1 -1
- data/lib/isodoc/base_style/all.css +207 -0
- data/lib/isodoc/base_style/blocks.css +0 -0
- data/lib/isodoc/base_style/coverpage.css +0 -0
- data/lib/isodoc/base_style/defaults.css +0 -0
- data/lib/isodoc/base_style/metanorma_word.css +34 -0
- data/lib/isodoc/base_style/metanorma_word.scss +0 -1
- data/lib/isodoc/base_style/nav.css +0 -0
- data/lib/isodoc/base_style/reset.css +105 -0
- data/lib/isodoc/base_style/reset.scss +3 -3
- data/lib/isodoc/base_style/typography.css +0 -0
- data/lib/isodoc/convert.rb +106 -53
- data/lib/isodoc/function/references.rb +28 -17
- data/lib/isodoc/function/to_word_html.rb +2 -2
- data/lib/isodoc/function/utils.rb +57 -51
- data/lib/isodoc/gem_tasks.rb +133 -0
- data/lib/isodoc/metadata.rb +69 -63
- data/lib/isodoc/sassc_importer.rb +11 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_sect_gen.rb +3 -7
- data/spec/assets/{html.css → html.scss} +0 -0
- data/spec/isodoc/footnotes_spec.rb +2 -2
- data/spec/isodoc/postproc_spec.rb +1319 -1345
- data/spec/isodoc/ref_spec.rb +1 -1
- data/spec/isodoc/section_spec.rb +52 -0
- metadata +28 -18
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sassc'
|
4
|
+
require 'isodoc/sassc_importer'
|
5
|
+
require 'rake/clean'
|
6
|
+
|
7
|
+
module IsoDoc
|
8
|
+
module GemTasks
|
9
|
+
extend Rake::DSL if defined? Rake::DSL
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def install
|
14
|
+
rule '.css' => [proc { |tn| tn.sub(/\.css$/, '.scss') }] do |current_task|
|
15
|
+
begin
|
16
|
+
puts(current_task)
|
17
|
+
compile_scss_task(current_task)
|
18
|
+
rescue StandardError => e
|
19
|
+
notify_borken_compilation(e, current_task)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
scss_files = Rake::FileList['lib/**/*.scss']
|
24
|
+
source_files = scss_files.ext('.css')
|
25
|
+
|
26
|
+
task :comment_out_liquid do
|
27
|
+
process_css_files(scss_files) do |file_name|
|
28
|
+
comment_out_liquid(File.read(file_name, encoding: 'UTF-8'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task build_scss: [:comment_out_liquid].push(*source_files) do
|
33
|
+
process_css_files(scss_files) do |file_name|
|
34
|
+
uncomment_out_liquid(File.read(file_name, encoding: 'UTF-8'))
|
35
|
+
end
|
36
|
+
git_cache_compiled_files && puts('Built scss!')
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::Task['build'].enhance [:build_scss] do
|
40
|
+
git_rm_compiled_files
|
41
|
+
Rake::Task[:clean].invoke
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def notify_borken_compilation(error, current_task)
|
46
|
+
puts("Cannot compile #{current_task} because of #{error.message}")
|
47
|
+
puts('continue anyway[y|n]?')
|
48
|
+
answer = STDIN.gets.strip
|
49
|
+
if %w[y yes].include?(answer.strip.downcase)
|
50
|
+
puts("Cannot compile #{current_task} because of #{error.message}")
|
51
|
+
else
|
52
|
+
exit(0)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def git_cache_compiled_files
|
57
|
+
CLEAN.each do |css_file|
|
58
|
+
sh "git add #{css_file}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def git_rm_compiled_files
|
63
|
+
CLEAN.each do |css_file|
|
64
|
+
sh "git rm --cached #{css_file}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_css_files(scss_files)
|
69
|
+
scss_files.each do |file_name|
|
70
|
+
result = yield(file_name)
|
71
|
+
File.open(file_name, 'w', encoding: 'UTF-8') do |file|
|
72
|
+
file.puts(result)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def comment_out_liquid(text)
|
78
|
+
text.split("\n").map do |line|
|
79
|
+
if line.match?(/{({|%).+(}|%)}/)
|
80
|
+
"/* LIQUID_COMMENT#{line}LIQUID_COMMENT */"
|
81
|
+
else
|
82
|
+
line
|
83
|
+
end
|
84
|
+
end
|
85
|
+
.join("\n")
|
86
|
+
end
|
87
|
+
|
88
|
+
def uncomment_out_liquid(text)
|
89
|
+
text
|
90
|
+
.gsub('/* LIQUID_COMMENT', '')
|
91
|
+
.gsub('LIQUID_COMMENT */', '')
|
92
|
+
.gsub('"{{', '{{').gsub('}}"', '}}')
|
93
|
+
end
|
94
|
+
|
95
|
+
def fonts_placeholder
|
96
|
+
<<~TEXT
|
97
|
+
$bodyfont: '{{bodyfont}}';
|
98
|
+
$headerfont: '{{headerfont}}';
|
99
|
+
$monospacefont: '{{monospacefont}}';
|
100
|
+
TEXT
|
101
|
+
end
|
102
|
+
|
103
|
+
def compile_scss(filename)
|
104
|
+
require 'sassc'
|
105
|
+
|
106
|
+
isodoc_path = if Gem.loaded_specs['isodoc']
|
107
|
+
File.join(Gem.loaded_specs['isodoc'].full_gem_path, 'lib', 'isodoc')
|
108
|
+
else
|
109
|
+
File.join('lib', 'isodoc')
|
110
|
+
end
|
111
|
+
[isodoc_path,
|
112
|
+
File.dirname(filename)].each do |name|
|
113
|
+
SassC.load_paths << name
|
114
|
+
end
|
115
|
+
sheet_content = File.read(filename, encoding: 'UTF-8')
|
116
|
+
SassC::Engine.new(fonts_placeholder + sheet_content,
|
117
|
+
syntax: :scss,
|
118
|
+
importer: SasscImporter)
|
119
|
+
.render
|
120
|
+
end
|
121
|
+
|
122
|
+
def compile_scss_task(current_task)
|
123
|
+
filename = current_task.source
|
124
|
+
basename = File.basename(filename, '.*')
|
125
|
+
compiled_path = File.join(File.dirname(filename), "#{basename}.css")
|
126
|
+
content = uncomment_out_liquid(compile_scss(filename))
|
127
|
+
File.open(compiled_path, 'w:UTF-8') do |f|
|
128
|
+
f.write(content)
|
129
|
+
end
|
130
|
+
CLEAN << compiled_path
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/lib/isodoc/metadata.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './metadata_date'
|
2
4
|
|
3
5
|
module IsoDoc
|
4
6
|
class Metadata
|
5
7
|
DATETYPES = %w{published accessed created implemented obsoleted confirmed
|
6
|
-
|
7
|
-
|
8
|
+
updated issued received transmitted copied unchanged
|
9
|
+
circulated vote-started
|
10
|
+
vote-ended}.freeze
|
11
|
+
|
12
|
+
attr_accessor :fonts_options
|
8
13
|
|
9
14
|
def ns(xpath)
|
10
15
|
Common::ns(xpath)
|
@@ -14,13 +19,14 @@ module IsoDoc
|
|
14
19
|
IsoDoc::Function::I18n::l10n(a, b, c)
|
15
20
|
end
|
16
21
|
|
17
|
-
def initialize(lang, script, labels)
|
22
|
+
def initialize(lang, script, labels, fonts_options = {})
|
18
23
|
@metadata = {}
|
19
|
-
DATETYPES.each { |w| @metadata["#{w.gsub(/-/,
|
24
|
+
DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = 'XXX' }
|
20
25
|
@lang = lang
|
21
26
|
@script = script
|
22
27
|
@c = HTMLEntities.new
|
23
28
|
@labels = labels
|
29
|
+
@fonts_options = fonts_options
|
24
30
|
end
|
25
31
|
|
26
32
|
def get
|
@@ -36,26 +42,26 @@ module IsoDoc
|
|
36
42
|
end
|
37
43
|
|
38
44
|
def extract_person_names(authors)
|
39
|
-
authors.
|
40
|
-
if a.at(ns(
|
41
|
-
ret << a.at(ns(
|
45
|
+
authors.reduce([]) do |ret, a|
|
46
|
+
if a.at(ns('./name/completename'))
|
47
|
+
ret << a.at(ns('./name/completename')).text
|
42
48
|
else
|
43
49
|
fn = []
|
44
|
-
forenames = a.xpath(ns(
|
50
|
+
forenames = a.xpath(ns('./name/forename'))
|
45
51
|
forenames.each { |f| fn << f.text }
|
46
|
-
surname = a&.at(ns(
|
47
|
-
ret << fn.join(
|
52
|
+
surname = a&.at(ns('./name/surname'))&.text
|
53
|
+
ret << fn.join(' ') + ' ' + surname
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
52
58
|
def extract_person_affiliations(authors)
|
53
|
-
authors.
|
54
|
-
name = a&.at(ns(
|
55
|
-
location = a&.at(ns(
|
56
|
-
|
57
|
-
m << (
|
58
|
-
(name || location ||
|
59
|
+
authors.reduce([]) do |m, a|
|
60
|
+
name = a&.at(ns('./affiliation/organization/name'))&.text
|
61
|
+
location = a&.at(ns('./affiliation/organization/address/'\
|
62
|
+
'formattedAddress'))&.text
|
63
|
+
m << (!name.nil? && !location.nil? ? "#{name}, #{location}" :
|
64
|
+
(name || location || ''))
|
59
65
|
m
|
60
66
|
end
|
61
67
|
end
|
@@ -84,99 +90,99 @@ module IsoDoc
|
|
84
90
|
end
|
85
91
|
|
86
92
|
def bibdate(isoxml, _out)
|
87
|
-
isoxml.xpath(ns(
|
88
|
-
set("#{d['type'].gsub(/-/,
|
93
|
+
isoxml.xpath(ns('//bibdata/date')).each do |d|
|
94
|
+
set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
98
|
def doctype(isoxml, _out)
|
93
|
-
b = isoxml&.at(ns(
|
94
|
-
t = b.split(/[- ]/).map
|
99
|
+
b = isoxml&.at(ns('//bibdata/ext/doctype'))&.text || return
|
100
|
+
t = b.split(/[- ]/).map(&:capitalize).join(' ')
|
95
101
|
set(:doctype, t)
|
96
102
|
end
|
97
103
|
|
98
104
|
def iso?(org)
|
99
|
-
name = org&.at(ns(
|
100
|
-
abbrev = org&.at(ns(
|
101
|
-
(abbrev ==
|
102
|
-
name ==
|
105
|
+
name = org&.at(ns('./name'))&.text
|
106
|
+
abbrev = org&.at(ns('./abbreviation'))&.text
|
107
|
+
(abbrev == 'ISO' ||
|
108
|
+
name == 'International Organization for Standardization')
|
103
109
|
end
|
104
110
|
|
105
111
|
def agency(xml)
|
106
|
-
agency =
|
112
|
+
agency = ''
|
107
113
|
publisher = []
|
108
114
|
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
109
|
-
|
110
|
-
name = org&.at(ns(
|
111
|
-
agency1 = org&.at(ns(
|
115
|
+
'organization')).each do |org|
|
116
|
+
name = org&.at(ns('./name'))&.text
|
117
|
+
agency1 = org&.at(ns('./abbreviation'))&.text || name
|
112
118
|
publisher << name if name
|
113
|
-
agency = iso?(org) ?
|
119
|
+
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
114
120
|
end
|
115
|
-
set(:agency, agency.sub(%r{/$},
|
116
|
-
set(:publisher, multiple_and(publisher, @labels[
|
121
|
+
set(:agency, agency.sub(%r{/$}, ''))
|
122
|
+
set(:publisher, multiple_and(publisher, @labels['and']))
|
117
123
|
end
|
118
124
|
|
119
125
|
def multiple_and(names, andword)
|
120
|
-
return
|
126
|
+
return '' if names.empty?
|
121
127
|
return names[0] if names.length == 1
|
122
|
-
names.length == 2
|
123
|
-
return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script)
|
124
|
-
l10n(names[0..-2].join(
|
128
|
+
(names.length == 2) &&
|
129
|
+
(return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
|
130
|
+
l10n(names[0..-2].join(', ') + " #{andword} #{names[-1]}", @lang, @script)
|
125
131
|
end
|
126
132
|
|
127
133
|
def docstatus(isoxml, _out)
|
128
|
-
docstatus = isoxml.at(ns(
|
134
|
+
docstatus = isoxml.at(ns('//bibdata/status/stage'))
|
129
135
|
set(:unpublished, true)
|
130
136
|
if docstatus
|
131
137
|
set(:stage, status_print(docstatus.text))
|
132
|
-
i = isoxml&.at(ns(
|
138
|
+
(i = isoxml&.at(ns('//bibdata/status/substage'))&.text) &&
|
133
139
|
set(:substage, i)
|
134
|
-
i = isoxml&.at(ns(
|
140
|
+
(i = isoxml&.at(ns('//bibdata/status/iteration'))&.text) &&
|
135
141
|
set(:iteration, i)
|
136
142
|
set(:unpublished, unpublished(docstatus.text))
|
137
|
-
unpublished(docstatus.text)
|
143
|
+
unpublished(docstatus.text) &&
|
138
144
|
set(:stageabbr, stage_abbr(docstatus.text))
|
139
145
|
end
|
140
146
|
end
|
141
147
|
|
142
148
|
def stage_abbr(docstatus)
|
143
|
-
status_print(docstatus).split(/ /)
|
144
|
-
|
149
|
+
status_print(docstatus).split(/ /)
|
150
|
+
.map { |s| s[0].upcase }.join('')
|
145
151
|
end
|
146
152
|
|
147
153
|
def unpublished(status)
|
148
|
-
!
|
154
|
+
!status.casecmp('published').zero?
|
149
155
|
end
|
150
156
|
|
151
157
|
def status_print(status)
|
152
|
-
status.split(/-/).map
|
158
|
+
status.split(/-/).map(&:capitalize).join(' ')
|
153
159
|
end
|
154
160
|
|
155
161
|
def docid(isoxml, _out)
|
156
|
-
dn = isoxml.at(ns(
|
162
|
+
dn = isoxml.at(ns('//bibdata/docidentifier'))
|
157
163
|
set(:docnumber, dn&.text)
|
158
164
|
end
|
159
165
|
|
160
166
|
def docnumeric(isoxml, _out)
|
161
|
-
dn = isoxml.at(ns(
|
167
|
+
dn = isoxml.at(ns('//bibdata/docnumber'))
|
162
168
|
set(:docnumeric, dn&.text)
|
163
169
|
end
|
164
170
|
|
165
171
|
def draftinfo(draft, revdate)
|
166
|
-
draftinfo =
|
172
|
+
draftinfo = ''
|
167
173
|
if draft
|
168
|
-
draftinfo = " (#{@labels[
|
174
|
+
draftinfo = " (#{@labels['draft_label']} #{draft}"
|
169
175
|
draftinfo += ", #{revdate}" if revdate
|
170
|
-
draftinfo +=
|
176
|
+
draftinfo += ')'
|
171
177
|
end
|
172
178
|
l10n(draftinfo, @lang, @script)
|
173
179
|
end
|
174
180
|
|
175
181
|
def version(isoxml, _out)
|
176
|
-
set(:edition, isoxml&.at(ns(
|
177
|
-
set(:docyear, isoxml&.at(ns(
|
178
|
-
set(:draft, isoxml&.at(ns(
|
179
|
-
revdate = isoxml&.at(ns(
|
182
|
+
set(:edition, isoxml&.at(ns('//bibdata/edition'))&.text)
|
183
|
+
set(:docyear, isoxml&.at(ns('//bibdata/copyright/from'))&.text)
|
184
|
+
set(:draft, isoxml&.at(ns('//version/draft'))&.text)
|
185
|
+
revdate = isoxml&.at(ns('//version/revision-date'))&.text
|
180
186
|
set(:revdate, revdate)
|
181
187
|
set(:revdate_monthyear, monthyr(revdate))
|
182
188
|
set(:draftinfo,
|
@@ -188,7 +194,7 @@ module IsoDoc
|
|
188
194
|
set(:doctitle, main)
|
189
195
|
end
|
190
196
|
|
191
|
-
def subtitle(
|
197
|
+
def subtitle(_isoxml, _out)
|
192
198
|
nil
|
193
199
|
end
|
194
200
|
|
@@ -199,29 +205,29 @@ module IsoDoc
|
|
199
205
|
|
200
206
|
def relations_partof(isoxml)
|
201
207
|
std = isoxml.at(ns("//bibdata/relation[@type = 'partOf']")) || return
|
202
|
-
id = std.at(ns(
|
208
|
+
id = std.at(ns('.//docidentifier'))
|
203
209
|
set(:partof, id.text) if id
|
204
210
|
end
|
205
211
|
|
206
212
|
def relations_obsoletes(isoxml)
|
207
213
|
std = isoxml.at(ns("//bibdata/relation[@type = 'obsoletes']")) || return
|
208
|
-
locality = std.at(ns(
|
209
|
-
id = std.at(ns(
|
214
|
+
locality = std.at(ns('.//locality'))
|
215
|
+
id = std.at(ns('.//docidentifier'))
|
210
216
|
set(:obsoletes, id.text) if id
|
211
217
|
set(:obsoletes_part, locality.text) if locality
|
212
218
|
end
|
213
219
|
|
214
220
|
def url(xml, _out)
|
215
|
-
a = xml.at(ns(
|
216
|
-
a = xml.at(ns("//bibdata/uri[@type = 'html']"))
|
217
|
-
a = xml.at(ns("//bibdata/uri[@type = 'xml']"))
|
218
|
-
a = xml.at(ns("//bibdata/uri[@type = 'pdf']"))
|
219
|
-
a = xml.at(ns("//bibdata/uri[@type = 'doc']"))
|
221
|
+
(a = xml.at(ns('//bibdata/uri[not(@type)]'))) && set(:url, a.text)
|
222
|
+
(a = xml.at(ns("//bibdata/uri[@type = 'html']"))) && set(:html, a.text)
|
223
|
+
(a = xml.at(ns("//bibdata/uri[@type = 'xml']"))) && set(:xml, a.text)
|
224
|
+
(a = xml.at(ns("//bibdata/uri[@type = 'pdf']"))) && set(:pdf, a.text)
|
225
|
+
(a = xml.at(ns("//bibdata/uri[@type = 'doc']"))) && set(:doc, a.text)
|
220
226
|
end
|
221
227
|
|
222
228
|
def keywords(isoxml, _out)
|
223
229
|
ret = []
|
224
|
-
isoxml.xpath(ns(
|
230
|
+
isoxml.xpath(ns('//bibdata/keyword')).each { |kw| ret << kw.text }
|
225
231
|
set(:keywords, ret)
|
226
232
|
end
|
227
233
|
end
|
data/lib/isodoc/version.rb
CHANGED
@@ -5,9 +5,7 @@ module IsoDoc::XrefGen
|
|
5
5
|
annex_names(c, (65 + i).chr.to_s)
|
6
6
|
end
|
7
7
|
docxml.xpath(
|
8
|
-
|
9
|
-
"//bibliography/references[@normative = 'false']"
|
10
|
-
)).each do |b|
|
8
|
+
ns(@klass.bibliography_xpath)).each do |b|
|
11
9
|
preface_names(b)
|
12
10
|
end
|
13
11
|
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
@@ -20,9 +18,7 @@ module IsoDoc::XrefGen
|
|
20
18
|
# potentially overridden in middle_section_asset_names()
|
21
19
|
sequential_asset_names(d.xpath(ns("//preface/*")))
|
22
20
|
n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1)
|
23
|
-
n = section_names(d.at(ns(
|
24
|
-
"//bibliography/clause[.//references[@normative = 'true']] | "\
|
25
|
-
"//bibliography/references[@normative = 'true']")), n, 1)
|
21
|
+
n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
|
26
22
|
n = section_names(d.at(ns("//sections/terms | "\
|
27
23
|
"//sections/clause[descendant::terms]")), n, 1)
|
28
24
|
n = section_names(d.at(ns("//sections/definitions")), n, 1)
|
@@ -65,7 +61,7 @@ module IsoDoc::XrefGen
|
|
65
61
|
|
66
62
|
def middle_section_asset_names(d)
|
67
63
|
middle_sections = "//clause[title = 'Scope'] | "\
|
68
|
-
"
|
64
|
+
"#{@klass.norm_ref_xpath} | "\
|
69
65
|
"//sections/terms | //preface/* | "\
|
70
66
|
"//sections/definitions | //clause[parent::sections]"
|
71
67
|
sequential_asset_names(d.xpath(ns(middle_sections)))
|
File without changes
|
@@ -138,7 +138,7 @@ RSpec.describe IsoDoc do
|
|
138
138
|
|
139
139
|
it "processes IsoXML reviewer notes (HTML)" do
|
140
140
|
FileUtils.rm_f "test.html"
|
141
|
-
IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.
|
141
|
+
IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("test", <<~"INPUT", false)
|
142
142
|
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
143
143
|
<preface>
|
144
144
|
<foreword>
|
@@ -192,7 +192,7 @@ RSpec.describe IsoDoc do
|
|
192
192
|
|
193
193
|
it "processes IsoXML reviewer notes (Word)" do
|
194
194
|
FileUtils.rm_f "test.doc"
|
195
|
-
IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.
|
195
|
+
IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("test", <<~"INPUT", false)
|
196
196
|
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
197
197
|
<preface>
|
198
198
|
<foreword>
|