relaton-cli 1.2.1 → 1.3.0
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/docs/README.adoc +8 -0
- data/exe/relaton +0 -1
- data/lib/relaton/bibdata.rb +1 -1
- data/lib/relaton/cli/base_convertor.rb +1 -8
- data/lib/relaton/cli/command.rb +21 -2
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/yaml_convertor.rb +9 -9
- data/relaton-cli.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7283d682da8a6ace042d4184849ff7007784a240498c11164a235bf6cf38e20f
|
4
|
+
data.tar.gz: 17c8c09ebd535f8851c487843d709077aac4a63b11cf145f97e71cccb41ea1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29d79e044e21d3c8392fc8d28231e9b8646b227de12bb09669cf9d737d82cc6972c97cce1a0e9c291f132925805c00c3d43eb2a467e93ffbcd99185af7229504
|
7
|
+
data.tar.gz: 37952a6bb4ba3feb6cf88ce60a3899428e6da7686c719a6030e4fb6e851609e8c4a2279cfc333d60dae5e094cde8859f8c4f248606f2daa032b052949a6a6f35
|
data/docs/README.adoc
CHANGED
@@ -209,3 +209,11 @@ $ relaton yaml2html YAML [<stylesheet>] [<liquid-template-dir>]
|
|
209
209
|
|
210
210
|
Render a Relaton YAML file (`filename.yaml`) as an HTML file. The `stylesheet` and `liquid-template-dir` directories are as for <<relaton-xml2html,relaton xml2html>>.
|
211
211
|
|
212
|
+
=== relaton convert
|
213
|
+
|
214
|
+
[source,conxole]
|
215
|
+
----
|
216
|
+
$ relaton convert XML -f FORMAT -o OUTPUT-FILE
|
217
|
+
----
|
218
|
+
|
219
|
+
Convert a Relaton XML document into YAML, AsciiBib, or BibTex format. Allowed -f or --format options are yaml, asciibib, bibtex. If the option -o or --output is omitted then a new file will be created in the folder where the original file is, with the same name but another appropriated extension.
|
data/exe/relaton
CHANGED
data/lib/relaton/bibdata.rb
CHANGED
@@ -39,7 +39,7 @@ module Relaton
|
|
39
39
|
file,
|
40
40
|
style: style || File.join(File.dirname(__FILE__), "../../../templates/index-style.css"),
|
41
41
|
template: template || File.join(File.dirname(__FILE__), "../../../templates/"),
|
42
|
-
extension: "html"
|
42
|
+
extension: "html"
|
43
43
|
).to_html
|
44
44
|
end
|
45
45
|
|
@@ -91,13 +91,6 @@ module Relaton
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def write_to_file_collection(content, format)
|
94
|
-
# if outdir && (content.is_a?(Relaton::Bibcollection))
|
95
|
-
# FileUtils.mkdir_p(outdir)
|
96
|
-
# content.items_flattened.each do |item|
|
97
|
-
# collection = collection_filename(item.docidentifier_code)
|
98
|
-
# write_to_a_file(item_output(item, format), collection)
|
99
|
-
# end
|
100
|
-
# end
|
101
94
|
if outdir && content.is_a?(Relaton::Bibcollection)
|
102
95
|
FileUtils.mkdir_p(outdir)
|
103
96
|
content.items_flattened.each do |item|
|
data/lib/relaton/cli/command.rb
CHANGED
@@ -45,7 +45,7 @@ module Relaton
|
|
45
45
|
desc "yaml2xml YAML", "Convert Relaton YAML into Relaton Collection XML or separate files"
|
46
46
|
option :extension, aliases: :x, default: "rxl", desc: "File extension of Relaton XML files, defaults to 'rxl'"
|
47
47
|
option :prefix, aliases: :p, desc: "Filename prefix of individual Relaton XML files, defaults to empty"
|
48
|
-
option :outdir, aliases: :o,
|
48
|
+
option :outdir, aliases: :o, desc: "Output to the specified directory with individual Relaton Bibdata XML files"
|
49
49
|
option :require, aliases: :r, type: :array, desc: "Require LIBRARY prior to execution"
|
50
50
|
option :overwrite, aliases: :f, type: :boolean, default: false, desc: "Overwrite the existing file"
|
51
51
|
|
@@ -53,7 +53,7 @@ module Relaton
|
|
53
53
|
Relaton::Cli::YAMLConvertor.to_xml(filename, options)
|
54
54
|
end
|
55
55
|
|
56
|
-
desc "
|
56
|
+
desc "xml2yaml XML", "Convert Relaton XML into Relaton Bibdata / Bibcollection YAML (and separate files)"
|
57
57
|
option :extension, aliases: :x, default: "yaml", desc: "File extension of Relaton YAML files, defaults to 'yaml'"
|
58
58
|
option :prefix, aliases: :p, desc: "Filename prefix of Relaton XML files, defaults to empty"
|
59
59
|
option :outdir, aliases: :o, desc: "Output to the specified directory with individual Relaton Bibdata YAML files"
|
@@ -82,6 +82,25 @@ module Relaton
|
|
82
82
|
Relaton::Cli::YAMLConvertor.to_html(file, style, template)
|
83
83
|
end
|
84
84
|
|
85
|
+
desc "convert XML", "Convert Relaton XML document"
|
86
|
+
option :format, aliases: :f, required: true, desc: "Output format (yaml, bibtex, asciibib)"
|
87
|
+
option :output, aliases: :o, desc: "Output to the specified file"
|
88
|
+
|
89
|
+
def convert(file)
|
90
|
+
item = Relaton::Cli.parse_xml Nokogiri::XML(File.read(file, encoding: "UTF-8"))
|
91
|
+
result = if /yaml|yml/.match?(options[:format])
|
92
|
+
item.to_hash.to_yaml
|
93
|
+
else item.send "to_#{options[:format]}"
|
94
|
+
end
|
95
|
+
ext = case options[:format]
|
96
|
+
when "bibtex" then "bib"
|
97
|
+
when "asciibib" then "adoc"
|
98
|
+
else options[:format]
|
99
|
+
end
|
100
|
+
output = options[:output] || file.sub(/(?<=\.)[^\.]+$/, ext)
|
101
|
+
File.write output, result, encoding: "UTF-8"
|
102
|
+
end
|
103
|
+
|
85
104
|
private
|
86
105
|
|
87
106
|
# @param code [String]
|
data/lib/relaton/cli/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "yaml"
|
2
|
+
require "relaton/cli/base_convertor"
|
3
|
+
require "relaton_bib"
|
4
4
|
|
5
5
|
module Relaton
|
6
6
|
module Cli
|
@@ -33,7 +33,7 @@ module Relaton
|
|
33
33
|
# @return [RelatonBib::BibliographicItem,
|
34
34
|
# RelatonIso::IsoBiblioraphicItem]
|
35
35
|
def convert_single_file(content)
|
36
|
-
if (processor = Registry.instance.by_type(doctype(content[
|
36
|
+
if (processor = Registry.instance.by_type(doctype(content["docid"])))
|
37
37
|
processor.hash_to_bib content
|
38
38
|
else
|
39
39
|
RelatonBib::BibliographicItem.new(
|
@@ -50,14 +50,14 @@ module Relaton
|
|
50
50
|
did = docid.is_a?(Array) ? docid.fetch(0) : docid
|
51
51
|
return unless did
|
52
52
|
|
53
|
-
did[
|
53
|
+
did["type"] || did.fetch("id")&.match(/^\w+/)&.to_s
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def default_ext
|
60
|
-
|
60
|
+
"rxl"
|
61
61
|
end
|
62
62
|
|
63
63
|
def file_content
|
@@ -78,12 +78,12 @@ module Relaton
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def convert_collection(content)
|
81
|
-
if content.has_key?(
|
82
|
-
content[
|
81
|
+
if content.has_key?("root")
|
82
|
+
content["root"]["items"] = content["root"]["items"].map do |i|
|
83
83
|
# RelatonBib::HashConverter::hash_to_bib(i)
|
84
84
|
self.class.convert_single_file(i)
|
85
85
|
end
|
86
|
-
Relaton::Bibcollection.new(content[
|
86
|
+
Relaton::Bibcollection.new(content["root"])
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/relaton-cli.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "simplecov"
|
35
35
|
|
36
36
|
spec.add_runtime_dependency "liquid"
|
37
|
-
spec.add_runtime_dependency "relaton", "~> 1.
|
37
|
+
spec.add_runtime_dependency "relaton", "~> 1.3.0"
|
38
38
|
spec.add_runtime_dependency "thor"
|
39
39
|
# spec.add_runtime_dependency 'byebug'
|
40
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
173
|
+
version: 1.3.0
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
180
|
+
version: 1.3.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: thor
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|