metanorma-cli 1.2.13.1 → 1.3.3

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.
data/a ADDED
@@ -0,0 +1,3 @@
1
+ git add lib/metanorma/cli/command.rb metanorma-cli.gemspec spec/acceptance/setup_spec.rb
2
+
3
+
data/a.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "id": "<GUID>",
3
+ "actor": {
4
+ "name": "<Student Name>",
5
+ "mbox": "<Student Email Address>",
6
+ "objectType": "Person"
7
+ },
8
+ "verb": {
9
+ "id": "http://adlnet.gov/expapi/verbs/completed",
10
+ "display": {
11
+ "en-US": "completed"
12
+ }
13
+ },
14
+ "object": {
15
+ "id": "<Activity URL>",
16
+ "definition": {
17
+ "name": {
18
+ "en-US": "<Activity name>"
19
+ },
20
+ "description": {
21
+ "en-US": "<Activity description>"
22
+ },
23
+ "type": "http://id.tincanapi.com/activitytype/resource"
24
+ },
25
+ "objectType": "Activity"
26
+ },
27
+ "result": {
28
+ "completion": "<Boolean>",
29
+ "duration": "<Cumulative ISO 8601 Duration>"
30
+ },
31
+ "timestamp": "<Start, ISO 8601 DATE>"
32
+ }
33
+
data/a.rb ADDED
@@ -0,0 +1,13 @@
1
+ def a
2
+ validate or return nil
3
+ puts "OK"
4
+ end
5
+
6
+ def validate
7
+ unless false
8
+ return nil
9
+ end
10
+ true
11
+ end
12
+
13
+ a
data/a.rxl ADDED
@@ -0,0 +1,45 @@
1
+ <bibdata type="standard">
2
+
3
+
4
+
5
+
6
+
7
+ <contributor>
8
+ <role type="author"/>
9
+ <organization>
10
+ <name>International Organization for Standardization</name>
11
+ <abbreviation>ISO</abbreviation>
12
+ </organization>
13
+ </contributor>
14
+ <contributor>
15
+ <role type="publisher"/>
16
+ <organization>
17
+ <name>International Organization for Standardization</name>
18
+ <abbreviation>ISO</abbreviation>
19
+ </organization>
20
+ </contributor>
21
+
22
+ <language>en</language>
23
+ <script>Latn</script>
24
+ <status>
25
+ <stage>60</stage>
26
+ <substage>60</substage>
27
+ </status>
28
+ <copyright>
29
+ <from>2020</from>
30
+ <owner>
31
+ <organization>
32
+ <name>International Organization for Standardization</name>
33
+ <abbreviation>ISO</abbreviation>
34
+ </organization>
35
+ </owner>
36
+ </copyright>
37
+ <ext>
38
+ <doctype>article</doctype>
39
+ <editorialgroup>
40
+ <technical-committee/>
41
+ <subcommittee/>
42
+ <workgroup/>
43
+ </editorialgroup>
44
+ </ext>
45
+ </bibdata>
data/b ADDED
@@ -0,0 +1,85 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <gb-standard xmlns="http://riboseinc.com/gbstandard">
3
+ <bibdata type="standard">
4
+ <title>
5
+
6
+ </title>
7
+ <title>
8
+
9
+ </title>
10
+ <docidentifier type="gb">T/AAA 123</docidentifier>
11
+ <docidentifier type="gb-structured">
12
+ <project-number>T/AAA 123</project-number>
13
+ </docidentifier>
14
+ <docnumber>123</docnumber>
15
+ <contributor>
16
+ <role type="author"/>
17
+ <person>
18
+ <name>
19
+ <surname>Author</surname>
20
+ </name>
21
+ </person>
22
+ </contributor>
23
+ <contributor>
24
+ <role type="author"/>
25
+ <organization>
26
+ <name>GB</name>
27
+ </organization>
28
+ </contributor>
29
+ <contributor>
30
+ <role type="publisher"/>
31
+ <organization>
32
+ <name>GB</name>
33
+ </organization>
34
+ </contributor>
35
+ <contributor>
36
+ <role type="authority"/>
37
+ <organization>
38
+ <name>GB</name>
39
+ </organization>
40
+ </contributor>
41
+ <contributor>
42
+ <role type="proposer"/>
43
+ <organization>
44
+ <name>GB</name>
45
+ </organization>
46
+ </contributor>
47
+ <contributor>
48
+ <role type="issuer"/>
49
+ <organization>
50
+ <name>GB</name>
51
+ </organization>
52
+ </contributor>
53
+
54
+ <language>en</language>
55
+ <script>Latn</script>
56
+ <status>
57
+ <stage>60</stage>
58
+ <substage>60</substage>
59
+ </status>
60
+ <copyright>
61
+ <from>2019</from>
62
+ <owner>
63
+ <organization>
64
+ <name>GB</name>
65
+ </organization>
66
+ </owner>
67
+ </copyright>
68
+ <relation type="nonequivalent">
69
+ <bibitem>
70
+ <title> Televisual Frequencies</title>
71
+ <docidentifier>ISO 1012</docidentifier>
72
+ </bibitem>
73
+ </relation>
74
+ <ext>
75
+ <doctype>recommendation</doctype>
76
+ <gbtype>
77
+ <gbscope>social-group</gbscope>
78
+ <gbprefix>AAA</gbprefix>
79
+ <gbmandate>recommendation</gbmandate>
80
+ <gbtopic>basic</gbtopic>
81
+ </gbtype>
82
+ </ext>
83
+ </bibdata>
84
+ <sections/>
85
+ </gb-standard
Binary file
Binary file
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "metanorma"
5
+ require "fileutils"
6
+ require "nokogiri"
7
+
8
+ registry = Metanorma::Registry.instance
9
+
10
+ supported_gem_paths = [
11
+ "asciidoctor-rfc",
12
+ "metanorma-iso",
13
+ "metanorma-gb",
14
+ "metanorma-csd",
15
+ "metanorma-csand",
16
+ "metanorma-m3d",
17
+ "metanorma-rsd",
18
+ "metanorma-acme",
19
+ "metanorma-standoc",
20
+ ]
21
+
22
+ puts "[metanorma] detecting backends:"
23
+ supported_gem_paths.each do |backend|
24
+ begin
25
+ puts backend
26
+ require backend
27
+ rescue LoadError
28
+ puts "[metanorma] backend #{backend} not present"
29
+ end
30
+ end
31
+ puts
32
+
33
+ options = {
34
+ format: :asciidoc
35
+ }
36
+ opt_parser = OptionParser.new do |opts|
37
+ opts.banner += " <file>"
38
+ opts.on(
39
+ '-t',
40
+ '--type TYPE',
41
+ "Type of standard to generate: #{registry.supported_backends.join(", ")}"
42
+ ) { |v| options[:type] = v.to_sym }
43
+
44
+ opts.on(
45
+ '-x',
46
+ '--extensions EXT1,EXT2,... | all',
47
+ Array,
48
+ "Type of extension to generate per type: #{registry.output_formats}\n"
49
+ ) { |v| options[:extension_keys] = v.map(&:to_sym) }
50
+
51
+ opts.on(
52
+ '-f',
53
+ '--format FORMAT',
54
+ 'Format of source file: asciidoc (current default, only format supported)'
55
+ ) { |v| options[:format] = v.to_sym }
56
+
57
+ opts.on(
58
+ '-r',
59
+ '--require LIBRARY',
60
+ 'Require LIBRARY prior to execution'
61
+ ) { |v|
62
+ options[:require] ||= []
63
+ options[:require] << v
64
+ }
65
+
66
+ opts.on(
67
+ '-v',
68
+ '--version',
69
+ "Print version of code (accompanied with -t)",
70
+ ) { options[:version] = true }
71
+
72
+ opts.on(
73
+ '-w',
74
+ '--wrapper',
75
+ 'Create wrapper folder for HTML output'
76
+ ) { options[:wrapper] = true }
77
+
78
+ opts.on(
79
+ '-d',
80
+ '--data-uri-image',
81
+ 'Encode HTML output images as data URIs'
82
+ ) { options[:datauriimage] = true }
83
+
84
+ opts.on(
85
+ '-R',
86
+ '--relaton FILENAME',
87
+ 'Export Relaton XML for document to nominated filename'
88
+ ) { |v| options[:relaton] = v }
89
+
90
+ opts.on_tail("-h", "--help", "Show this message") do
91
+ puts opts
92
+ exit
93
+ end
94
+
95
+ end
96
+
97
+ opt_parser.parse!(ARGV)
98
+
99
+ if options[:require]
100
+ options[:require].each do |r|
101
+ require r
102
+ end
103
+ end
104
+
105
+ if options[:version]
106
+ case options[:format]
107
+ when :asciidoc
108
+ processor = registry.find_processor(options[:type].to_sym)
109
+ puts processor.version
110
+ exit
111
+ end
112
+ end
113
+
114
+ options[:filename] = ARGV.pop
115
+
116
+ unless options[:type]
117
+ puts "[metanorma] Error: Please specify a standard type."
118
+ puts opt_parser.help
119
+ exit 0
120
+ end
121
+
122
+ unless registry.supported_backends.include? options[:type]
123
+ puts "[metanorma] Error: #{options[:type]} is not a supported standard type."
124
+ exit 0
125
+ end
126
+
127
+ unless options[:format] == :asciidoc
128
+ puts "[metanorma] Error: Only source file format currently supported is 'asciidoc'."
129
+ exit 0
130
+ end
131
+
132
+ unless options[:filename]
133
+ puts "[metanorma] Error: Need to specify a file to process."
134
+ exit 0
135
+ end
136
+
137
+ options[:extension_keys] = nil if options[:extension_keys] == [:all]
138
+
139
+ case options[:format]
140
+ when :asciidoc
141
+ processor = registry.find_processor(options[:type].to_sym)
142
+ options[:extension_keys] ||= processor.output_formats.inject([]) do |memo, (k, _)|
143
+ memo << k; memo
144
+ end
145
+ extensions = options[:extension_keys].inject([]) do |memo, e|
146
+ if processor.output_formats[e]
147
+ memo << e
148
+ else
149
+ warn "[metanorma] Error: #{e} format is not supported for this standard"
150
+ end
151
+ memo
152
+ end
153
+ exit 0 if extensions.empty?
154
+
155
+ file = File.read(options[:filename], encoding: "utf-8")
156
+ isodoc = processor.input_to_isodoc(file)
157
+ if options[:relaton]
158
+ xml = Nokogiri::XML(isodoc)
159
+ bibdata = xml.at("//xmlns:bibdata")
160
+ #docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
161
+ #outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
162
+ File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
163
+ end
164
+ isodoc_options = processor.extract_options(file)
165
+ isodoc_options[:datauriimage] = true if options[:datauriimage]
166
+ extensions.each do |ext|
167
+ file_extension = processor.output_formats[ext]
168
+ outfilename = options[:filename].sub(/\.[^.]+$/, ".#{file_extension}")
169
+ processor.output(isodoc, outfilename, ext, isodoc_options)
170
+ if options[:wrapper] and /html$/.match file_extension
171
+ outfilename = outfilename.sub(/\.html$/, "")
172
+ FileUtils.mkdir_p outfilename
173
+ FileUtils.mv "#{outfilename}.html", outfilename
174
+ FileUtils.mv "#{outfilename}_images", outfilename
175
+ end
176
+ end
177
+ end
178
+
@@ -0,0 +1,5 @@
1
+ def ruby(x)
2
+ if x < 0 && x > 1
3
+ return
4
+ end
5
+ end
Binary file
@@ -10,10 +10,10 @@ module Metanorma
10
10
  "metanorma-iec",
