metanorma-acme 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,155 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+
4
+ module IsoDoc
5
+ module Acme
6
+ # A {Converter} implementation that generates Word output, and a document
7
+ # schema encapsulation of the document for validation
8
+
9
+ class WordConvert < IsoDoc::WordConvert
10
+ def html_path_acme(file)
11
+ File.join(File.dirname(__FILE__), File.join("html", file))
12
+ end
13
+
14
+ def initialize(options)
15
+ super
16
+ @wordstylesheet = generate_css(html_path_acme("wordstyle.scss"), false, default_fonts(options))
17
+ @standardstylesheet = generate_css(html_path_acme("acme.scss"), false, default_fonts(options))
18
+ @header = html_path_acme("header.html")
19
+ @wordcoverpage = html_path_acme("word_acme_titlepage.html")
20
+ @wordintropage = html_path_acme("word_acme_intro.html")
21
+ @ulstyle = "l3"
22
+ @olstyle = "l2"
23
+ system "cp #{html_path_acme('logo.jpg')} logo.jpg"
24
+ end
25
+
26
+ def default_fonts(options)
27
+ b = options[:bodyfont] ||
28
+ (options[:script] == "Hans" ? '"SimSun",serif' :
29
+ '"Arial",sans-serif')
30
+ h = options[:headerfont] ||
31
+ (options[:script] == "Hans" ? '"SimHei",sans-serif' :
32
+ '"Arial",sans-serif')
33
+ m = options[:monospacefont] || '"Courier New",monospace'
34
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
35
+ end
36
+
37
+ def metadata_init(lang, script, labels)
38
+ @meta = Metadata.new(lang, script, labels)
39
+ end
40
+
41
+ def make_body(xml, docxml)
42
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
43
+ xml.body **body_attr do |body|
44
+ make_body1(body, docxml)
45
+ make_body2(body, docxml)
46
+ make_body3(body, docxml)
47
+ end
48
+ end
49
+
50
+ def make_body2(body, docxml)
51
+ body.div **{ class: "WordSection2" } do |div2|
52
+ info docxml, div2
53
+ div2.p { |p| p << "&nbsp;" } # placeholder
54
+ end
55
+ #body.br **{ clear: "all", style: "page-break-before:auto;mso-break-type:section-break;" }
56
+ section_break(body)
57
+ end
58
+
59
+ def title(isoxml, _out)
60
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
61
+ set_metadata(:doctitle, main)
62
+ end
63
+
64
+ def generate_header(filename, dir)
65
+ return unless @header
66
+ template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
67
+ meta = @meta.get
68
+ meta[:filename] = filename
69
+ params = meta.map { |k, v| [k.to_s, v] }.to_h
70
+ File.open("header.html", "w") { |f| f.write(template.render(params)) }
71
+ @files_to_delete << "header.html"
72
+ "header.html"
73
+ end
74
+
75
+ def header_strip(h)
76
+ h = h.to_s.gsub(%r{<br/>}, " ").sub(/<\/?h[12][^>]*>/, "")
77
+ h1 = to_xhtml_fragment(h.dup)
78
+ h1.traverse do |x|
79
+ x.replace(" ") if x.name == "span" &&
80
+ /mso-tab-count/.match?(x["style"])
81
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
82
+ x.remove if x.name == "a" && x["epub:type"] == "footnote"
83
+ x.replace(x.children) if x.name == "a"
84
+ end
85
+ from_xhtml(h1)
86
+ end
87
+
88
+ def info(isoxml, out)
89
+ @meta.security isoxml, out
90
+ super
91
+ end
92
+
93
+ def annex_name(annex, name, div)
94
+ div.h1 **{ class: "Annex" } do |t|
95
+ t << "#{get_anchors[annex['id']][:label]} "
96
+ t << "<b>#{name.text}</b>"
97
+ end
98
+ end
99
+
100
+ def annex_name_lbl(clause, num)
101
+ obl = l10n("(#{@inform_annex_lbl})")
102
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
103
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
104
+ end
105
+
106
+ def pre_parse(node, out)
107
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
108
+ end
109
+
110
+ def term_defs_boilerplate(div, source, term, preface)
111
+ if source.empty? && term.nil?
112
+ div << @no_terms_boilerplate
113
+ else
114
+ div << term_defs_boilerplate_cont(source, term)
115
+ end
116
+ end
117
+
118
+ def i18n_init(lang, script)
119
+ super
120
+ @annex_lbl = "Appendix"
121
+ end
122
+
123
+ def error_parse(node, out)
124
+ # catch elements not defined in ISO
125
+ case node.name
126
+ when "pre"
127
+ pre_parse(node, out)
128
+ when "keyword"
129
+ out.span node.text, **{ class: "keyword" }
130
+ else
131
+ super
132
+ end
133
+ end
134
+
135
+ def fileloc(loc)
136
+ File.join(File.dirname(__FILE__), loc)
137
+ end
138
+
139
+ def cleanup(docxml)
140
+ super
141
+ term_cleanup(docxml)
142
+ end
143
+
144
+ def term_cleanup(docxml)
145
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
146
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
147
+ h2.add_child("&nbsp;")
148
+ h2.add_child(d.remove)
149
+ end
150
+ docxml
151
+ end
152
+
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,8 @@
1
+ require "metanorma/acme"
2
+ require "asciidoctor"
3
+ require "asciidoctor/acme"
4
+ require "isodoc/acme"
5
+
6
+ if defined? Metanorma
7
+ Metanorma::Registry.instance.register(Metanorma::Acme::Processor)
8
+ end
@@ -0,0 +1,11 @@
1
+ require "metanorma/acme/processor"
2
+
3
+ module Metanorma
4
+ module Acme
5
+
6
+ ORGANIZATION_NAME_SHORT = "Acme"
7
+ ORGANIZATION_NAME_LONG = "Acme Corp."
8
+ DOCUMENT_NAMESPACE = "https://open.ribose.com/standards/acme"
9
+
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ require "metanorma/processor"
2
+
3
+ module Metanorma
4
+ module Acme
5
+ class Processor < Metanorma::Processor
6
+
7
+ def initialize
8
+ @short = :acme
9
+ @input_format = :asciidoc
10
+ @asciidoctor_backend = :acme
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
+ "Metanorma::Acme #{Metanorma::Acme::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::Acme::HtmlConvert.new(options).convert(outname, isodoc_node)
33
+ when :doc
34
+ IsoDoc::Acme::WordConvert.new(options).convert(outname, isodoc_node)
35
+ when :pdf
36
+ IsoDoc::Acme::PdfConvert.new(options).convert(outname, isodoc_node)
37
+ =begin
38
+ require 'tempfile'
39
+ outname_html = outname + ".html"
40
+ IsoDoc::Acme::HtmlConvert.new(options).convert(outname_html, isodoc_node)
41
+ puts outname_html
42
+ system "cat #{outname_html}"
43
+ Metanorma::Output::Pdf.new.convert(outname_html, outname)
44
+ =end
45
+ else
46
+ super
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Metanorma
2
+ module Acme
3
+ VERSION = "0.3.3"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "metanorma/acme/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "metanorma-acme"
7
+ spec.version = Metanorma::Acme::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "Metanorma for the (fictitious) Acme Corp."
12
+ spec.description = <<~DESCRIPTION
13
+ Metanorma for the (fictitious) Acme Corp.
14
+
15
+ This gem is meant to be customised for any downstream use.
16
+ DESCRIPTION
17
+
18
+ spec.homepage = "https://github.com/riboseinc/metanorma-acme"
19
+ spec.license = "BSD-2-Clause"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "asciidoctor", "~> 1.5.7"
29
+ spec.add_dependency "htmlentities", "~> 4.3.4"
30
+ spec.add_dependency "ruby-jing"
31
+
32
+ spec.add_dependency "asciidoctor-iso", "~> 0.9.3"
33
+ spec.add_dependency "isodoc", "~> 0.8.1"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.15"
36
+ spec.add_development_dependency "byebug", "~> 9.1"
37
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
38
+ spec.add_development_dependency "guard", "~> 2.14"
39
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
40
+ spec.add_development_dependency "rake", "~> 12.0"
41
+ spec.add_development_dependency "rspec", "~> 3.6"
42
+ spec.add_development_dependency "rubocop", "~> 0.50"
43
+ spec.add_development_dependency "simplecov", "~> 0.15"
44
+ spec.add_development_dependency "timecop", "~> 0.9"
45
+ spec.add_development_dependency "metanorma", "~> 0.2.5"
46
+ end
metadata ADDED
@@ -0,0 +1,308 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metanorma-acme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-17 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: ruby-jing
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: asciidoctor-iso
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.3
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.1
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.1
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.5
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.5
237
+ description: |
238
+ Metanorma for the (fictitious) Acme Corp.
239
+
240
+ This gem is meant to be customised for any downstream use.
241
+ email:
242
+ - open.source@ribose.com
243
+ executables: []
244
+ extensions: []
245
+ extra_rdoc_files: []
246
+ files:
247
+ - ".gitignore"
248
+ - ".travis.yml"
249
+ - CODE_OF_CONDUCT.md
250
+ - Gemfile
251
+ - LICENSE
252
+ - README.adoc
253
+ - Rakefile
254
+ - bin/console
255
+ - bin/rspec
256
+ - bin/setup
257
+ - lib/asciidoctor/acme.rb
258
+ - lib/asciidoctor/acme/acme.rng
259
+ - lib/asciidoctor/acme/biblio.rng
260
+ - lib/asciidoctor/acme/converter.rb
261
+ - lib/asciidoctor/acme/isodoc.rng
262
+ - lib/asciidoctor/acme/isostandard.rng
263
+ - lib/asciidoctor/acme/pdf.js
264
+ - lib/isodoc/acme.rb
265
+ - lib/isodoc/acme/html/acme.scss
266
+ - lib/isodoc/acme/html/header.html
267
+ - lib/isodoc/acme/html/html_acme_intro.html
268
+ - lib/isodoc/acme/html/html_acme_titlepage.html
269
+ - lib/isodoc/acme/html/htmlstyle.scss
270
+ - lib/isodoc/acme/html/logo.jpg
271
+ - lib/isodoc/acme/html/scripts.html
272
+ - lib/isodoc/acme/html/word_acme_intro.html
273
+ - lib/isodoc/acme/html/word_acme_titlepage.html
274
+ - lib/isodoc/acme/html/wordstyle.scss
275
+ - lib/isodoc/acme/html_convert.rb
276
+ - lib/isodoc/acme/metadata.rb
277
+ - lib/isodoc/acme/pdf_convert.rb
278
+ - lib/isodoc/acme/word_convert.rb
279
+ - lib/metanorma-acme.rb
280
+ - lib/metanorma/acme.rb
281
+ - lib/metanorma/acme/processor.rb
282
+ - lib/metanorma/acme/version.rb
283
+ - metanorma-acme.gemspec
284
+ homepage: https://github.com/riboseinc/metanorma-acme
285
+ licenses:
286
+ - BSD-2-Clause
287
+ metadata: {}
288
+ post_install_message:
289
+ rdoc_options: []
290
+ require_paths:
291
+ - lib
292
+ required_ruby_version: !ruby/object:Gem::Requirement
293
+ requirements:
294
+ - - ">="
295
+ - !ruby/object:Gem::Version
296
+ version: '0'
297
+ required_rubygems_version: !ruby/object:Gem::Requirement
298
+ requirements:
299
+ - - ">="
300
+ - !ruby/object:Gem::Version
301
+ version: '0'
302
+ requirements: []
303
+ rubyforge_project:
304
+ rubygems_version: 2.7.7
305
+ signing_key:
306
+ specification_version: 4
307
+ summary: Metanorma for the (fictitious) Acme Corp.
308
+ test_files: []