relaton-cli 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +13 -0
- data/.hound.yml +3 -0
- data/.rubocop.yml +2 -7
- data/.travis.yml +5 -0
- data/Gemfile.lock +31 -24
- data/README.adoc +77 -36
- data/bin/rspec +29 -0
- data/exe/relaton +21 -0
- data/lib/relaton/bibcollection.rb +27 -38
- data/lib/relaton/bibdata.rb +81 -18
- data/lib/relaton/cli/_document.liquid +2 -2
- data/lib/relaton/cli/base_convertor.rb +94 -0
- data/lib/relaton/cli/command.rb +83 -0
- data/lib/relaton/cli/relaton_file.rb +153 -0
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_convertor.rb +41 -0
- data/lib/relaton/cli/xml_to_html_renderer.rb +4 -14
- data/lib/relaton/cli/yaml_convertor.rb +59 -0
- data/lib/relaton/cli.rb +21 -3
- data/relaton-cli.gemspec +9 -7
- data/templates/_document.liquid +7 -2
- data/templates/_index.liquid +53 -0
- metadata +31 -18
- data/.rubocop.ribose.yml +0 -66
- data/.rubocop.tb.yml +0 -650
- data/exe/relaton-concatenate +0 -24
- data/exe/relaton-fetch +0 -41
- data/exe/relaton-metanorma-extract +0 -20
- data/exe/relaton-xml-html +0 -28
- data/exe/relaton-yaml-xml +0 -68
data/lib/relaton/cli/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "relaton/cli/base_convertor"
|
3
|
+
|
4
|
+
module Relaton
|
5
|
+
module Cli
|
6
|
+
class XMLConvertor < Relaton::Cli::BaseConvertor
|
7
|
+
def to_yaml
|
8
|
+
convert_and_write(file_content, :to_yaml)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Convert to YAML
|
12
|
+
#
|
13
|
+
# This interface allow us to convert any XML file to YAML.
|
14
|
+
# It only require us to provide a valid XML file and it can
|
15
|
+
# do converstion using default attributes, but it also allow
|
16
|
+
# us to provide custom options to customize this converstion
|
17
|
+
# process.
|
18
|
+
#
|
19
|
+
# @param file [File] The complete path to a XML file
|
20
|
+
# @param options [Hash] Options as hash key, value pairs.
|
21
|
+
#
|
22
|
+
def self.to_yaml(file, options = {})
|
23
|
+
new(file, options).to_yaml
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def default_ext
|
29
|
+
"yaml"
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert_content(content)
|
33
|
+
Relaton::Bibcollection.from_xml(content)
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_content
|
37
|
+
Nokogiri::XML(File.read(file, encoding: "utf-8"))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -35,26 +35,13 @@ module Relaton::Cli
|
|
35
35
|
def render(index_xml)
|
36
36
|
source = Nokogiri::XML(index_xml)
|
37
37
|
bibcollection = ::Relaton::Bibcollection.from_xml(source)
|
38
|
-
|
39
|
-
# puts "@"*38
|
40
|
-
# puts bibcollection.inspect
|
41
|
-
# puts "@"*38
|
42
|
-
|
43
38
|
locals = {
|
44
39
|
css: @stylesheet,
|
45
40
|
title: bibcollection.title,
|
46
41
|
author: bibcollection.author,
|
47
|
-
documents: bibcollection.to_h[
|
42
|
+
documents: bibcollection.to_h["root"]["items"].map { |i| hash_to_liquid(i) },
|
48
43
|
depth: 2
|
49
44
|
}
|
50
|
-
|
51
|
-
# puts "template: #{template}"
|
52
|
-
# puts "B"*30
|
53
|
-
# puts "#{bibcollection.inspect}"
|
54
|
-
# puts "B"*30
|
55
|
-
# puts "#{bibcollection.items.size}"
|
56
|
-
# pp bibcollection.to_h[:items]
|
57
|
-
|
58
45
|
Liquid::Template.parse(@template).render(hash_to_liquid(locals))
|
59
46
|
end
|
60
47
|
|
@@ -63,5 +50,8 @@ module Relaton::Cli
|
|
63
50
|
uri.sub(/\.[^.]+$/, ".#{extension.to_s}")
|
64
51
|
end
|
65
52
|
|
53
|
+
def self.render(file, options)
|
54
|
+
new(options).render(file)
|
55
|
+
end
|
66
56
|
end
|
67
57
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "relaton/cli/base_convertor"
|
3
|
+
|
4
|
+
module Relaton
|
5
|
+
module Cli
|
6
|
+
class YAMLConvertor < Relaton::Cli::BaseConvertor
|
7
|
+
def to_xml
|
8
|
+
if writable
|
9
|
+
convert_and_write(file_content, :to_xml)
|
10
|
+
else
|
11
|
+
convert_content(file_content).to_xml
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Convert to XML
|
16
|
+
#
|
17
|
+
# This interface allow us to convert any YAML file to XML.
|
18
|
+
# It only require us to provide a valid YAML file and it can
|
19
|
+
# do converstion using default attributes, but it also allow
|
20
|
+
# us to provide custom options to customize this converstion
|
21
|
+
# process.
|
22
|
+
#
|
23
|
+
# @param file [File] The complete path to a YAML file
|
24
|
+
# @param options [Hash] Options as hash key, value pairs.
|
25
|
+
#
|
26
|
+
def self.to_xml(file, options = {})
|
27
|
+
new(file, options).to_xml
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def default_ext
|
33
|
+
"rxl"
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_content
|
37
|
+
YAML.load_file(file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert_single_file(content)
|
41
|
+
Relaton::Bibdata.new(content)
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert_collection(content)
|
45
|
+
if content.has_key?("root")
|
46
|
+
Relaton::Bibcollection.new(content["root"])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def xml_content(_raw_file)
|
51
|
+
convert_content(file_content).to_xml
|
52
|
+
end
|
53
|
+
|
54
|
+
def convert_content(content)
|
55
|
+
convert_collection(content) || convert_single_file(content)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/relaton/cli.rb
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
+
require "thor"
|
1
2
|
require "relaton"
|
2
|
-
require_relative "
|
3
|
-
|
4
|
-
|
3
|
+
require_relative "cli/command"
|
4
|
+
|
5
|
+
module Relaton
|
6
|
+
module Cli
|
7
|
+
def self.start(arguments)
|
8
|
+
Relaton::Cli::Command.start(arguments)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Relaton
|
12
|
+
#
|
13
|
+
# Based on current setup, we need to initiate a Db instance to
|
14
|
+
# register all of it's supported processor backends. To make it
|
15
|
+
# easier we have added it as a class method so we can use this
|
16
|
+
# whenever necessary.
|
17
|
+
#
|
18
|
+
def self.relaton
|
19
|
+
@relaton ||= Relaton::Db.new("#{Dir.home}/.relaton/cache", nil)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/relaton-cli.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "relaton/cli/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "relaton-cli"
|
8
8
|
spec.version = Relaton::Cli::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ["Ribose Inc."]
|
10
|
+
spec.email = ["open.source@ribose.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Relaton Command-line Interface}
|
13
13
|
spec.description = %q{Relaton Command-line Interface}
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.required_ruby_version =
|
25
|
+
spec.required_ruby_version = ">= 2.3.0"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.16"
|
28
28
|
spec.add_development_dependency "rake", "~> 12.0"
|
@@ -30,9 +30,11 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "byebug", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec-command", "~> 1.0.3"
|
32
32
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
33
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency "rspec-core", "~> 3.4"
|
34
|
+
spec.add_development_dependency "pry"
|
34
35
|
|
35
|
-
spec.add_runtime_dependency
|
36
|
-
spec.add_runtime_dependency
|
37
|
-
spec.add_runtime_dependency
|
36
|
+
spec.add_runtime_dependency "relaton", "~> 0.3"
|
37
|
+
spec.add_runtime_dependency "thor"
|
38
|
+
spec.add_runtime_dependency "liquid"
|
39
|
+
# spec.add_runtime_dependency 'byebug'
|
38
40
|
end
|
data/templates/_document.liquid
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
<div class="doc-identifier">
|
9
9
|
<h{{ depth }}>
|
10
10
|
{% if document.html == "" %}
|
11
|
-
{{ document.
|
11
|
+
{{ document.docidentifier }}
|
12
12
|
{% else %}
|
13
|
-
<a href="{{ document.html }}">{{ document.
|
13
|
+
<a href="{{ document.html }}">{{ document.docidentifier }}</a>
|
14
14
|
{% endif %}
|
15
15
|
</h{{ depth }}>
|
16
16
|
</div>
|
@@ -54,6 +54,11 @@
|
|
54
54
|
</div>
|
55
55
|
|
56
56
|
<div class="doc-access">
|
57
|
+
{% unless document.uri == blank or document.uri == nil %}
|
58
|
+
<div class="doc-access-button-uri">
|
59
|
+
<a href="{{ document.uri }}">URI</a>
|
60
|
+
</div>
|
61
|
+
{% endunless %}
|
57
62
|
{% unless document.html == blank or document.html == nil %}
|
58
63
|
<div class="doc-access-button-html">
|
59
64
|
<a href="{{ document.html }}">HTML</a>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<!DOCTYPE HTML>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>{{ title }}</title>
|
5
|
+
<style>
|
6
|
+
<!--
|
7
|
+
{{ css }}
|
8
|
+
-->
|
9
|
+
</style>
|
10
|
+
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
|
11
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
|
12
|
+
<script src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js" type="text/javascript"></script>
|
13
|
+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700|Overpass:300,300i,600,900|Ek+Mukta:200" rel="stylesheet" type="text/css"/>
|
14
|
+
<link href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous"/>
|
15
|
+
<link href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous"/>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<header>
|
19
|
+
<div id="topbar-inner">
|
20
|
+
<div id="title-bar"><span>{{ author }}</span></div>
|
21
|
+
</div>
|
22
|
+
<div class="title-section">
|
23
|
+
<div class="coverpage">
|
24
|
+
<div class="wrapper-top">
|
25
|
+
<div class="coverpage-doc-identity">
|
26
|
+
<div class="coverpage-title"><span class="title-first">{{ title }}</span></div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
</header>
|
32
|
+
<main class="main-section">
|
33
|
+
{% include 'document' for documents %}
|
34
|
+
</main>
|
35
|
+
<footer>
|
36
|
+
<div class="copyright">
|
37
|
+
<p class="year">© {{ author }}</p>
|
38
|
+
<p class="message">All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying, or posting on the internet or an intranet, without prior written permission.</p>
|
39
|
+
</div>
|
40
|
+
</footer>
|
41
|
+
<script>
|
42
|
+
$(document).ready(function() {
|
43
|
+
$('[id^=toc]').each(function () {
|
44
|
+
var currentToc = $(this);
|
45
|
+
var url = window.location.href;
|
46
|
+
currentToc.wrap("<a href='" + url + "#" + currentToc.attr("id") + "' <\/a>");
|
47
|
+
});
|
48
|
+
});
|
49
|
+
anchors.options = { placement: 'left' };
|
50
|
+
anchors.add('h1, h2, h3, h4');
|
51
|
+
</script>
|
52
|
+
</body>
|
53
|
+
</html>
|
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: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,22 +108,36 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
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'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: relaton
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
131
|
+
version: '0.3'
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
138
|
+
version: '0.3'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
140
|
+
name: thor
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
@@ -154,18 +168,14 @@ description: Relaton Command-line Interface
|
|
154
168
|
email:
|
155
169
|
- open.source@ribose.com
|
156
170
|
executables:
|
157
|
-
- relaton
|
158
|
-
- relaton-fetch
|
159
|
-
- relaton-metanorma-extract
|
160
|
-
- relaton-xml-html
|
161
|
-
- relaton-yaml-xml
|
171
|
+
- relaton
|
162
172
|
extensions: []
|
163
173
|
extra_rdoc_files:
|
164
174
|
- README.adoc
|
165
175
|
- LICENSE
|
166
176
|
files:
|
167
|
-
- ".
|
168
|
-
- ".
|
177
|
+
- ".gitignore"
|
178
|
+
- ".hound.yml"
|
169
179
|
- ".rubocop.yml"
|
170
180
|
- ".travis.yml"
|
171
181
|
- Gemfile
|
@@ -173,21 +183,24 @@ files:
|
|
173
183
|
- LICENSE
|
174
184
|
- README.adoc
|
175
185
|
- Rakefile
|
176
|
-
-
|
177
|
-
- exe/relaton
|
178
|
-
- exe/relaton-metanorma-extract
|
179
|
-
- exe/relaton-xml-html
|
180
|
-
- exe/relaton-yaml-xml
|
186
|
+
- bin/rspec
|
187
|
+
- exe/relaton
|
181
188
|
- i18n.yaml
|
182
189
|
- lib/relaton/bibcollection.rb
|
183
190
|
- lib/relaton/bibdata.rb
|
184
191
|
- lib/relaton/cli.rb
|
185
192
|
- lib/relaton/cli/_document.liquid
|
186
193
|
- lib/relaton/cli/_index.liquid
|
194
|
+
- lib/relaton/cli/base_convertor.rb
|
195
|
+
- lib/relaton/cli/command.rb
|
196
|
+
- lib/relaton/cli/relaton_file.rb
|
187
197
|
- lib/relaton/cli/version.rb
|
198
|
+
- lib/relaton/cli/xml_convertor.rb
|
188
199
|
- lib/relaton/cli/xml_to_html_renderer.rb
|
200
|
+
- lib/relaton/cli/yaml_convertor.rb
|
189
201
|
- relaton-cli.gemspec
|
190
202
|
- templates/_document.liquid
|
203
|
+
- templates/_index.liquid
|
191
204
|
homepage: https://github.com/riboseinc/relaton-cli
|
192
205
|
licenses:
|
193
206
|
- BSD-2-Clause
|
@@ -208,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
221
|
version: '0'
|
209
222
|
requirements: []
|
210
223
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.7.
|
224
|
+
rubygems_version: 2.7.6
|
212
225
|
signing_key:
|
213
226
|
specification_version: 4
|
214
227
|
summary: Relaton Command-line Interface
|
data/.rubocop.ribose.yml
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Include:
|
3
|
-
- "**/*.rake"
|
4
|
-
- "**/Gemfile"
|
5
|
-
- "**/*.gemfile"
|
6
|
-
- "**/Rakefile"
|
7
|
-
- "**/*.rb"
|
8
|
-
Exclude:
|
9
|
-
- "vendor/**/*"
|
10
|
-
- "db/**/*"
|
11
|
-
- "tmp/**/*"
|
12
|
-
DisplayCopNames: false
|
13
|
-
StyleGuideCopsOnly: false
|
14
|
-
Rails:
|
15
|
-
Enabled: true
|
16
|
-
Metrics/AbcSize:
|
17
|
-
Description: A calculated magnitude based on number of assignments, branches, and
|
18
|
-
conditions.
|
19
|
-
Enabled: true
|
20
|
-
Max: 15
|
21
|
-
Metrics/BlockLength:
|
22
|
-
Exclude:
|
23
|
-
- "spec/**/*"
|
24
|
-
Metrics/BlockNesting:
|
25
|
-
Description: Avoid excessive block nesting
|
26
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count
|
27
|
-
Enabled: true
|
28
|
-
Max: 3
|
29
|
-
Metrics/ClassLength:
|
30
|
-
Description: Avoid classes longer than 100 lines of code.
|
31
|
-
Enabled: false
|
32
|
-
CountComments: false
|
33
|
-
Max: 100
|
34
|
-
Metrics/CyclomaticComplexity:
|
35
|
-
Description: A complexity metric that is strongly correlated to the number of test
|
36
|
-
cases needed to validate a method.
|
37
|
-
Enabled: true
|
38
|
-
Max: 6
|
39
|
-
Metrics/LineLength:
|
40
|
-
Description: Limit lines to 80 characters.
|
41
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
|
42
|
-
Enabled: true
|
43
|
-
Max: 80
|
44
|
-
AllowURI: true
|
45
|
-
URISchemes:
|
46
|
-
- http
|
47
|
-
- https
|
48
|
-
Metrics/MethodLength:
|
49
|
-
Description: Avoid methods longer than 10 lines of code.
|
50
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
51
|
-
Enabled: true
|
52
|
-
CountComments: true
|
53
|
-
Max: 10
|
54
|
-
Exclude:
|
55
|
-
- "spec/**/*"
|
56
|
-
Metrics/ParameterLists:
|
57
|
-
Description: Avoid long parameter lists.
|
58
|
-
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
59
|
-
Enabled: true
|
60
|
-
Max: 5
|
61
|
-
CountKeywordArgs: true
|
62
|
-
Metrics/PerceivedComplexity:
|
63
|
-
Description: A complexity metric geared towards measuring complexity for a human
|
64
|
-
reader.
|
65
|
-
Enabled: true
|
66
|
-
Max: 7
|