11
11
  "metanorma-ietf",
12
12
  "metanorma-gb",
13
- "metanorma-csd",
13
+ "metanorma-cc",
14
14
  "metanorma-csa",
15
15
  "metanorma-iho",
16
- "metanorma-m3d",
16
+ "metanorma-m3aawg",
17
17
  "metanorma-generic",
18
18
  "metanorma-standoc",
19
19
  "metanorma-un",
@@ -22,20 +22,7 @@ module Metanorma
22
22
  "metanorma-itu",
23
23
  ]
24
24
 
25
- # @TODO: Note
26
- #
27
- # This is temporary, we are going to extend this to
28
- # each of the metanorma gem, so they can specifcy their
29
- # own font requirements.
30
- #
31
- # Please add the whole set here.
32
- #
33
- REQUIRED_FONTS = [
34
- "CALIBRI.TTF",
35
- "CAMBRIA.TTC",
36
- ].freeze
37
-
38
- PRIVATE_SUPPORTED_GEMS = ["metanorma-rsd", "metanorma-mpfd"]
25
+ PRIVATE_SUPPORTED_GEMS = ["metanorma-ribose", "metanorma-mpfa"]
39
26
 
40
27
  def self.load_flavors(flavor_names = SUPPORTED_GEMS + PRIVATE_SUPPORTED_GEMS)
