relaton-cli 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +93 -0
- data/README.adoc +139 -0
- data/exe/relaton-concatenate +24 -0
- data/exe/relaton-fetch +41 -0
- data/exe/relaton-metanorma-extract +20 -0
- data/exe/relaton-xml-html +13 -8
- data/exe/relaton-yaml-xml +10 -26
- data/lib/relaton/bibcollection.rb +59 -7
- data/lib/relaton/bibdata.rb +56 -1
- data/lib/relaton/cli/_document.liquid +82 -0
- data/lib/relaton/cli/_index.liquid +53 -0
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_to_html_renderer.rb +41 -253
- data/relaton-cli.gemspec +1 -0
- data/templates/_document.liquid +82 -0
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b19614f9f5484181337571cbc881a8f45d7131bbb8c1fea9ca77f8573935d8f3
|
4
|
+
data.tar.gz: 45429bb98e29ebfd54a2b1525a793b34f93a453f143ed1b9a9b2e0529eea6d9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2af0e98a901968e3751a1c209dc98b326098aae82b0ba0eb6d4562f9826da83e380ff05a3e8ff9884d4bb32a12e4ca43de933bd77754d31377e29052287364ee
|
7
|
+
data.tar.gz: 268053ca0bd8992ad7125829b3718e896b3bcbec6ca6220ccf3df98ebfce7d8680d062a89ffa3971b74474f2bdfa8ee57740d282fcdd67b869972b605cba202d
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
relaton-cli (0.1.1)
|
5
|
+
liquid
|
6
|
+
relaton (~> 0.2.4)
|
7
|
+
uuidtools
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.2)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
algoliasearch (1.23.2)
|
15
|
+
httpclient (~> 2.8, >= 2.8.3)
|
16
|
+
json (>= 1.5.1)
|
17
|
+
byebug (10.0.2)
|
18
|
+
cnccs (0.1.3)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
equivalent-xml (0.6.0)
|
21
|
+
nokogiri (>= 1.4.3)
|
22
|
+
gb-agencies (0.0.3)
|
23
|
+
gbbib (0.3.1)
|
24
|
+
cnccs (~> 0.1.1)
|
25
|
+
gb-agencies (~> 0.0.1)
|
26
|
+
iso-bib-item (~> 0.3.0)
|
27
|
+
httpclient (2.8.3)
|
28
|
+
iecbib (0.1.2)
|
29
|
+
addressable
|
30
|
+
iso-bib-item (~> 0.3.0)
|
31
|
+
ietfbib (0.4.1)
|
32
|
+
iso-bib-item (~> 0.3.0)
|
33
|
+
iso-bib-item (0.3.1)
|
34
|
+
isoics (~> 0.1.6)
|
35
|
+
nokogiri (~> 1.8.4)
|
36
|
+
ruby_deep_clone (~> 0.8.0)
|
37
|
+
isobib (0.3.1)
|
38
|
+
algoliasearch
|
39
|
+
iso-bib-item (~> 0.3.0)
|
40
|
+
isoics (0.1.7)
|
41
|
+
json (2.1.0)
|
42
|
+
liquid (4.0.0)
|
43
|
+
mini_portile2 (2.3.0)
|
44
|
+
mixlib-shellout (2.4.0)
|
45
|
+
nokogiri (1.8.4)
|
46
|
+
mini_portile2 (~> 2.3.0)
|
47
|
+
public_suffix (3.0.3)
|
48
|
+
rake (12.3.1)
|
49
|
+
relaton (0.2.4)
|
50
|
+
algoliasearch
|
51
|
+
gbbib (~> 0.3.1)
|
52
|
+
iecbib (~> 0.1.1)
|
53
|
+
ietfbib (~> 0.4.1)
|
54
|
+
iso-bib-item (~> 0.3.0)
|
55
|
+
isobib (~> 0.3.1)
|
56
|
+
rspec (3.8.0)
|
57
|
+
rspec-core (~> 3.8.0)
|
58
|
+
rspec-expectations (~> 3.8.0)
|
59
|
+
rspec-mocks (~> 3.8.0)
|
60
|
+
rspec-command (1.0.3)
|
61
|
+
mixlib-shellout (~> 2.0)
|
62
|
+
rspec (~> 3.2)
|
63
|
+
rspec-its (~> 1.2)
|
64
|
+
rspec-core (3.8.0)
|
65
|
+
rspec-support (~> 3.8.0)
|
66
|
+
rspec-expectations (3.8.1)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.8.0)
|
69
|
+
rspec-its (1.2.0)
|
70
|
+
rspec-core (>= 3.0.0)
|
71
|
+
rspec-expectations (>= 3.0.0)
|
72
|
+
rspec-mocks (3.8.0)
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
+
rspec-support (~> 3.8.0)
|
75
|
+
rspec-support (3.8.0)
|
76
|
+
ruby_deep_clone (0.8.0)
|
77
|
+
uuidtools (2.1.5)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
bundler (~> 1.16)
|
84
|
+
byebug (~> 10.0)
|
85
|
+
equivalent-xml (~> 0.6)
|
86
|
+
rake (~> 12.0)
|
87
|
+
relaton-cli!
|
88
|
+
rspec (~> 3.0)
|
89
|
+
rspec-command (~> 1.0.3)
|
90
|
+
rspec-core (~> 3.4)
|
91
|
+
|
92
|
+
BUNDLED WITH
|
93
|
+
1.16.2
|
data/README.adoc
CHANGED
@@ -7,3 +7,142 @@ image:https://codeclimate.com/github/riboseinc/relaton-cli/badges/gpa.svg["Code
|
|
7
7
|
Documentation in development.
|
8
8
|
|
9
9
|
Please refer to https://github.com/riboseinc/relaton.
|
10
|
+
|
11
|
+
== Executables
|
12
|
+
|
13
|
+
The following executables are included:
|
14
|
+
|
15
|
+
=== relaton-concatenate
|
16
|
+
|
17
|
+
```
|
18
|
+
relaton-concatenate DIRECTORY
|
19
|
+
```
|
20
|
+
|
21
|
+
Iterates through all the Relaton YAML files in DIRECTORY, and converts them in-place into Relaton XML.
|
22
|
+
|
23
|
+
Iterates through all the Relaton XML files in DIRECTORY (including those just converted from Relaton YAML),
|
24
|
+
and outputs to stdout a `relaton-collection` document containing all the Relaton XML objects read in.
|
25
|
+
|
26
|
+
=== relaton-fetch
|
27
|
+
|
28
|
+
```
|
29
|
+
relaton-fetch -t TYPE -y YEAR code
|
30
|
+
```
|
31
|
+
|
32
|
+
Fetch the Relaton XML entry corresponding to the document identifier `code`.
|
33
|
+
|
34
|
+
* `YEAR` is optional, and specifies the year of publication of the standard.
|
35
|
+
* `TYPE` specifies the standards class library to be used, that the identifier is part of; the recognised
|
36
|
+
values for `TYPE` are `isobib`, `ietfbib`, `iecbib`, `gbbib`.
|
37
|
+
|
38
|
+
=== relaton-metanorma-extract
|
39
|
+
|
40
|
+
```
|
41
|
+
relaton-metanorma-extract Metanorma-XML-Directory Relaton-XML-Directory
|
42
|
+
```
|
43
|
+
|
44
|
+
Iterate through all the Metanorma XML files in `Metanorma-XML-Directory`, and extract the `bibdata`
|
45
|
+
element from each. Save the `bibdata` element for each file to `Relaton-XML-Directory`, as the Relaton XML
|
46
|
+
description for that file. If a document identifier is present in `bibdata`, it is used as the name of the
|
47
|
+
file; otherwise, the original file name is used.
|
48
|
+
|
49
|
+
=== relaton-xml-html
|
50
|
+
|
51
|
+
```
|
52
|
+
relaton-xml-html <relaton-xml> <stylesheet> <output-root> <html-template>
|
53
|
+
```
|
54
|
+
|
55
|
+
Render a Relaton Collection XML as an HTML file. Used to generate an HTML index of standards.
|
56
|
+
|
57
|
+
* `relaton-xml` is the Relaton Collection XML file.
|
58
|
+
* `stylesheet` is the CSS stylesheet to be used to style the output. For the CSS styling of each bibliographic element, see below.
|
59
|
+
* `output-root` is the directory containing the Relaton XML for each file, named after the document identifier (as generated by `relaton-metanorma-extract`)
|
60
|
+
* `html-template` is the HTML Liquid Template file into which the bibliographic entries are to be inserted. The HTML Template recognises the following parameters:
|
61
|
+
** `css`: where the CSS stylesheet `stylesheet` is injected
|
62
|
+
** `title`: the Title of the collection, `./relaton-collection/title` in `relaton-xml`
|
63
|
+
** `author`: the Author of the collection, `./relaton-collection/contributor[role/@type = 'author']/organization/name` in `relaton-xml`
|
64
|
+
** `content`: the list of resources generated by the script
|
65
|
+
|
66
|
+
Sample HTML output for a bibliographic entry:
|
67
|
+
|
68
|
+
```xml
|
69
|
+
<div class="document">
|
70
|
+
<div class="doc-line">
|
71
|
+
<div class="doc-identifier">
|
72
|
+
<h2>
|
73
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.html">CC/R 3101</a>
|
74
|
+
</h2>
|
75
|
+
</div>
|
76
|
+
<div class="doc-type-wrap">
|
77
|
+
<div class="doc-type report">report</div>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
<div class="doc-title">
|
81
|
+
<h3>
|
82
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.html">CalConnect XLIII -- Position on the European Union daylight-savings timezone change</a>
|
83
|
+
</h3>
|
84
|
+
</div>
|
85
|
+
<div class="doc-info cancelled">
|
86
|
+
<div class="doc-stage cancelled">cancelled</div>
|
87
|
+
<div class="doc-dates">
|
88
|
+
<div class="doc-updated">2019-10-17</div>
|
89
|
+
</div>
|
90
|
+
</div>
|
91
|
+
<div class="doc-bib">
|
92
|
+
<div class="doc-bib-relaton">
|
93
|
+
<a href="csd/cc-r-3101.xml">Relaton XML</a>
|
94
|
+
</div>
|
95
|
+
</div>
|
96
|
+
<div class="doc-access">
|
97
|
+
<div class="doc-access-button-html">
|
98
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.html">HTML</a>
|
99
|
+
</div>
|
100
|
+
<div class="doc-access-button-pdf">
|
101
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.pdf">PDF</a>
|
102
|
+
</div>
|
103
|
+
<div class="doc-access-button-doc">
|
104
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.doc">Word</a>
|
105
|
+
</div>
|
106
|
+
<div class="doc-access-button-xml">
|
107
|
+
<a href="http://calconnect.org/pubdocs/CD0507%20CalDAV%20Use%20Cases%20V1.0.xml">XML</a>
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
</div>
|
111
|
+
```
|
112
|
+
|
113
|
+
=== relaton-yaml-xml
|
114
|
+
|
115
|
+
```
|
116
|
+
relaton-yaml-xml -R relaton-dir yaml-file
|
117
|
+
```
|
118
|
+
|
119
|
+
Convert a Relaton YAML file into a Relaton Collection XML.
|
120
|
+
|
121
|
+
The Relaton YAML file contains some initial metadata, and a list of metadata about each bibliographic entry. The following is a sample:
|
122
|
+
|
123
|
+
```yaml
|
124
|
+
htmlstylesheet: ./index-style.css
|
125
|
+
root:
|
126
|
+
title: CalConnect Standards Registry
|
127
|
+
author: "CalConnect: The Calendaring and Scheduling Consortium"
|
128
|
+
items:
|
129
|
+
- technical_committee: TC VCARD
|
130
|
+
docid: CC 18001
|
131
|
+
doctype: standard
|
132
|
+
title: "Date and time -- Representations for information interchange -- Part 1: Basic rules"
|
133
|
+
stage: Published
|
134
|
+
revdate: 2018-10-17
|
135
|
+
xml: standards/csd-datetime-explict/csd-datetime-explict.xml
|
136
|
+
html: standards/csd-datetime-explict/csd-datetime-explict.html
|
137
|
+
pdf: standards/csd-datetime-explict/csd-datetime-explict.pdf
|
138
|
+
doc: standards/csd-datetime-explict/csd-datetime-explict.doc
|
139
|
+
relaton: standards/csd-datetime-explict/cc-18001.xml
|
140
|
+
- technical_committee: TC PUBLISH
|
141
|
+
docid: CC/DIR 10001
|
142
|
+
doctype: governance
|
143
|
+
title: "Standardization and publication"
|
144
|
+
stage: proposal
|
145
|
+
revdate: 2018-10-17
|
146
|
+
uri: standards/csd-standardization/csd-standardization.xml
|
147
|
+
```
|
148
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless ARGV.size == 1
|
4
|
+
warn "./relaton-concatenate DIRECTORY (containing Relaton-XML or YAML)"
|
5
|
+
end
|
6
|
+
dir = ARGV.pop
|
7
|
+
|
8
|
+
ret = ""
|
9
|
+
|
10
|
+
Dir.foreach dir do |f|
|
11
|
+
if /\.yaml$/.match f
|
12
|
+
puts "#{__dir__}/relaton-yaml-xml -R #{dir} #{dir}/#{f}"
|
13
|
+
system "#{__dir__}/relaton-yaml-xml -R #{dir} #{dir}/#{f}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir.foreach dir do |f|
|
18
|
+
if /\.xml$/.match f
|
19
|
+
ret += File.read("#{dir}/#{f}", encoding: "utf-8")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ret = "<relaton-collection>\n#{ret}\n</relaton-collection>"
|
24
|
+
puts ret
|
data/exe/relaton-fetch
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "relaton"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
cache = "#{Dir.home}/.relaton-bib.pstore"
|
7
|
+
relaton = Relaton::Db.new(cache, nil)
|
8
|
+
types = Relaton::Db::SUPPORTED_GEMS.join(', ')
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
opt_parser = OptionParser.new do |opts|
|
13
|
+
opts.banner += " <file>"
|
14
|
+
opts.on(
|
15
|
+
'-t',
|
16
|
+
'--type TYPE',
|
17
|
+
"Type of standard to get bibliographic entry for: #{types}"
|
18
|
+
) { |v| options[:type] = v.to_sym }
|
19
|
+
|
20
|
+
opts.on(
|
21
|
+
'-y',
|
22
|
+
'--year YEAR',
|
23
|
+
"Year the standard was published"
|
24
|
+
) { |v| options[:year] = v }
|
25
|
+
|
26
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
27
|
+
puts opts
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
opt_parser.parse!(ARGV)
|
33
|
+
options[:code] = ARGV.pop
|
34
|
+
|
35
|
+
ret = relaton.fetch_std(options[:code], options[:year], options[:type], {})
|
36
|
+
|
37
|
+
if ret.nil?
|
38
|
+
warn "No matching bibliographic entry found"
|
39
|
+
else
|
40
|
+
puts ret.to_xml
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
unless ARGV.size == 2
|
6
|
+
warn "./relaton-metanorma-extract Metanorma-XML-Directory Relaton-XML-Directory"
|
7
|
+
end
|
8
|
+
indir = ARGV[0]
|
9
|
+
outdir = ARGV[1]
|
10
|
+
|
11
|
+
Dir.foreach indir do |f|
|
12
|
+
if /\.xml$/.match f
|
13
|
+
file = File.read("#{indir}/#{f}", encoding: "utf-8")
|
14
|
+
xml = Nokogiri::XML(file)
|
15
|
+
bibdata = xml.at("//xmlns:bibdata") || next
|
16
|
+
docid = bibdata&.at("./xmlns:docidentifier")&.text || f.sub(/\.xml$/, "")
|
17
|
+
outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
|
18
|
+
File.open("#{outdir}/#{outname}", "w:UTF-8") { |f| f.write bibdata.to_xml }
|
19
|
+
end
|
20
|
+
end
|
data/exe/relaton-xml-html
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# Invoke as: ./relaton-doc FILENAME STYLESHEET RELATON-ROOT
|
4
|
-
require "
|
4
|
+
require "yaml"
|
5
|
+
require "optparse"
|
6
|
+
require "fileutils"
|
5
7
|
require "relaton/cli"
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
if ARGV.size < 2 || ARGV.size > 3
|
11
|
+
warn "Invoke as: ./relaton-xml-html <relaton-index-xml> <stylesheet> <liquid-template-dir>"
|
9
12
|
exit
|
10
13
|
end
|
11
14
|
|
12
15
|
filename = ARGV[0]
|
13
|
-
|
14
|
-
relaton_root = ARGV[2] || "relaton"
|
16
|
+
file = File.read(filename, encoding: "utf-8")
|
15
17
|
|
16
|
-
|
18
|
+
puts ARGV.inspect
|
17
19
|
|
18
|
-
xml_to_html = Relaton::Cli::XmlToHtmlRenderer.new
|
20
|
+
xml_to_html = Relaton::Cli::XmlToHtmlRenderer.new({
|
21
|
+
stylesheet: ARGV[1],
|
22
|
+
liquid_dir: ARGV[2]
|
23
|
+
})
|
19
24
|
|
20
25
|
File.open(filename.sub(/\.xml$/, ".html"), "w:UTF-8") do |f|
|
21
|
-
f.write(xml_to_html.render(file
|
26
|
+
f.write(xml_to_html.render(file))
|
22
27
|
end
|
23
28
|
|
data/exe/relaton-yaml-xml
CHANGED
@@ -2,21 +2,13 @@
|
|
2
2
|
|
3
3
|
require "yaml"
|
4
4
|
require "optparse"
|
5
|
-
# require "metanorma"
|
6
|
-
# require "byebug"
|
7
5
|
require "fileutils"
|
8
6
|
require "relaton/cli"
|
9
7
|
|
10
|
-
|
11
8
|
options = {}
|
12
9
|
|
13
10
|
opt_parser = OptionParser.new do |opts|
|
14
11
|
opts.banner += " <file>"
|
15
|
-
opts.on(
|
16
|
-
'-t',
|
17
|
-
'--type TYPE',
|
18
|
-
"Type of standard to generate"
|
19
|
-
) { |v| options[:type] = v.to_sym }
|
20
12
|
|
21
13
|
opts.on(
|
22
14
|
'-r',
|
@@ -59,26 +51,18 @@ File.open(outfilename, "w") do |f|
|
|
59
51
|
f.write index_collection.to_xml
|
60
52
|
end
|
61
53
|
|
62
|
-
outdir = options[:outdir]
|
54
|
+
outdir = options[:outdir]
|
63
55
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
if outdir
|
57
|
+
FileUtils.mkdir_p(outdir)
|
58
|
+
# Write out relaton/#{id}.xml
|
59
|
+
index_collection.items_flattened.each do |item|
|
60
|
+
filename = File.join(outdir, "#{item.docid_code}.xml")
|
68
61
|
|
69
|
-
|
70
|
-
|
71
|
-
|
62
|
+
File.open(filename, "w:UTF-8") do |f|
|
63
|
+
f.write(item.to_xml)
|
64
|
+
end
|
72
65
|
|
66
|
+
end
|
73
67
|
end
|
74
68
|
|
75
|
-
# cmd = "#{File.dirname(__FILE__)}/relaton-doc #{outfilename} #{ manifest["htmlstylesheet"] || '""' } #{ options[:relaton] || '""' }"
|
76
|
-
# system cmd
|
77
|
-
|
78
|
-
#processor = registry.find_processor(options[:type].to_sym)
|
79
|
-
#ext = :html
|
80
|
-
#file_extension = "html" || processor.output_formats[ext]
|
81
|
-
#outfilename = options[:filename].sub(/\.[^.]+$/, ".#{file_extension}")
|
82
|
-
#isodoc_options = { suppressheadingnumbers: true }
|
83
|
-
#isodoc_options[:htmlstylesheet] = manifest["htmlstylesheet"] if manifest["htmlstylesheet"]
|
84
|
-
#processor.output(out, outfilename, ext, isodoc_options)
|
@@ -5,24 +5,32 @@ module Relaton
|
|
5
5
|
title
|
6
6
|
items
|
7
7
|
doctype
|
8
|
+
author
|
8
9
|
]
|
9
10
|
|
10
11
|
attr_accessor *ATTRIBS
|
11
12
|
|
13
|
+
def self.ns(xpath)
|
14
|
+
xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1").
|
15
|
+
gsub(%r{::([a-zA-z])}, "::xmlns:\\1").
|
16
|
+
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1").
|
17
|
+
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
|
18
|
+
end
|
19
|
+
|
12
20
|
def initialize(options)
|
13
21
|
self.items = []
|
14
22
|
ATTRIBS.each do |k|
|
15
23
|
method = "#{k}="
|
16
|
-
value = options[k.to_s]
|
17
|
-
|
18
|
-
|
24
|
+
value = options[k] || options[k.to_s]
|
25
|
+
puts "K #{method}"
|
26
|
+
puts value.inspect
|
19
27
|
|
20
|
-
self.send("#{k}=",
|
21
|
-
|
28
|
+
self.send("#{k}=", value)
|
29
|
+
puts "SET! to #{self.send(k).inspect}"
|
22
30
|
end
|
23
31
|
|
24
32
|
# puts items.inspect
|
25
|
-
self.items = self.items.inject([]) do |acc,item|
|
33
|
+
self.items = (self.items || []).inject([]) do |acc,item|
|
26
34
|
acc << if item.is_a?(::Relaton::Bibcollection) ||
|
27
35
|
item.is_a?(::Relaton::Bibdata)
|
28
36
|
|
@@ -37,6 +45,36 @@ module Relaton
|
|
37
45
|
# byebug
|
38
46
|
end
|
39
47
|
|
48
|
+
def self.from_xml(source)
|
49
|
+
# source = Nokogiri::XML(content)
|
50
|
+
|
51
|
+
title = source&.at(ns("./relaton-collection/title"))&.text
|
52
|
+
author = source&.at(ns("./relaton-collection/contributor[role/@type = 'author']/organization/name"))&.text
|
53
|
+
|
54
|
+
puts "!!!!!!!!!!"*3
|
55
|
+
puts "BC: title #{title}"
|
56
|
+
puts "BC: author #{author}"
|
57
|
+
puts "!!!!!!!!!!"*3
|
58
|
+
|
59
|
+
items = source.xpath(ns("./relaton-collection/relation")).map do |item|
|
60
|
+
puts "========="*3
|
61
|
+
puts "item #{item.to_s}"
|
62
|
+
klass = item.at(ns("./bibdata")) ? Bibdata : Bibcollection
|
63
|
+
klass.from_xml(item.at(ns("./bibdata")))
|
64
|
+
end
|
65
|
+
|
66
|
+
opts = {
|
67
|
+
title: title,
|
68
|
+
author: author,
|
69
|
+
items: items
|
70
|
+
}
|
71
|
+
|
72
|
+
puts "X"*38
|
73
|
+
puts opts.inspect
|
74
|
+
puts "X"*38
|
75
|
+
new(opts)
|
76
|
+
end
|
77
|
+
|
40
78
|
def new_bib_item_class(options)
|
41
79
|
if options["items"]
|
42
80
|
::Relaton::Bibcollection.new(options)
|
@@ -66,6 +104,9 @@ module Relaton
|
|
66
104
|
|
67
105
|
ret = "<relaton-collection #{collection_type}>"
|
68
106
|
ret += "<title>#{title}</title>" if title
|
107
|
+
if author
|
108
|
+
ret += "<contributor><role type='author'/><organization><name>#{author}</name></organization></contributor>"
|
109
|
+
end
|
69
110
|
unless items.empty?
|
70
111
|
items.each do |item|
|
71
112
|
ret += "<relation type='partOf'>"
|
@@ -76,5 +117,16 @@ module Relaton
|
|
76
117
|
ret += "</relaton-collection>\n"
|
77
118
|
end
|
78
119
|
|
120
|
+
def to_h
|
121
|
+
a = ATTRIBS.inject({}) do |acc, k|
|
122
|
+
acc[k] = send(k)
|
123
|
+
acc
|
124
|
+
end
|
125
|
+
|
126
|
+
a[:items] = a[:items].map(&:to_h)
|
127
|
+
|
128
|
+
a
|
129
|
+
end
|
130
|
+
|
79
131
|
end
|
80
|
-
end
|
132
|
+
end
|
data/lib/relaton/bibdata.rb
CHANGED
@@ -7,7 +7,12 @@ module Relaton
|
|
7
7
|
title
|
8
8
|
stage
|
9
9
|
relation
|
10
|
+
xml
|
11
|
+
pdf
|
12
|
+
doc
|
13
|
+
html
|
10
14
|
uri
|
15
|
+
relaton
|
11
16
|
revdate
|
12
17
|
abstract
|
13
18
|
technical_committee
|
@@ -15,22 +20,64 @@ module Relaton
|
|
15
20
|
|
16
21
|
attr_accessor *ATTRIBS
|
17
22
|
|
23
|
+
def self.ns(xpath)
|
24
|
+
xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1").
|
25
|
+
gsub(%r{::([a-zA-z])}, "::xmlns:\\1").
|
26
|
+
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1").
|
27
|
+
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
|
28
|
+
end
|
29
|
+
|
18
30
|
def initialize(options)
|
19
31
|
options.each_pair do |k,v|
|
20
32
|
send("#{k.to_s}=", v)
|
21
33
|
end
|
34
|
+
|
35
|
+
puts "*+"*30
|
36
|
+
puts self.inspect
|
37
|
+
|
38
|
+
self
|
22
39
|
end
|
23
40
|
|
24
41
|
def docid_code
|
25
42
|
docid.downcase.gsub(/[\s\/]/, "-") || ""
|
26
43
|
end
|
27
44
|
|
45
|
+
def self.from_xml(source)
|
46
|
+
|
47
|
+
# bib.relaton_xml_path = URI.escape("#{relaton_root}/#{id_code}.xml")
|
48
|
+
|
49
|
+
datetype = source.at(ns("./date[@type]")).text
|
50
|
+
revdate = source.at(ns("./date/on")).text
|
51
|
+
|
52
|
+
new({
|
53
|
+
uri: source.at(ns("./uri"))&.text,
|
54
|
+
xml: source.at(ns("./uri[@type='xml']"))&.text,
|
55
|
+
pdf: source.at(ns("./uri[@type='pdf']"))&.text,
|
56
|
+
html: source.at(ns("./uri[@type='html']"))&.text,
|
57
|
+
relaton: source.at(ns("./uri[@type='relaton']"))&.text,
|
58
|
+
doc: source.at(ns("./uri[@type='doc']"))&.text,
|
59
|
+
docid: source.at(ns("./docidentifier"))&.text,
|
60
|
+
title: source.at(ns("./title"))&.text,
|
61
|
+
doctype: source.at(ns("./@type"))&.text,
|
62
|
+
stage: source.at(ns("./status"))&.text,
|
63
|
+
technical_committee: source.at(ns("./technical-committee"))&.text,
|
64
|
+
abstract: source.at(ns("./abstract"))&.text,
|
65
|
+
revdate: Date.parse(revdate)
|
66
|
+
# revdate TODO
|
67
|
+
})
|
68
|
+
end
|
69
|
+
|
28
70
|
def to_xml
|
29
71
|
datetype = stage.casecmp("published") == 0 ? "published" : "updated"
|
30
72
|
|
31
73
|
ret = "<bibdata type='#{doctype}'>\n"
|
32
74
|
ret += "<title>#{title}</title>\n"
|
33
|
-
ret += "<uri>#{uri}</uri>\n"
|
75
|
+
ret += "<uri>#{uri}</uri>\n" if uri
|
76
|
+
ret += "<uri type='xml'>#{xml}</uri>\n" if xml
|
77
|
+
ret += "<uri type='html'>#{html}</uri>\n" if html
|
78
|
+
ret += "<uri type='pdf'>#{pdf}</uri>\n" if pdf
|
79
|
+
ret += "<uri type='doc'>#{doc}</uri>\n" if doc
|
80
|
+
ret += "<uri type='relaton'>#{relaton}</uri>\n" if relaton
|
34
81
|
ret += "<docidentifier>#{docid}</docidentifier>\n"
|
35
82
|
ret += "<date type='#{datetype}'><on>#{revdate}</on></date>\n" if revdate
|
36
83
|
ret += "<abstract>#{abstract}</abstract>\n" if abstract
|
@@ -39,5 +86,13 @@ module Relaton
|
|
39
86
|
ret += "</bibdata>\n"
|
40
87
|
end
|
41
88
|
|
89
|
+
def to_h
|
90
|
+
ATTRIBS.inject({}) do |acc, k|
|
91
|
+
value = send(k)
|
92
|
+
acc[k] = value unless value.nil?
|
93
|
+
acc
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
42
97
|
end
|
43
98
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
{%- if document.items.size > 0 -%}
|
2
|
+
<div class="doc-section">
|
3
|
+
{%- else -%}
|
4
|
+
<div class="document">
|
5
|
+
{%- endif -%}
|
6
|
+
|
7
|
+
<div class="doc-line">
|
8
|
+
<div class="doc-identifier">
|
9
|
+
<h{{ depth }}>
|
10
|
+
{% if document.html == "" %}
|
11
|
+
{{ document.docid }}
|
12
|
+
{% else %}
|
13
|
+
<a href="{{ document.html }}">{{ document.docid }}</a>
|
14
|
+
{% endif %}
|
15
|
+
</h{{ depth }}>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="doc-type-wrap">
|
19
|
+
<div class="doc-type {{ document.doctype | downcase | split: " " | join: "-" }}">
|
20
|
+
{{ document.doctype }}
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="doc-title">
|
26
|
+
<h{{ depth | plus: 1 }}>
|
27
|
+
{% if document.html == blank or document.html == nil %}
|
28
|
+
{{ document.title }}
|
29
|
+
{% else %}
|
30
|
+
<a href="{{ document.html }}">{{ document.title }}</a>
|
31
|
+
{% endif %}
|
32
|
+
</h{{ depth | plus: 1 }}>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div class="doc-info {{ document.stage | downcase }}">
|
36
|
+
<div class="doc-stage {{ document.stage | downcase }}">
|
37
|
+
{{ document.stage }}
|
38
|
+
</div>
|
39
|
+
<div class="doc-dates">
|
40
|
+
{% unless document.stage == "published" %}
|
41
|
+
<div class="doc-updated">
|
42
|
+
{% else %}
|
43
|
+
<div class="doc-published">
|
44
|
+
{% endunless %}
|
45
|
+
{{ document.revdate }}
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<div class="doc-bib">
|
51
|
+
<div class="doc-bib-relaton">
|
52
|
+
<a href="{{ document.relaton }}">Relaton XML</a>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
<div class="doc-access">
|
57
|
+
{% unless document.html == blank or document.html == nil %}
|
58
|
+
<div class="doc-access-button-html">
|
59
|
+
<a href="{{ document.html }}">HTML</a>
|
60
|
+
</div>
|
61
|
+
{% endunless %}
|
62
|
+
{% unless document.pdf == blank or document.pdf == nil %}
|
63
|
+
<div class="doc-access-button-pdf">
|
64
|
+
<a href="{{ document.pdf }}">PDF</a>
|
65
|
+
</div>
|
66
|
+
{% endunless %}
|
67
|
+
{% unless document.doc == blank or document.doc == nil %}
|
68
|
+
<div class="doc-access-button-doc">
|
69
|
+
<a href="{{ document.doc }}">Word</a>
|
70
|
+
</div>
|
71
|
+
{% endunless %}
|
72
|
+
{% unless document.xml == blank or document.xml == nil %}
|
73
|
+
<div class="doc-access-button-xml">
|
74
|
+
<a href="{{ document.xml }}">XML</a>
|
75
|
+
</div>
|
76
|
+
{% endunless %}
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
|
80
|
+
{%- if document.items.size > 0 -%}
|
81
|
+
{%- include 'document' for document.items -%}
|
82
|
+
{%- endif -%}
|
@@ -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>
|
data/lib/relaton/cli/version.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "liquid"
|
3
|
+
require 'pp'
|
1
4
|
|
2
5
|
module Relaton::Cli
|
3
6
|
class XmlToHtmlRenderer
|
4
7
|
|
5
|
-
|
8
|
+
def initialize(options)
|
9
|
+
@liquid_dir = options[:liquid_dir]
|
10
|
+
@stylesheet = File.read(options[:stylesheet], encoding: "utf-8")
|
11
|
+
|
12
|
+
puts "HTML html_template_dir #{@liquid_dir}"
|
13
|
+
@file_system = Liquid::LocalFileSystem.new(@liquid_dir)
|
14
|
+
@template = File.read(@file_system.full_path("index"), encoding: "utf-8")
|
15
|
+
Liquid::Template.file_system = @file_system
|
16
|
+
end
|
17
|
+
|
6
18
|
def ns(xpath)
|
7
19
|
xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1").
|
8
20
|
gsub(%r{::([a-zA-z])}, "::xmlns:\\1").
|
@@ -10,269 +22,45 @@ module Relaton::Cli
|
|
10
22
|
gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
|
11
23
|
end
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
<head></head>
|
17
|
-
<body></body>
|
18
|
-
</html>
|
19
|
-
HERE
|
20
|
-
|
21
|
-
# block for processing XML document fragments as XHTML,
|
22
|
-
# to allow for HTMLentities
|
23
|
-
def noko(&block)
|
24
|
-
doc = ::Nokogiri::XML.parse(NOKOHEAD)
|
25
|
-
fragment = doc.fragment("")
|
26
|
-
::Nokogiri::XML::Builder.with fragment, &block
|
27
|
-
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
|
28
|
-
l.gsub(/\s*\n/, "")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def script_cdata(result)
|
33
|
-
result.gsub(%r{<script>\s*<!\[CDATA\[}m, "<script>").
|
34
|
-
gsub(%r{\]\]>\s*</script>}, "</script>").
|
35
|
-
gsub(%r{<!\[CDATA\[\s*<script>}m, "<script>").
|
36
|
-
gsub(%r{</script>\s*\]\]>}, "</script>")
|
25
|
+
def empty2nil(v)
|
26
|
+
return nil if !v.nil? && v.is_a?(String) && v.empty?
|
27
|
+
v
|
37
28
|
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
result = noko do |xml|
|
44
|
-
xml.html do |html|
|
45
|
-
define_head(
|
46
|
-
html,
|
47
|
-
stylesheet,
|
48
|
-
doc&.at(ns("./relaton-collection/title"))&.text || "Untitled"
|
49
|
-
)
|
50
|
-
make_body html, doc, relaton_root
|
51
|
-
end
|
52
|
-
end.join("\n")
|
53
|
-
|
54
|
-
script_cdata(result)
|
30
|
+
# TODO: This should be recursive, but it's not
|
31
|
+
def hash_to_liquid(hash)
|
32
|
+
hash.map { |k, v| [k.to_s, empty2nil(v)] }.to_h
|
55
33
|
end
|
56
34
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
head.style do |style|
|
61
|
-
style.comment "\n#{stylesheet}\n"
|
62
|
-
end
|
63
|
-
head.meta **{ "http-equiv": "Content-Type", content: "text/html", charset: "utf-8" }
|
64
|
-
|
65
|
-
[
|
66
|
-
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js",
|
67
|
-
"https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"
|
68
|
-
].each do |url|
|
69
|
-
head.script **{ src: url, type: "text/javascript" } do |s|
|
70
|
-
s.text nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
[
|
75
|
-
{
|
76
|
-
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",
|
77
|
-
rel: "stylesheet",
|
78
|
-
type: "text/css"
|
79
|
-
},
|
80
|
-
{
|
81
|
-
href: "https://use.fontawesome.com/releases/v5.0.8/css/solid.css",
|
82
|
-
integrity: "sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk",
|
83
|
-
crossorigin: "anonymous"
|
84
|
-
},
|
85
|
-
{
|
86
|
-
href: "https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css",
|
87
|
-
integrity: "sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P",
|
88
|
-
crossorigin: "anonymous"
|
89
|
-
}
|
90
|
-
|
91
|
-
].each do |attribs|
|
92
|
-
head.link **attribs
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def make_body(html, xml, relaton_root)
|
99
|
-
# require "byebug"; byebug
|
100
|
-
body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
|
101
|
-
html.body **body_attr do |body|
|
102
|
-
make_body1(body, xml)
|
103
|
-
make_body2(body, xml)
|
104
|
-
make_body3(body, xml, relaton_root)
|
105
|
-
scripts(body)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def make_body1(body, docxml)
|
110
|
-
body.div **{ class: "title-section" } do |div1|
|
111
|
-
div1 << <<~END
|
112
|
-
<header>
|
113
|
-
<div class="coverpage">
|
114
|
-
<div class="wrapper-top">
|
115
|
-
<div class="coverpage-doc-identity">
|
116
|
-
<div class="coverpage-title">
|
117
|
-
<span class="title-first">#{docxml&.at(ns("./relaton-collection/title"))&.text}</span>
|
118
|
-
</div>
|
119
|
-
</div>
|
120
|
-
</div>
|
121
|
-
<div>
|
122
|
-
</header>
|
123
|
-
END
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def make_body2(body, docxml)
|
128
|
-
body.div **{ class: "prefatory-section" } do |div2|
|
129
|
-
div2.p { |p| p << " " } # placeholder
|
130
|
-
end
|
131
|
-
end
|
35
|
+
def render(index_xml)
|
36
|
+
source = Nokogiri::XML(index_xml)
|
37
|
+
bibcollection = ::Relaton::Bibcollection.from_xml(source)
|
132
38
|
|
133
|
-
|
134
|
-
#
|
135
|
-
|
136
|
-
docxml.xpath(ns("./relaton-collection/relation")).each do |x|
|
137
|
-
iterate(div3, x.at(ns("./bibdata | ./relaton-collection")), 2, relaton_root)
|
138
|
-
end
|
139
|
-
end
|
39
|
+
# puts "@"*38
|
40
|
+
# puts bibcollection.inspect
|
41
|
+
# puts "@"*38
|
140
42
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
</p>
|
149
|
-
END
|
150
|
-
end
|
43
|
+
locals = {
|
44
|
+
css: @stylesheet,
|
45
|
+
title: bibcollection.title,
|
46
|
+
author: bibcollection.author,
|
47
|
+
documents: bibcollection.to_h[:items].map { |i| hash_to_liquid(i) },
|
48
|
+
depth: 2
|
49
|
+
}
|
151
50
|
|
152
|
-
|
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]
|
153
57
|
|
154
|
-
|
155
|
-
<<~"END"
|
156
|
-
<script>
|
157
|
-
$(document).ready(function() {
|
158
|
-
$('[id^=toc]').each(function () {
|
159
|
-
var currentToc = $(this);
|
160
|
-
var url = window.location.href;
|
161
|
-
currentToc.wrap("<a href='" + url + "#" + currentToc.attr("id") + "' <\/a>");
|
162
|
-
});
|
163
|
-
});
|
164
|
-
anchors.options = { placement: 'left' };
|
165
|
-
anchors.add('h1, h2, h3, h4');
|
166
|
-
</script>
|
167
|
-
END
|
58
|
+
Liquid::Template.parse(@template).render(hash_to_liquid(locals))
|
168
59
|
end
|
169
60
|
|
170
|
-
def scripts(body)
|
171
|
-
body.parent.add_child script
|
172
|
-
end
|
173
|
-
|
174
|
-
EXTENSION_TYPES = [
|
175
|
-
{
|
176
|
-
text: "HTML",
|
177
|
-
extension: ".html"
|
178
|
-
},
|
179
|
-
{
|
180
|
-
text: "PDF",
|
181
|
-
extension: ".pdf"
|
182
|
-
},
|
183
|
-
{
|
184
|
-
text: "Word",
|
185
|
-
extension: ".doc"
|
186
|
-
},
|
187
|
-
{
|
188
|
-
text: "XML",
|
189
|
-
extension: ".xml"
|
190
|
-
}
|
191
|
-
]
|
192
|
-
|
193
61
|
def uri_for_extension(uri, extension)
|
194
|
-
uri.
|
195
|
-
|
196
|
-
|
197
|
-
def iterate(d0, bib, depth, relaton_root)
|
198
|
-
# require "byebug"; byebug
|
199
|
-
uri = bib.at(ns("./uri"))&.text
|
200
|
-
id = bib.at(ns("./docidentifier"))&.text
|
201
|
-
id_code = id.downcase.gsub(/[\s\/]/, "-") unless id.nil?
|
202
|
-
title = bib.at(ns("./title"))&.text
|
203
|
-
|
204
|
-
d0.div **{ class: bib.name == "bibdata" ? "document" : "doc-section" } do |d|
|
205
|
-
d.div **{ class: "doc-line" } do |d1|
|
206
|
-
|
207
|
-
d1.div **{ class: "doc-identifier" } do |d2|
|
208
|
-
d2.send "h#{depth}" do |h|
|
209
|
-
if uri
|
210
|
-
h.a **{ href: uri_for_extension(uri, :html) } do |a|
|
211
|
-
a << id
|
212
|
-
end
|
213
|
-
else
|
214
|
-
h << id
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
d1.div **{ class: "doc-type-wrap" } do |d2|
|
220
|
-
d2.div bib.at(ns("./@type"))&.text, **{ class: "doc-type #{bib.at(ns("./@type"))&.text&.downcase}" }
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
d.div **{ class: "doc-title" } do |d1|
|
225
|
-
d1.send "h#{depth+1}" do |h|
|
226
|
-
|
227
|
-
if uri
|
228
|
-
h.a **{ href: uri_for_extension(uri, :html) } do |a|
|
229
|
-
a << title
|
230
|
-
end
|
231
|
-
else
|
232
|
-
h << title
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
d.div **{ class: "doc-info #{bib.at(ns("./status"))&.text&.downcase}" } do |d1|
|
238
|
-
d1.div bib.at(ns("./status"))&.text, **{ class: "doc-stage #{bib.at(ns("./status"))&.text&.downcase}" }
|
239
|
-
d1.div **{ class: "doc-dates" } do |d2|
|
240
|
-
if bib.at(ns("./date[@type = 'published']/on"))
|
241
|
-
d2.div bib.at(ns("./date[@type = 'published']/on"))&.text, **{ class: "doc-published" }
|
242
|
-
end
|
243
|
-
if bib.at(ns("./date[@type = 'updated']/on"))
|
244
|
-
d2.div bib.at(ns("./date[@type = 'updated']/on"))&.text, **{ class: "doc-updated" }
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
if id
|
250
|
-
d.div **{ class: "doc-bib" } do |d1|
|
251
|
-
d1.div **{ class: "doc-bib-relaton" } do |d2|
|
252
|
-
d2.a **{ href: URI.escape("#{relaton_root}/#{id_code}.xml") } do |a|
|
253
|
-
a << "Relaton XML"
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
if uri
|
260
|
-
d.div **{ class: "doc-access" } do |d1|
|
261
|
-
|
262
|
-
EXTENSION_TYPES.each do |attribs|
|
263
|
-
d1.div **{ class: "doc-access-button-#{attribs[:extension]}" } do |d2|
|
264
|
-
d2.a **{ href: uri_for_extension(uri, attribs[:extension]) } do |a|
|
265
|
-
a << attribs[:text]
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
bib.xpath(ns("./relation")).each do |x|
|
273
|
-
iterate(d, x.at(ns("./bibdata | ./relaton-collection")), depth + 1, relaton_root)
|
274
|
-
end
|
275
|
-
end
|
62
|
+
return nil if uri.nil?
|
63
|
+
uri.sub(/\.[^.]+$/, ".#{extension.to_s}")
|
276
64
|
end
|
277
65
|
|
278
66
|
end
|
data/relaton-cli.gemspec
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
{%- if document.items.size > 0 -%}
|
2
|
+
<div class="doc-section">
|
3
|
+
{%- else -%}
|
4
|
+
<div class="document">
|
5
|
+
{%- endif -%}
|
6
|
+
|
7
|
+
<div class="doc-line">
|
8
|
+
<div class="doc-identifier">
|
9
|
+
<h{{ depth }}>
|
10
|
+
{% if document.html == "" %}
|
11
|
+
{{ document.docid }}
|
12
|
+
{% else %}
|
13
|
+
<a href="{{ document.html }}">{{ document.docid }}</a>
|
14
|
+
{% endif %}
|
15
|
+
</h{{ depth }}>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<div class="doc-type-wrap">
|
19
|
+
<div class="doc-type {{ document.doctype | downcase | split: " " | join: "-" }}">
|
20
|
+
{{ document.doctype }}
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="doc-title">
|
26
|
+
<h{{ depth | plus: 1 }}>
|
27
|
+
{% if document.html == blank or document.html == nil %}
|
28
|
+
{{ document.title }}
|
29
|
+
{% else %}
|
30
|
+
<a href="{{ document.html }}">{{ document.title }}</a>
|
31
|
+
{% endif %}
|
32
|
+
</h{{ depth | plus: 1 }}>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div class="doc-info {{ document.stage | downcase }}">
|
36
|
+
<div class="doc-stage {{ document.stage | downcase }}">
|
37
|
+
{{ document.stage }}
|
38
|
+
</div>
|
39
|
+
<div class="doc-dates">
|
40
|
+
{% unless document.stage == "published" %}
|
41
|
+
<div class="doc-updated">
|
42
|
+
{% else %}
|
43
|
+
<div class="doc-published">
|
44
|
+
{% endunless %}
|
45
|
+
{{ document.revdate }}
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<div class="doc-bib">
|
51
|
+
<div class="doc-bib-relaton">
|
52
|
+
<a href="{{ document.relaton }}">Relaton XML</a>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
<div class="doc-access">
|
57
|
+
{% unless document.html == blank or document.html == nil %}
|
58
|
+
<div class="doc-access-button-html">
|
59
|
+
<a href="{{ document.html }}">HTML</a>
|
60
|
+
</div>
|
61
|
+
{% endunless %}
|
62
|
+
{% unless document.pdf == blank or document.pdf == nil %}
|
63
|
+
<div class="doc-access-button-pdf">
|
64
|
+
<a href="{{ document.pdf }}">PDF</a>
|
65
|
+
</div>
|
66
|
+
{% endunless %}
|
67
|
+
{% unless document.doc == blank or document.doc == nil %}
|
68
|
+
<div class="doc-access-button-doc">
|
69
|
+
<a href="{{ document.doc }}">Word</a>
|
70
|
+
</div>
|
71
|
+
{% endunless %}
|
72
|
+
{% unless document.xml == blank or document.xml == nil %}
|
73
|
+
<div class="doc-access-button-xml">
|
74
|
+
<a href="{{ document.xml }}">XML</a>
|
75
|
+
</div>
|
76
|
+
{% endunless %}
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
|
80
|
+
{%- if document.items.size > 0 -%}
|
81
|
+
{%- include 'document' for document.items -%}
|
82
|
+
{%- endif -%}
|
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.2
|
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-09-
|
11
|
+
date: 2018-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,10 +136,27 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: liquid
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Relaton Command-line Interface
|
140
154
|
email:
|
141
155
|
- open.source@ribose.com
|
142
156
|
executables:
|
157
|
+
- relaton-concatenate
|
158
|
+
- relaton-fetch
|
159
|
+
- relaton-metanorma-extract
|
143
160
|
- relaton-xml-html
|
144
161
|
- relaton-yaml-xml
|
145
162
|
extensions: []
|
@@ -152,18 +169,25 @@ files:
|
|
152
169
|
- ".rubocop.yml"
|
153
170
|
- ".travis.yml"
|
154
171
|
- Gemfile
|
172
|
+
- Gemfile.lock
|
155
173
|
- LICENSE
|
156
174
|
- README.adoc
|
157
175
|
- Rakefile
|
176
|
+
- exe/relaton-concatenate
|
177
|
+
- exe/relaton-fetch
|
178
|
+
- exe/relaton-metanorma-extract
|
158
179
|
- exe/relaton-xml-html
|
159
180
|
- exe/relaton-yaml-xml
|
160
181
|
- i18n.yaml
|
161
182
|
- lib/relaton/bibcollection.rb
|
162
183
|
- lib/relaton/bibdata.rb
|
163
184
|
- lib/relaton/cli.rb
|
185
|
+
- lib/relaton/cli/_document.liquid
|
186
|
+
- lib/relaton/cli/_index.liquid
|
164
187
|
- lib/relaton/cli/version.rb
|
165
188
|
- lib/relaton/cli/xml_to_html_renderer.rb
|
166
189
|
- relaton-cli.gemspec
|
190
|
+
- templates/_document.liquid
|
167
191
|
homepage: https://github.com/riboseinc/relaton-cli
|
168
192
|
licenses:
|
169
193
|
- BSD-2-Clause
|