metanorma 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +109 -4
- data/README.adoc +21 -0
- data/lib/metanorma/compile.rb +129 -0
- data/lib/metanorma/input/asciidoc.rb +2 -2
- data/lib/metanorma/version.rb +1 -1
- data/lib/metanorma.rb +1 -0
- data/metanorma.gemspec +3 -1
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb15f89f287c512af20258dac7a165a493d10fd69918c72597e599caa693712d
|
4
|
+
data.tar.gz: f185683fe26b26c49d3aa47542b924836dd6e87c9d5bee38647c578078e232bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f2174db12ddf90334042c9804e35b53ff6195703187bd19d2d82ad204d1c66505e3421ac71d635a18491f1b08aaf3885c698b4c49d329c562a8422e4ea9bddf
|
7
|
+
data.tar.gz: d306825846bd6bcd187741eec4ac806214bf2979143f3cb325167483d9050c1f07823b9143f146e2980bca868c9631d2d23e52502e15a619e1b249d41b477484
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,109 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
metanorma (0.3.
|
4
|
+
metanorma (0.3.5)
|
5
5
|
asciidoctor
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
algoliasearch (1.24.0)
|
13
|
+
httpclient (~> 2.8, >= 2.8.3)
|
14
|
+
json (>= 1.5.1)
|
10
15
|
asciidoctor (1.5.8)
|
16
|
+
asciimath (1.0.6)
|
11
17
|
byebug (10.0.2)
|
18
|
+
cnccs (0.1.3)
|
19
|
+
concurrent-ruby (1.1.3)
|
12
20
|
diff-lcs (1.3)
|
13
21
|
equivalent-xml (0.6.0)
|
14
22
|
nokogiri (>= 1.4.3)
|
23
|
+
ffi (1.9.25)
|
24
|
+
gb-agencies (0.0.5)
|
25
|
+
gbbib (0.4.3)
|
26
|
+
cnccs (~> 0.1.1)
|
27
|
+
gb-agencies (~> 0.0.1)
|
28
|
+
iso-bib-item (~> 0.4.2)
|
29
|
+
html2doc (0.8.6)
|
30
|
+
asciimath
|
31
|
+
htmlentities (~> 4.3.4)
|
32
|
+
image_size
|
33
|
+
mime-types
|
34
|
+
nokogiri
|
35
|
+
ruby-xslt
|
36
|
+
thread_safe
|
37
|
+
uuidtools
|
38
|
+
htmlentities (4.3.4)
|
39
|
+
httpclient (2.8.3)
|
40
|
+
iecbib (0.2.2)
|
41
|
+
addressable
|
42
|
+
iso-bib-item (~> 0.4.2)
|
43
|
+
ietfbib (0.4.5)
|
44
|
+
iso-bib-item (~> 0.4.2)
|
45
|
+
iev (0.2.0)
|
46
|
+
nokogiri
|
47
|
+
image_size (2.0.0)
|
48
|
+
iso-bib-item (0.4.4)
|
49
|
+
isoics (~> 0.1.6)
|
50
|
+
nokogiri (~> 1.8.4)
|
51
|
+
ruby_deep_clone (~> 0.8.0)
|
52
|
+
isobib (0.4.2)
|
53
|
+
algoliasearch
|
54
|
+
iecbib (~> 0.2.1)
|
55
|
+
iso-bib-item (~> 0.4.2)
|
56
|
+
isodoc (0.9.11)
|
57
|
+
asciimath
|
58
|
+
html2doc (~> 0.8.6)
|
59
|
+
htmlentities (~> 4.3.4)
|
60
|
+
liquid
|
61
|
+
metanorma (~> 0.3.0)
|
62
|
+
nokogiri
|
63
|
+
rake (~> 12.0)
|
64
|
+
roman-numerals
|
65
|
+
ruby-xslt
|
66
|
+
sassc (~> 1.12.1)
|
67
|
+
thread_safe
|
68
|
+
uuidtools
|
69
|
+
isoics (0.1.7)
|
70
|
+
json (2.1.0)
|
71
|
+
liquid (4.0.1)
|
72
|
+
metanorma-iso (1.0.11)
|
73
|
+
asciidoctor (~> 1.5.7)
|
74
|
+
iev (~> 0.2.0)
|
75
|
+
isodoc (~> 0.9.8)
|
76
|
+
metanorma-standoc (~> 1.0.0)
|
77
|
+
ruby-jing
|
78
|
+
metanorma-standoc (1.0.11)
|
79
|
+
asciidoctor (~> 1.5.7)
|
80
|
+
concurrent-ruby
|
81
|
+
iev (~> 0.2.0)
|
82
|
+
isodoc (~> 0.9.0)
|
83
|
+
relaton (~> 0.3.1)
|
84
|
+
ruby-jing
|
85
|
+
sterile
|
86
|
+
mime-types (3.2.2)
|
87
|
+
mime-types-data (~> 3.2015)
|
88
|
+
mime-types-data (3.2018.0812)
|
15
89
|
mini_portile2 (2.3.0)
|
16
|
-
mixlib-shellout (2.4.
|
90
|
+
mixlib-shellout (2.4.2)
|
17
91
|
nokogiri (1.8.5)
|
18
92
|
mini_portile2 (~> 2.3.0)
|
19
|
-
|
93
|
+
optout (0.0.2)
|
94
|
+
public_suffix (3.0.3)
|
95
|
+
rake (12.3.2)
|
96
|
+
rb-fsevent (0.10.3)
|
97
|
+
rb-inotify (0.9.10)
|
98
|
+
ffi (>= 0.5.0, < 2)
|
99
|
+
relaton (0.3.1)
|
100
|
+
algoliasearch
|
101
|
+
gbbib (~> 0.4.0)
|
102
|
+
iecbib (~> 0.2.0)
|
103
|
+
ietfbib (~> 0.4.2)
|
104
|
+
iso-bib-item (~> 0.4.2)
|
105
|
+
isobib (~> 0.4.0)
|
106
|
+
roman-numerals (0.3.0)
|
20
107
|
rspec (3.8.0)
|
21
108
|
rspec-core (~> 3.8.0)
|
22
109
|
rspec-expectations (~> 3.8.0)
|
@@ -37,6 +124,22 @@ GEM
|
|
37
124
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
125
|
rspec-support (~> 3.8.0)
|
39
126
|
rspec-support (3.8.0)
|
127
|
+
ruby-jing (0.0.1)
|
128
|
+
optout (>= 0.0.2)
|
129
|
+
ruby-xslt (0.9.10)
|
130
|
+
ruby_deep_clone (0.8.0)
|
131
|
+
sass (3.7.2)
|
132
|
+
sass-listen (~> 4.0.0)
|
133
|
+
sass-listen (4.0.0)
|
134
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
135
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
136
|
+
sassc (1.12.1)
|
137
|
+
ffi (~> 1.9.6)
|
138
|
+
sass (>= 3.3.0)
|
139
|
+
sterile (1.0.13)
|
140
|
+
nokogiri
|
141
|
+
thread_safe (0.3.6)
|
142
|
+
uuidtools (2.1.5)
|
40
143
|
|
41
144
|
PLATFORMS
|
42
145
|
ruby
|
@@ -45,8 +148,10 @@ DEPENDENCIES
|
|
45
148
|
bundler (~> 1.16)
|
46
149
|
byebug (~> 10.0)
|
47
150
|
equivalent-xml (~> 0.6)
|
151
|
+
isodoc (= 0.9.11)
|
48
152
|
metanorma!
|
49
|
-
|
153
|
+
metanorma-iso
|
154
|
+
rake (~> 12.0)
|
50
155
|
rspec (~> 3.0)
|
51
156
|
rspec-command (~> 1.0.3)
|
52
157
|
|
data/README.adoc
CHANGED
@@ -168,6 +168,8 @@ HTML renderings (e.g. `html_alt` for ISO).
|
|
168
168
|
the same as the output file, without the `.html` suffix. Used to make distribution of HTML outputs
|
169
169
|
more straightforward.
|
170
170
|
|
171
|
+
`datauriimage`:: Encode all images as data URIs.
|
172
|
+
|
171
173
|
`relaton`:: exports the bibdata Relaton XML description of the document (which is part of its Metanorma XML)
|
172
174
|
to the nominated directory. The filename is the document identifier, if present, else the document filename.
|
173
175
|
|
@@ -207,6 +209,25 @@ of document attributes `mn-document-class:` and `:mn-output-extensions:`, e.g.
|
|
207
209
|
.Foreword
|
208
210
|
----
|
209
211
|
|
212
|
+
Metanorma can also be invoked within Ruby, through the metanorma gem:
|
213
|
+
|
214
|
+
[source,asciidoctor]
|
215
|
+
----
|
216
|
+
require "metanorma"
|
217
|
+
|
218
|
+
Metanorma::Compile.new().compile(filename, options)
|
219
|
+
----
|
220
|
+
|
221
|
+
The options hash has the same structure it does when invoked in metanorma-cli:
|
222
|
+
|
223
|
+
`:type`:: one of `"iso"`, `"csd"`, `"rsd"`, etc. (mandatory)
|
224
|
+
`:format`:: `:asciidoc` is only value currently allowed
|
225
|
+
`:extension_keys`:: array of symbols: `:all`, `:xml`:, `:doc` etc.
|
226
|
+
`:wrapper`: true/false
|
227
|
+
`:darauriimage`: true/false
|
228
|
+
`:require`: array of libraries to require
|
229
|
+
`:relaton`: exports the bibdata Relaton XML description of the document (which is part of its Metanorma XML)
|
230
|
+
to the nominated directory
|
210
231
|
|
211
232
|
== Origin of name
|
212
233
|
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module Metanorma
|
5
|
+
class Compile
|
6
|
+
def initialize
|
7
|
+
@registry = Metanorma::Registry.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def compile(filename, options = {})
|
11
|
+
options = options_extract(filename, options)
|
12
|
+
validate(options) or return nil
|
13
|
+
require_libraries(options)
|
14
|
+
@processor = @registry.find_processor(options[:type].to_sym)
|
15
|
+
extensions = get_extensions(options) or return nil
|
16
|
+
(file, isodoc = process_input(filename)) or return nil
|
17
|
+
relaton_export(isodoc, options)
|
18
|
+
process_extensions(extensions, file, isodoc, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def require_libraries(options)
|
22
|
+
if options[:require]
|
23
|
+
options[:require].each do |r|
|
24
|
+
require r
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def options_extract(filename, options)
|
30
|
+
o = Metanorma::Input::Asciidoc.new.extract_metanorma_options(File.read(filename, encoding: "utf-8"))
|
31
|
+
options[:type] ||= o[:type]&.to_sym
|
32
|
+
options[:extension_keys] ||= o[:extensions]&.split(/,[ ]*/)&.map(&:to_sym)
|
33
|
+
options[:extension_keys] = nil if options[:extension_keys] == [:all]
|
34
|
+
options[:format] ||= :asciidoc
|
35
|
+
options[:filename] = filename
|
36
|
+
options
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate(options)
|
40
|
+
validate_type(options) && validate_format(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_type(options)
|
44
|
+
unless options[:type]
|
45
|
+
puts "[metanorma] Error: Please specify a standard type: #{@registry.supported_backends}."
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
stdtype = options[:type].to_sym
|
49
|
+
unless @registry.supported_backends.include? stdtype
|
50
|
+
puts "[metanorma] Warning: #{stdtype} is not a default standard type."
|
51
|
+
puts "[metanorma] Info: Attempting to load `metanorma-#{stdtype}` gem for standard type `#{stdtype}`."
|
52
|
+
end
|
53
|
+
begin
|
54
|
+
require "metanorma-#{stdtype}"
|
55
|
+
puts "[metanorma] Info: gem `metanorma-#{stdtype}` loaded."
|
56
|
+
rescue LoadError
|
57
|
+
puts "[metanorma] Error: loading gem `metanorma-#{stdtype}` failed. Exiting."
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
unless @registry.supported_backends.include? stdtype
|
61
|
+
puts "[metanorma] Error: The `metanorma-#{stdtype}` gem still doesn't support `#{stdtype}`. Exiting."
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_format(options)
|
68
|
+
unless options[:format] == :asciidoc
|
69
|
+
puts "[metanorma] Error: Only source file format currently supported is 'asciidoc'."
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_extensions(options)
|
76
|
+
options[:extension_keys] ||= @processor.output_formats.inject([]) do |memo, (k, _)|
|
77
|
+
memo << k; memo
|
78
|
+
end
|
79
|
+
extensions = options[:extension_keys].inject([]) do |memo, e|
|
80
|
+
@processor.output_formats[e] and memo << e or
|
81
|
+
puts "[metanorma] Error: #{e} format is not supported for this standard."
|
82
|
+
memo
|
83
|
+
end
|
84
|
+
extensions
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_input(filename)
|
88
|
+
case extname = File.extname(filename)
|
89
|
+
when ".adoc"
|
90
|
+
puts "[metanorma] Processing: Asciidoctor input."
|
91
|
+
file = File.read(filename, encoding: "utf-8")
|
92
|
+
[file, @processor.input_to_isodoc(file, filename)]
|
93
|
+
when ".xml"
|
94
|
+
puts "[metanorma] Processing: Metanorma XML input."
|
95
|
+
# TODO NN: this is a hack -- we should provide/bridge the
|
96
|
+
# document attributes in Metanorma XML
|
97
|
+
["", File.read(filename, encoding: "utf-8")]
|
98
|
+
else
|
99
|
+
puts "[metanorma] Error: file extension #{extname} is not supported."
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def relaton_export(isodoc, options)
|
105
|
+
return unless options[:relaton]
|
106
|
+
xml = Nokogiri::XML(isodoc)
|
107
|
+
bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
|
108
|
+
#docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
|
109
|
+
#outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
|
110
|
+
File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
|
111
|
+
end
|
112
|
+
|
113
|
+
def process_extensions(extensions, file, isodoc, options)
|
114
|
+
extensions.each do |ext|
|
115
|
+
isodoc_options = @processor.extract_options(file)
|
116
|
+
isodoc_options[:datauriimage] = true if options[:datauriimage]
|
117
|
+
file_extension = @processor.output_formats[ext]
|
118
|
+
outfilename = options[:filename].sub(/\.[^.]+$/, ".#{file_extension}")
|
119
|
+
@processor.output(isodoc, outfilename, ext, isodoc_options)
|
120
|
+
if options[:wrapper] and /html$/.match file_extension
|
121
|
+
outfilename = outfilename.sub(/\.html$/, "")
|
122
|
+
FileUtils.mkdir_p outfilename
|
123
|
+
FileUtils.mv "#{outfilename}.html", outfilename
|
124
|
+
FileUtils.mv "#{outfilename}_images", outfilename, force: true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -46,7 +46,7 @@ module Metanorma
|
|
46
46
|
/\n:wordintropage: (?<wordintropage>[^\n]+)\n/ =~ headerextract
|
47
47
|
/\n:ulstyle: (?<ulstyle>[^\n]+)\n/ =~ headerextract
|
48
48
|
/\n:olstyle: (?<olstyle>[^\n]+)\n/ =~ headerextract
|
49
|
-
/\n
|
49
|
+
/\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ headerextract
|
50
50
|
{
|
51
51
|
script: defined?(script) ? script : nil,
|
52
52
|
bodyfont: defined?(bodyfont) ? bodyfont : nil,
|
@@ -66,7 +66,7 @@ module Metanorma
|
|
66
66
|
wordintropage: defined?(wordintropage) ? wordintropage : nil,
|
67
67
|
ulstyle: defined?(ulstyle) ? ulstyle : nil,
|
68
68
|
olstyle: defined?(olstyle) ? olstyle : nil,
|
69
|
-
datauriimage: defined?(datauriimage) ?
|
69
|
+
datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
|
70
70
|
}.reject { |_, val| val.nil? }
|
71
71
|
end
|
72
72
|
|
data/lib/metanorma/version.rb
CHANGED
data/lib/metanorma.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -27,9 +27,11 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_runtime_dependency 'asciidoctor'
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.16"
|
30
|
-
spec.add_development_dependency "rake", "~>
|
30
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
spec.add_development_dependency "byebug", "~> 10.0"
|
33
33
|
spec.add_development_dependency "rspec-command", "~> 1.0.3"
|
34
34
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
35
|
+
spec.add_development_dependency "metanorma-iso"
|
36
|
+
spec.add_development_dependency "isodoc", "0.9.11"
|
35
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: metanorma-iso
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: isodoc
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.9.11
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.9.11
|
111
139
|
description: Library to process any Metanorma standard.
|
112
140
|
email:
|
113
141
|
- open.source@ribose.com
|
@@ -138,6 +166,7 @@ files:
|
|
138
166
|
- lib/metanorma.rb
|
139
167
|
- lib/metanorma/asciidoctor_extensions.rb
|
140
168
|
- lib/metanorma/asciidoctor_extensions/glob_include_processor.rb
|
169
|
+
- lib/metanorma/compile.rb
|
141
170
|
- lib/metanorma/document.rb
|
142
171
|
- lib/metanorma/input.rb
|
143
172
|
- lib/metanorma/input/asciidoc.rb
|