41
28
  flavor_names.each do |flavor|
@@ -29,11 +29,14 @@ module Metanorma
29
29
  option :relaton, aliases: "-R", desc: "Export Relaton XML for document to nominated filename"
30
30
  option :extract, aliases: "-e", desc: "Export sourcecode fragments from this document to nominated directory"
31
31
  option :version, aliases: "-v", desc: "Print version of code (accompanied with -t)"
32
+ option "output-dir", aliases: "-o", desc: "Directory to save compiled files"
32
33
 
33
34
  def compile(file_name = nil)
34
35
  if file_name && !options[:version]
35
36
  Metanorma::Cli.load_flavors
36
- Metanorma::Cli::Compiler.compile(file_name, options.dup)
37
+ errs = Metanorma::Cli::Compiler.compile(file_name, options.dup)
38
+ errs.each { |e| Util.log e, :error }
39
+ exit(1) if errs.any?
37
40
 
38
41
  elsif options[:version]
39
42
  invoke(:version, [], type: options[:type], format: options[:format])
@@ -51,6 +54,7 @@ module Metanorma
51
54
  option :format, aliases: "-f", default: :asciidoc, desc: "Format of source file: eg. asciidoc"
52
55
 
53
56
  def version
57
+ Metanorma::Cli.load_flavors
54
58
  backend_version(options[:type]) || supported_backends
