metanorma-rsd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,157 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require "fileutils"
4
+
5
+ module IsoDoc
6
+ module Rsd
7
+ # A {Converter} implementation that generates Word output, and a document
8
+ # schema encapsulation of the document for validation
9
+
10
+ class WordConvert < IsoDoc::WordConvert
11
+ def initialize(options)
12
+ @libdir = File.dirname(__FILE__)
13
+ super
14
+ #system "cp #{html_doc_path('logo.svg')} logo.svg"
15
+ FileUtils.cp html_doc_path('logo.svg'), "logo.svg"
16
+ @files_to_delete << "logo.svg"
17
+ end
18
+
19
+ def default_fonts(options)
20
+ {
21
+ bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Arial",sans-serif'),
22
+ headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Arial",sans-serif'),
23
+ monospacefont: '"Courier New",monospace'
24
+ }
25
+ end
26
+
27
+ def default_file_locations(options)
28
+ {
29
+ wordstylesheet: html_doc_path("wordstyle.scss"),
30
+ standardstylesheet: html_doc_path("rsd.scss"),
31
+ header: html_doc_path("header.html"),
32
+ wordcoverpage: html_doc_path("word_rsd_titlepage.html"),
33
+ wordintropage: html_doc_path("word_rsd_intro.html"),
34
+ ulstyle: "l3",
35
+ olstyle: "l2",
36
+ }
37
+ end
38
+
39
+ def metadata_init(lang, script, labels)
40
+ @meta = Metadata.new(lang, script, labels)
41
+ end
42
+
43
+ def make_body(xml, docxml)
44
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
45
+ xml.body **body_attr do |body|
46
+ make_body1(body, docxml)
47
+ make_body2(body, docxml)
48
+ make_body3(body, docxml)
49
+ end
50
+ end
51
+
52
+ def make_body2(body, docxml)
53
+ body.div **{ class: "WordSection2" } do |div2|
54
+ info docxml, div2
55
+ div2.p { |p| p << "&nbsp;" } # placeholder
56
+ end
57
+ #body.br **{ clear: "all", style: "page-break-before:auto;mso-break-type:section-break;" }
58
+ section_break(body)
59
+ end
60
+
61
+ def title(isoxml, _out)
62
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
63
+ set_metadata(:doctitle, main)
64
+ end
65
+
66
+ def generate_header(filename, dir)
67
+ return unless @header
68
+ template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
69
+ meta = @meta.get
70
+ meta[:filename] = filename
71
+ params = meta.map { |k, v| [k.to_s, v] }.to_h
72
+ File.open("header.html", "w") { |f| f.write(template.render(params)) }
73
+ @files_to_delete << "header.html"
74
+ "header.html"
75
+ end
76
+
77
+ def header_strip(h)
78
+ h = h.to_s.gsub(%r{<br/>}, " ").sub(/<\/?h[12][^>]*>/, "")
79
+ h1 = to_xhtml_fragment(h.dup)
80
+ h1.traverse do |x|
81
+ x.replace(" ") if x.name == "span" &&
82
+ /mso-tab-count/.match(x["style"])
83
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
84
+ x.remove if x.name == "a" && x["epub:type"] == "footnote"
85
+ x.replace(x.children) if x.name == "a"
86
+ end
87
+ from_xhtml(h1)
88
+ end
89
+
90
+ def info(isoxml, out)
91
+ @meta.security isoxml, out
92
+ super
93
+ end
94
+
95
+ def annex_name(annex, name, div)
96
+ div.h1 **{ class: "Annex" } do |t|
97
+ t << "#{get_anchors[annex['id']][:label]} "
98
+ t << "<b>#{name.text}</b>"
99
+ end
100
+ end
101
+
102
+ def annex_name_lbl(clause, num)
103
+ obl = l10n("(#{@inform_annex_lbl})")
104
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
105
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
106
+ end
107
+
108
+ def pre_parse(node, out)
109
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
110
+ end
111
+
112
+ def term_defs_boilerplate(div, source, term, preface)
113
+ if source.empty? && term.nil?
114
+ div << @no_terms_boilerplate
115
+ else
116
+ div << term_defs_boilerplate_cont(source, term)
117
+ end
118
+ end
119
+
120
+ def i18n_init(lang, script)
121
+ super
122
+ @annex_lbl = "Appendix"
123
+ end
124
+
125
+ def error_parse(node, out)
126
+ # catch elements not defined in ISO
127
+ case node.name
128
+ when "pre"
129
+ pre_parse(node, out)
130
+ when "keyword"
131
+ out.span node.text, **{ class: "keyword" }
132
+ else
133
+ super
134
+ end
135
+ end
136
+
137
+ def fileloc(loc)
138
+ File.join(File.dirname(__FILE__), loc)
139
+ end
140
+
141
+ def cleanup(docxml)
142
+ super
143
+ term_cleanup(docxml)
144
+ end
145
+
146
+ def term_cleanup(docxml)
147
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
148
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
149
+ h2.add_child("&nbsp;")
150
+ h2.add_child(d.remove)
151
+ end
152
+ docxml
153
+ end
154
+
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "./rsd/processor"
2
+
3
+ module Metanorma
4
+ module Rsd
5
+
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ require "metanorma/processor"
2
+
3
+ module Metanorma
4
+ module Rsd
5
+ class Processor < Metanorma::Processor
6
+
7
+ def initialize
8
+ @short = :rsd
9
+ @input_format = :asciidoc
10
+ @asciidoctor_backend = :rsd
11
+ end
12
+
13
+ def output_formats
14
+ super.merge(
15
+ html: "html",
16
+ doc: "doc",
17
+ pdf: "pdf"
18
+ )
19
+ end
20
+
21
+ def version
22
+ "Asciidoctor::Rsd #{Asciidoctor::Rsd::VERSION}"
23
+ end
24
+
25
+ def input_to_isodoc(file)
26
+ Metanorma::Input::Asciidoc.new.process(file, @asciidoctor_backend)
27
+ end
28
+
29
+ def output(isodoc_node, outname, format, options={})
30
+ case format
31
+ when :html
32
+ IsoDoc::Rsd::HtmlConvert.new(options).convert(outname, isodoc_node)
33
+ when :doc
34
+ IsoDoc::Rsd::WordConvert.new(options).convert(outname, isodoc_node)
35
+ when :pdf
36
+ IsoDoc::Rsd::PdfConvert.new(options).convert(outname, isodoc_node)
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "asciidoctor/rsd/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "metanorma-rsd"
7
+ spec.version = Asciidoctor::Rsd::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "metanorma-rsd lets you write RSD in AsciiDoc."
12
+ spec.description = <<~DESCRIPTION
13
+ metanorma-rsd lets you write RSD in AsciiDoc syntax.
14
+
15
+ This gem is in active development.
16
+
17
+ Formerly known as asciidoctor-rsd.
18
+ DESCRIPTION
19
+
20
+ spec.homepage = "https://github.com/riboseinc/metanorma-rsd"
21
+ spec.license = "BSD-2-Clause"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "asciidoctor", "~> 1.5.7"
31
+ spec.add_dependency "htmlentities", "~> 4.3.4"
32
+ spec.add_dependency "nokogiri"
33
+ spec.add_dependency "metanorma-standoc", "~> 1.0.0"
34
+ spec.add_dependency "isodoc", "~> 0.8.8"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "byebug", "~> 9.1"
38
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
39
+ spec.add_development_dependency "guard", "~> 2.14"
40
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
41
+ spec.add_development_dependency "rake", "~> 12.0"
42
+ spec.add_development_dependency "rspec", "~> 3.6"
43
+ spec.add_development_dependency "rubocop", "~> 0.50"
44
+ spec.add_development_dependency "simplecov", "~> 0.15"
45
+ spec.add_development_dependency "timecop", "~> 0.9"
46
+ spec.add_development_dependency "metanorma", "~> 0.2.6"
47
+ end
metadata ADDED
@@ -0,0 +1,310 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metanorma-rsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.3.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.3.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: metanorma-standoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: isodoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.8
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.8
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '9.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '9.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: equivalent-xml
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.7'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '12.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '12.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.6'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.6'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.50'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.50'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0.15'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0.15'
209
+ - !ruby/object:Gem::Dependency
210
+ name: timecop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.9'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.9'
223
+ - !ruby/object:Gem::Dependency
224
+ name: metanorma
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 0.2.6
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.2.6
237
+ description: |
238
+ metanorma-rsd lets you write RSD in AsciiDoc syntax.
239
+
240
+ This gem is in active development.
241
+
242
+ Formerly known as asciidoctor-rsd.
243
+ email:
244
+ - open.source@ribose.com
245
+ executables: []
246
+ extensions: []
247
+ extra_rdoc_files: []
248
+ files:
249
+ - ".gitignore"
250
+ - ".travis.yml"
251
+ - CODE_OF_CONDUCT.md
252
+ - Gemfile
253
+ - LICENSE
254
+ - README.adoc
255
+ - Rakefile
256
+ - asciidoctor-rsd.gemspec.old
257
+ - bin/console
258
+ - bin/rspec
259
+ - bin/setup
260
+ - lib/asciidoctor-rsd.rb
261
+ - lib/asciidoctor/rsd.rb
262
+ - lib/asciidoctor/rsd/biblio.rng
263
+ - lib/asciidoctor/rsd/converter.rb
264
+ - lib/asciidoctor/rsd/isodoc.rng
265
+ - lib/asciidoctor/rsd/isostandard.rng
266
+ - lib/asciidoctor/rsd/pdf.js
267
+ - lib/asciidoctor/rsd/rsd.rng
268
+ - lib/asciidoctor/rsd/version.rb
269
+ - lib/isodoc/rsd/html/header.html
270
+ - lib/isodoc/rsd/html/html_rsd_intro.html
271
+ - lib/isodoc/rsd/html/html_rsd_titlepage.html
272
+ - lib/isodoc/rsd/html/htmlstyle.scss
273
+ - lib/isodoc/rsd/html/logo.svg
274
+ - lib/isodoc/rsd/html/rsd.scss
275
+ - lib/isodoc/rsd/html/scripts.html
276
+ - lib/isodoc/rsd/html/word_rsd_intro.html
277
+ - lib/isodoc/rsd/html/word_rsd_titlepage.html
278
+ - lib/isodoc/rsd/html/wordstyle.scss
279
+ - lib/isodoc/rsd/html_convert.rb
280
+ - lib/isodoc/rsd/metadata.rb
281
+ - lib/isodoc/rsd/pdf_convert.rb
282
+ - lib/isodoc/rsd/word_convert.rb
283
+ - lib/metanorma/rsd.rb
284
+ - lib/metanorma/rsd/processor.rb
285
+ - metanorma-rsd.gemspec
286
+ homepage: https://github.com/riboseinc/metanorma-rsd
287
+ licenses:
288
+ - BSD-2-Clause
289
+ metadata: {}
290
+ post_install_message:
291
+ rdoc_options: []
292
+ require_paths:
293
+ - lib
294
+ required_ruby_version: !ruby/object:Gem::Requirement
295
+ requirements:
296
+ - - ">="
297
+ - !ruby/object:Gem::Version
298
+ version: '0'
299
+ required_rubygems_version: !ruby/object:Gem::Requirement
300
+ requirements:
301
+ - - ">="
302
+ - !ruby/object:Gem::Version
303
+ version: '0'
304
+ requirements: []
305
+ rubyforge_project:
306
+ rubygems_version: 2.7.6
307
+ signing_key:
308
+ specification_version: 4
309
+ summary: metanorma-rsd lets you write RSD in AsciiDoc.
310
+ test_files: []