relaton-cli 1.5.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +46 -0
- data/Gemfile +0 -1
- data/docs/README.adoc +93 -5
- data/lib/relaton/bibcollection.rb +53 -35
- data/lib/relaton/bibdata.rb +2 -0
- data/lib/relaton/cli.rb +46 -28
- data/lib/relaton/cli/base_convertor.rb +1 -1
- data/lib/relaton/cli/command.rb +74 -36
- data/lib/relaton/cli/full_text_search.rb +91 -0
- data/lib/relaton/cli/relaton_file.rb +1 -1
- data/lib/relaton/cli/subcommand_collection.rb +221 -0
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_to_html_renderer.rb +14 -7
- data/lib/relaton/cli/yaml_convertor.rb +1 -1
- data/lib/relaton/element_finder.rb +5 -5
- data/relaton-cli.gemspec +7 -6
- data/templates/_index.liquid +9 -1
- metadata +29 -29
- data/.github/workflows/macos.yml +0 -32
- data/.github/workflows/ubuntu.yml +0 -32
- data/.github/workflows/windows.yml +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9983d2d6b80b1d1ac3a1ad7da07f4de43d8509c44c61c050ab2046c11580c8bc
|
4
|
+
data.tar.gz: '09593a750543ab10dae21731732f7858c5467bd30494613e5b59c00f0967bbb9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1419b4f0fdc45ca4dc5f9674eff0a9784ae89d6159a8bf23e4168d3f61776f28ddfd8caf76dc0540bf310e7b730095d94db03e7a5be95340cf668896d5446ed0
|
7
|
+
data.tar.gz: 5e4c6b9d094841f358566238406a6a08b1ad1080e33b48b190807c126c41fa17498f8f1b5707d66ac6f97aea06a04d73b567663fd6328e65db8dfc04b96d2736
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '3.0'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '3.0'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '3.0'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
with:
|
35
|
+
submodules: true
|
36
|
+
|
37
|
+
# https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
|
38
|
+
- if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
|
39
|
+
run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
|
40
|
+
|
41
|
+
- uses: ruby/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
44
|
+
bundler-cache: true
|
45
|
+
|
46
|
+
- run: bundle exec rake
|
data/Gemfile
CHANGED
data/docs/README.adoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= Relaton CLI (relaton-cli): Relaton Command-line Interface
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/relaton-cli.svg["Gem Version", link="https://rubygems.org/gems/relaton-cli"]
|
4
|
-
image:https://github.com/relaton/relaton-cli/workflows/
|
5
|
-
image:https://github.com/relaton/relaton-cli/workflows/macos/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=macos"]
|
6
|
-
image:https://github.com/relaton/relaton-cli/workflows/windows/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=windows"]
|
4
|
+
image:https://github.com/relaton/relaton-cli/workflows/rake/badge.svg["Build Status", link="https://github.com/relaton/relaton-cli/actions?workflow=rake"]
|
7
5
|
image:https://codeclimate.com/github/metanorma/relaton-cli/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/relaton-cli"]
|
8
6
|
|
9
7
|
Documentation in development.
|
@@ -50,8 +48,7 @@ Fetch the Relaton XML entry corresponding to the document identifier `CODE`.
|
|
50
48
|
|
51
49
|
* `YEAR` is optional, and specifies the year of publication of the standard.
|
52
50
|
* `FORMAT` is optional, and specifies the output format; the recognised values for `FORMAT` are `xml` (default), `bibtex`.
|
53
|
-
* `TYPE` specifies the standards class library to be used, that the identifier is part of
|
54
|
-
values for `TYPE` are `isobib`, `ietfbib`, `iecbib`, `gbbib`.
|
51
|
+
* `TYPE` specifies the standards class library to be used, that the identifier is part of. The recognised values for `TYPE` are `BIPM`, `CC`, `CN`, `IEC`, `IEEE`, `IETF`, `IHO`, `ISO`, `ITU`, `NIST`, `OGC`, `OMG`, `UN`, `W3C`.
|
55
52
|
|
56
53
|
=== relaton extract
|
57
54
|
|
@@ -217,3 +214,94 @@ $ relaton convert XML -f FORMAT -o OUTPUT-FILE
|
|
217
214
|
----
|
218
215
|
|
219
216
|
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.
|
217
|
+
|
218
|
+
=== relaton collection
|
219
|
+
|
220
|
+
The `relaton collection` is a set of subcommands for collections manipulations.
|
221
|
+
|
222
|
+
==== relaton collection create
|
223
|
+
|
224
|
+
----
|
225
|
+
$ relaton collection create COLLECTION -d DIRECTORY --author AUTHOR --title TITLE --doctype DOCTYPE
|
226
|
+
----
|
227
|
+
|
228
|
+
Create new empty collection with name `COLLECTION`.
|
229
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
230
|
+
* `AUTHOR`, `TITLE`, and `DOCTYPE` are optional.
|
231
|
+
|
232
|
+
==== relaton collection info
|
233
|
+
|
234
|
+
----
|
235
|
+
$ relaton collection info COLLECTION -d DIRECTORY
|
236
|
+
----
|
237
|
+
|
238
|
+
Show information about `COLLECTION` (number of items, file size of collection, last updated, name, metadata).
|
239
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
240
|
+
|
241
|
+
==== relaton collection list
|
242
|
+
|
243
|
+
----
|
244
|
+
$ relaton collection list -d DIRECTORY -e
|
245
|
+
----
|
246
|
+
|
247
|
+
List all collections.
|
248
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
249
|
+
* When parametr `-e` is defined the id of each entry id will be listed.
|
250
|
+
|
251
|
+
==== relaton collection get
|
252
|
+
|
253
|
+
----
|
254
|
+
$ relaton collection get CODE -c COLLECTION -d DIRECTORY -f FORMAT -o FILE
|
255
|
+
----
|
256
|
+
|
257
|
+
Get a document matched to `CODE` from `COLLECTION`.
|
258
|
+
|
259
|
+
* `COLLECTION` is optional name of collection. If undefined then fetch the first match across all collections in `DIRECTORY`.
|
260
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
261
|
+
* `FORMAT` is optional. If udefined then print documern in a human-readable form. Allowed values are `abb` (AsciiBib) or `xml` (XML).
|
262
|
+
* `FILE` is optional. When it's defined then save document with given file name. File's extension defines format of the file. Possible extensions are `abb` (AsciiBib) or `xml` (XML).
|
263
|
+
|
264
|
+
==== relaton collection find
|
265
|
+
|
266
|
+
----
|
267
|
+
$ relaton collection find TEXT -c COLLECTION -d DIRECTORY
|
268
|
+
----
|
269
|
+
|
270
|
+
Full-text search through a collection or all collections.
|
271
|
+
|
272
|
+
* `COLLECTION` is optional name of collection. If udefined then search across all collections.
|
273
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
274
|
+
|
275
|
+
==== relaton collection fetch
|
276
|
+
|
277
|
+
----
|
278
|
+
$ relaton collection fetch CODE -t TYPE -y YEAR -c COLLECTION -d DIRECTORY
|
279
|
+
----
|
280
|
+
|
281
|
+
Fetch the Relaton XML entry corresponding to the document identifier `CODE` and save it into `COLLECTION`.
|
282
|
+
|
283
|
+
* `TYPE` specifies the standards class library to be used, that the identifier is part of. The recognised values for `TYPE` are `BIPM`, `CC`, `CN`, `IEC`, `IEEE`, `IETF`, `IHO`, `ISO`, `ITU`, `NIST`, `OGC`, `OMG`, `UN`, `W3C`.
|
284
|
+
* `YEAR` is optional, and specifies the year of publication of the standard.
|
285
|
+
* `COLLECTION` is a name of collection.
|
286
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
287
|
+
|
288
|
+
==== relaton collection export
|
289
|
+
|
290
|
+
----
|
291
|
+
$ relaton collection export COLLECTION -d DIRECTORY
|
292
|
+
----
|
293
|
+
|
294
|
+
Export `COLLECTION` into XML file.
|
295
|
+
|
296
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
297
|
+
|
298
|
+
==== relaton collection import
|
299
|
+
|
300
|
+
----
|
301
|
+
$ relaton collection import FILE -c COLLECTION -d DIRECTORY
|
302
|
+
----
|
303
|
+
|
304
|
+
Import document or collection from XML `FILE` into `COLLECTION`.
|
305
|
+
|
306
|
+
* `COLLECTION` is optional. If collection doesn't exist then it will be created.
|
307
|
+
* `DIRECTORY` is optional, and specifies path to a directory with collections. Default is `$HOME/.relaton/collections`.
|
@@ -8,36 +8,34 @@ module Relaton
|
|
8
8
|
|
9
9
|
attr_accessor *ATTRIBS
|
10
10
|
|
11
|
-
#
|
12
|
-
|
11
|
+
# @param options [Hash]
|
13
12
|
def initialize(options)
|
14
|
-
self.items = []
|
15
13
|
ATTRIBS.each do |k|
|
16
14
|
value = options[k] || options[k.to_s]
|
17
15
|
send("#{k}=", value)
|
18
16
|
end
|
19
|
-
|
20
|
-
acc << if item.is_a?(Bibcollection) || item.is_a?(Bibdata)
|
21
|
-
item
|
22
|
-
else new_bib_item_class(item)
|
23
|
-
end
|
24
|
-
end
|
17
|
+
reduce_items
|
25
18
|
end
|
26
|
-
# rubocop:enable Metrics/MethodLength
|
27
19
|
|
28
20
|
# arbitrary number, must sort after all bib items
|
29
21
|
def doc_number
|
30
22
|
9999999
|
31
23
|
end
|
32
24
|
|
25
|
+
# Add a dcoument to the collection
|
26
|
+
# @param item [RelatonBib::BibliographicItem]
|
27
|
+
def <<(item)
|
28
|
+
items << new_bib_item_class(item)
|
29
|
+
end
|
30
|
+
|
33
31
|
# rubocop:disable Metrics/MethodLength
|
34
32
|
|
35
33
|
# @param source [Nokogiri::XML::Element]
|
36
34
|
def self.from_xml(source)
|
37
35
|
title = find_text("./relaton-collection/title", source)
|
38
36
|
author = find_text(
|
39
|
-
"./relaton-collection/contributor[role/@type='author']/organization/
|
40
|
-
source
|
37
|
+
"./relaton-collection/contributor[role/@type='author']/organization/"\
|
38
|
+
"name", source
|
41
39
|
)
|
42
40
|
|
43
41
|
items = find_xpath("./relaton-collection/relation", source)&.map do |item|
|
@@ -48,29 +46,8 @@ module Relaton
|
|
48
46
|
|
49
47
|
new(title: title, author: author, items: items)
|
50
48
|
end
|
51
|
-
# rubocop:enable Metrics/MethodLength
|
52
|
-
|
53
|
-
def new_bib_item_class(options)
|
54
|
-
if options.is_a?(Hash) && options["items"]
|
55
|
-
::Relaton::Bibcollection.new(options)
|
56
|
-
else
|
57
|
-
::Relaton::Bibdata.new(options)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def items_flattened
|
62
|
-
items.sort_by! &:docnumber
|
63
|
-
|
64
|
-
items.reduce([]) do |acc,item|
|
65
|
-
acc << if item.is_a? ::Relaton::Bibcollection
|
66
|
-
item.items_flattened
|
67
|
-
else
|
68
|
-
item
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
49
|
|
73
|
-
# rubocop:disable Metrics/AbcSize
|
50
|
+
# rubocop:disable Metrics/AbcSize
|
74
51
|
|
75
52
|
# @param opts [Hash]
|
76
53
|
# @return [String] XML
|
@@ -98,7 +75,37 @@ module Relaton
|
|
98
75
|
end
|
99
76
|
ret += "</relaton-collection>\n"
|
100
77
|
end
|
101
|
-
# rubocop:enable Metrics/AbcSize
|
78
|
+
# rubocop:enable Metrics/AbcSize
|
79
|
+
|
80
|
+
# @param item [Hash, RelatonBib::BibliographicItem, Relatin::Bibdata,
|
81
|
+
# Relaton::Bibcollection]
|
82
|
+
# @return [Relaton::Bibdata, Relaton::Bibcollection]
|
83
|
+
def new_bib_item_class(item)
|
84
|
+
if item.is_a?(Hash)
|
85
|
+
if item["items"]
|
86
|
+
::Relaton::Bibcollection.new(item)
|
87
|
+
else
|
88
|
+
bibitem = ::Relaton::Cli::YAMLConvertor.convert_single_file item
|
89
|
+
::Relaton::Bibdata.new bibitem
|
90
|
+
end
|
91
|
+
elsif item.is_a?(Relaton::Bibdata) || item.is_a?(Relaton::Bibcollection)
|
92
|
+
item
|
93
|
+
else ::Relaton::Bibdata.new(item)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# rubocop:enable Metrics/MethodLength
|
97
|
+
|
98
|
+
def items_flattened
|
99
|
+
items.sort_by! &:doc_number
|
100
|
+
|
101
|
+
items.reduce([]) do |acc, item|
|
102
|
+
acc << if item.is_a? ::Relaton::Bibcollection
|
103
|
+
item.items_flattened
|
104
|
+
else
|
105
|
+
item
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
102
109
|
|
103
110
|
def to_yaml
|
104
111
|
to_h.to_yaml
|
@@ -116,5 +123,16 @@ module Relaton
|
|
116
123
|
|
117
124
|
{ "root" => a }
|
118
125
|
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def reduce_items
|
130
|
+
self.items = (items || []).reduce([]) do |acc, item|
|
131
|
+
acc << if item.is_a?(Bibcollection) || item.is_a?(Bibdata)
|
132
|
+
item
|
133
|
+
else new_bib_item_class(item)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
119
137
|
end
|
120
138
|
end
|
data/lib/relaton/bibdata.rb
CHANGED
@@ -4,8 +4,10 @@ module Relaton
|
|
4
4
|
class Bibdata
|
5
5
|
URL_TYPES = %i[uri xml pdf doc html rxl txt].freeze
|
6
6
|
|
7
|
+
# @return [RelatonBib::BibliographicItem]
|
7
8
|
attr_reader :bibitem
|
8
9
|
|
10
|
+
# @param bibitem [RelatonBib::BibliographicItem]
|
9
11
|
def initialize(bibitem)
|
10
12
|
@bibitem = bibitem
|
11
13
|
end
|
data/lib/relaton/cli.rb
CHANGED
@@ -16,40 +16,58 @@ module Relaton
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
class << self
|
20
|
+
def start(arguments)
|
21
|
+
Relaton::Cli::Command.start(arguments)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
# Relaton
|
25
|
+
#
|
26
|
+
# Based on current setup, we need to initiate a Db instance to
|
27
|
+
# register all of it's supported processor backends. To make it
|
28
|
+
# easier we have added it as a class method so we can use this
|
29
|
+
# whenever necessary.
|
30
|
+
#
|
31
|
+
def relaton
|
32
|
+
RelatonDb.instance.db
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
proc.
|
39
|
-
|
40
|
-
|
35
|
+
# @param content [Nokogiri::XML::Document]
|
36
|
+
# @return [RelatonBib::BibliographicItem,
|
37
|
+
# RelatonIsoBib::IsoBibliongraphicItem]
|
38
|
+
def parse_xml(doc)
|
39
|
+
if (proc = Cli.processor(doc))
|
40
|
+
proc.from_xml(doc.to_s)
|
41
|
+
else
|
42
|
+
RelatonBib::XMLParser.from_xml(doc.to_s)
|
43
|
+
end
|
41
44
|
end
|
42
|
-
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
# @param doc [Nokogiri::XML::Element]
|
47
|
+
# @return [RelatonIso::Processor, RelatonIec::Processor,
|
48
|
+
# RelatonNist::Processor, RelatonIetf::Processot,
|
49
|
+
# RelatonItu::Processor, RelatonGb::Processor,
|
50
|
+
# RelatonOgc::Processor, RelatonCalconnect::Processor]
|
51
|
+
def processor(doc)
|
52
|
+
docid = doc.at "docidentifier"
|
53
|
+
proc = get_proc docid
|
50
54
|
return proc if proc
|
55
|
+
|
56
|
+
Relaton::Registry.instance.by_type(docid&.text&.match(/^\w+/)&.to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# @param doc [Nokogiri::XML::Element]
|
62
|
+
# @return [RelatonIso::Processor, RelatonIec::Processor,
|
63
|
+
# RelatonNist::Processor, RelatonIetf::Processot,
|
64
|
+
# RelatonItu::Processor, RelatonGb::Processor,
|
65
|
+
# RelatonOgc::Processor, RelatonCalconnect::Processor]
|
66
|
+
def get_proc(docid)
|
67
|
+
return unless docid && docid[:type]
|
68
|
+
|
69
|
+
Relaton::Registry.instance.by_type(docid[:type])
|
51
70
|
end
|
52
|
-
Relaton::Registry.instance.by_type(docid&.text&.match(/^\w+/)&.to_s)
|
53
71
|
end
|
54
72
|
end
|
55
73
|
end
|
data/lib/relaton/cli/command.rb
CHANGED
@@ -1,93 +1,128 @@
|
|
1
1
|
require "relaton/cli/relaton_file"
|
2
2
|
require "relaton/cli/xml_convertor"
|
3
3
|
require "relaton/cli/yaml_convertor"
|
4
|
+
require "relaton/cli/subcommand_collection"
|
4
5
|
require "fcntl"
|
5
6
|
|
6
7
|
module Relaton
|
7
8
|
module Cli
|
8
9
|
class Command < Thor
|
9
10
|
desc "fetch CODE", "Fetch Relaton XML for Standard identifier CODE"
|
10
|
-
option :type, aliases: :t, required: true, desc: "Type of standard to
|
11
|
-
|
12
|
-
option :
|
11
|
+
option :type, aliases: :t, required: true, desc: "Type of standard to "\
|
12
|
+
"get bibliographic entry for"
|
13
|
+
option :format, aliases: :f, desc: "Output format (xml, bibtex). "\
|
14
|
+
"Default xml."
|
15
|
+
option :year, aliases: :y, type: :numeric, desc: "Year the standard was "\
|
16
|
+
"published"
|
13
17
|
|
14
18
|
def fetch(code)
|
15
19
|
Relaton.db
|
16
|
-
io = IO.new(STDOUT.fcntl(::Fcntl::F_DUPFD), mode:
|
20
|
+
io = IO.new(STDOUT.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
|
17
21
|
io.puts(fetch_document(code, options) || supported_type_message)
|
18
22
|
end
|
19
23
|
|
20
|
-
desc "extract Metanorma-XML-File / Directory Relaton-XML-Directory",
|
21
|
-
|
24
|
+
desc "extract Metanorma-XML-File / Directory Relaton-XML-Directory",
|
25
|
+
"Extract Relaton XML from Metanorma XML file / directory"
|
26
|
+
option :extension, aliases: :x, default: "rxl", desc: "File extension "\
|
27
|
+
"of Relaton XML files, defaults to 'rxl'"
|
22
28
|
|
23
29
|
def extract(source_dir, outdir)
|
24
30
|
Relaton::Cli::RelatonFile.extract(source_dir, outdir, options)
|
25
31
|
end
|
26
32
|
|
27
|
-
desc "concatenate SOURCE-DIR COLLECTION-FILE", "Concatenate entries in
|
33
|
+
desc "concatenate SOURCE-DIR COLLECTION-FILE", "Concatenate entries in "\
|
34
|
+
"DIRECTORY (containing Relaton-XML or YAML) into a Relaton Collection"
|
28
35
|
option :title, aliases: :t, desc: "Title of resulting Relaton collection"
|
29
|
-
option :organization, aliases: :g, desc: "Organization owner of Relaton
|
30
|
-
|
31
|
-
option :
|
36
|
+
option :organization, aliases: :g, desc: "Organization owner of Relaton "\
|
37
|
+
"collection"
|
38
|
+
option :new, aliases: :n, type: :boolean, desc: "Use the new Relaton "\
|
39
|
+
"YAML format"
|
40
|
+
option :extension, aliases: :x, desc: "File extension of destination "\
|
41
|
+
"Relaton file, defaults to 'rxl'"
|
32
42
|
|
33
43
|
def concatenate(source_dir, outfile)
|
34
44
|
Relaton::Cli::RelatonFile.concatenate(source_dir, outfile, options)
|
35
45
|
end
|
36
46
|
|
37
|
-
desc "split Relaton-Collection-File Relaton-XML-Directory", "Split a
|
38
|
-
|
39
|
-
option :
|
47
|
+
desc "split Relaton-Collection-File Relaton-XML-Directory", "Split a "\
|
48
|
+
"Relaton Collection into multiple files"
|
49
|
+
option :extension, aliases: :x, default: "rxl", desc: "File extension "\
|
50
|
+
"of Relaton XML files, defaults to 'rxl'"
|
51
|
+
option :new, aliases: :n, type: :boolean, desc: "Use the new Relaton "\
|
52
|
+
"YAML format"
|
40
53
|
|
41
54
|
def split(source, outdir)
|
42
55
|
Relaton::Cli::RelatonFile.split(source, outdir, options)
|
43
56
|
end
|
44
57
|
|
45
|
-
desc "yaml2xml YAML", "Convert Relaton YAML into Relaton Collection XML
|
46
|
-
|
47
|
-
option :
|
48
|
-
|
49
|
-
option :
|
50
|
-
|
58
|
+
desc "yaml2xml YAML", "Convert Relaton YAML into Relaton Collection XML "\
|
59
|
+
"or separate files"
|
60
|
+
option :extension, aliases: :x, default: "rxl", desc: "File extension "\
|
61
|
+
"of Relaton XML files, defaults to 'rxl'"
|
62
|
+
option :prefix, aliases: :p, desc: "Filename prefix of individual "\
|
63
|
+
"Relaton XML files, defaults to empty"
|
64
|
+
option :outdir, aliases: :o, desc: "Output to the specified directory "\
|
65
|
+
"with individual Relaton Bibdata XML files"
|
66
|
+
option :require, aliases: :r, type: :array, desc: "Require LIBRARY "\
|
67
|
+
"prior to execution"
|
68
|
+
option :overwrite, aliases: :f, type: :boolean, default: false,
|
69
|
+
desc: "Overwrite the existing file"
|
51
70
|
|
52
71
|
def yaml2xml(filename)
|
53
72
|
Relaton::Cli::YAMLConvertor.to_xml(filename, options)
|
54
73
|
end
|
55
74
|
|
56
|
-
desc "xml2yaml XML", "Convert Relaton XML into Relaton Bibdata /
|
57
|
-
|
58
|
-
option :
|
59
|
-
|
60
|
-
option :
|
61
|
-
|
75
|
+
desc "xml2yaml XML", "Convert Relaton XML into Relaton Bibdata / "\
|
76
|
+
"Bibcollection YAML (and separate files)"
|
77
|
+
option :extension, aliases: :x, default: "yaml", desc: "File extension "\
|
78
|
+
"of Relaton YAML files, defaults to 'yaml'"
|
79
|
+
option :prefix, aliases: :p, desc: "Filename prefix of Relaton XML "\
|
80
|
+
"files, defaults to empty"
|
81
|
+
option :outdir, aliases: :o, desc: "Output to the specified directory "\
|
82
|
+
"with individual Relaton Bibdata YAML files"
|
83
|
+
option :require, aliases: :r, type: :array, desc: "Require LIBRARY "\
|
84
|
+
"prior to execution"
|
85
|
+
option :overwrite, aliases: :f, type: :boolean, default: false,
|
86
|
+
desc: "Overwrite the existing file"
|
62
87
|
|
63
88
|
def xml2yaml(filename)
|
64
89
|
Relaton::Cli::XMLConvertor.to_yaml(filename, options)
|
65
90
|
end
|
66
91
|
|
67
|
-
desc "xml2html RELATON-INDEX-XML", "Convert Relaton Collection XML into
|
68
|
-
|
69
|
-
option :
|
70
|
-
|
92
|
+
desc "xml2html RELATON-INDEX-XML", "Convert Relaton Collection XML into "\
|
93
|
+
"HTML"
|
94
|
+
option :stylesheet, aliases: :s, desc: "Stylesheet file path for "\
|
95
|
+
"rendering HTML index"
|
96
|
+
option :templatedir, aliases: :t, desc: "Liquid template directory for "\
|
97
|
+
"rendering Relaton items and collection"
|
98
|
+
option :overwrite, aliases: :f, type: :boolean, default: false,
|
99
|
+
desc: "Overwrite the existing file"
|
71
100
|
|
72
101
|
def xml2html(file, style = nil, template = nil)
|
73
102
|
Relaton::Cli::XMLConvertor.to_html(file, style, template)
|
74
103
|
end
|
75
104
|
|
76
|
-
desc "yaml2html RELATON-INDEX-YAML", "Concatenate Relaton Collection
|
77
|
-
|
78
|
-
option :
|
79
|
-
|
105
|
+
desc "yaml2html RELATON-INDEX-YAML", "Concatenate Relaton Collection "\
|
106
|
+
"YAML into HTML"
|
107
|
+
option :stylesheet, aliases: :s, desc: "Stylesheet file path for "\
|
108
|
+
"rendering HTML index"
|
109
|
+
option :templatedir, aliases: :t, desc: "Liquid template directory for "\
|
110
|
+
"rendering Relaton items and collection"
|
111
|
+
option :overwrite, aliases: :f, type: :boolean, default: false,
|
112
|
+
desc: "Overwrite the existing file"
|
80
113
|
|
81
114
|
def yaml2html(file, style = nil, template = nil)
|
82
115
|
Relaton::Cli::YAMLConvertor.to_html(file, style, template)
|
83
116
|
end
|
84
117
|
|
85
118
|
desc "convert XML", "Convert Relaton XML document"
|
86
|
-
option :format, aliases: :f, required: true, desc: "Output format
|
119
|
+
option :format, aliases: :f, required: true, desc: "Output format "\
|
120
|
+
"(yaml, bibtex, asciibib)"
|
87
121
|
option :output, aliases: :o, desc: "Output to the specified file"
|
88
122
|
|
89
|
-
def convert(file)
|
90
|
-
|
123
|
+
def convert(file) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
124
|
+
xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"))
|
125
|
+
item = Relaton::Cli.parse_xml xml
|
91
126
|
result = if /yaml|yml/.match?(options[:format])
|
92
127
|
item.to_hash.to_yaml
|
93
128
|
else item.send "to_#{options[:format]}"
|
@@ -101,6 +136,9 @@ module Relaton
|
|
101
136
|
File.write output, result, encoding: "UTF-8"
|
102
137
|
end
|
103
138
|
|
139
|
+
desc "collection SUBCOMMAND", "Collection manipulations"
|
140
|
+
subcommand "collection", SubcommandCollection
|
141
|
+
|
104
142
|
private
|
105
143
|
|
106
144
|
# @param code [String]
|