55
59
  rescue NameError => error
56
60
  UI.say(error)
@@ -76,11 +80,15 @@ module Metanorma
76
80
  )
77
81
 
78
82
  def setup
79
- Metanorma::Cli::REQUIRED_FONTS.each do |font|
80
- Metanorma::Cli::Setup.run(
81
- font: font,
82
- term_agreement: options[:agree_to_terms],
83
- )
83
+ list_required_fonts.each do |font|
84
+ begin
85
+ Metanorma::Cli::Setup.run(
86
+ font: font,
87
+ term_agreement: options[:agree_to_terms],
88
+ )
89
+ rescue Fontist::Errors::NonSupportedFontError
90
+ UI.say("[info]: Font `#{font}` is not supported yet!")
91
+ end
84
92
  end
85
93
  end
86
94
 
@@ -113,7 +121,7 @@ module Metanorma
113
121
  end
114
122
 
115
123
  def find_backend(type)
116
- require "metanorma-#{type}"
124
+ load_flavours(type)
117
125
  Metanorma::Registry.instance.find_processor(type&.to_sym)
118
126
  end
119
127
 
@@ -141,6 +149,26 @@ module Metanorma
141
149
  overwrite: options[:overwrite],
142
150
  )
143
151
  end
152
+
153
+ def list_required_fonts
154
+ Metanorma::Cli.load_flavors
155
+
156
+ Metanorma::Registry.instance.processors.map do |_key, processor|
157
+ flavour = processor.class.to_s.gsub("::Processor", "")
158
+ flavour_module = Object.const_get(flavour)
159
+
160
+ if flavour_module.respond_to?(:fonts_used)
161
+ flavour_module.fonts_used.map { |_, value| value }.flatten
162
+ end
163
+ end.compact.flatten.uniq
164
+ end
165
+
166
+ def load_flavours(type)
167
+ Metanorma::Cli.load_flavors
168
+ unless Metanorma::Registry.instance.find_processor(type&.to_sym)
169
+ require "metanorma-#{type}"
170
+ end
171
+ end
144
172
  end
145
173
  end
146
174
  end