fni-docs-theme 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/_includes/head.html +6 -0
- data/_includes/iuml.html +5 -0
- data/_sass/modules.scss +1 -0
- data/_sass/plantuml.scss +25 -0
- data/assets/js/links.js +22 -0
- data/assets/js/plantuml.js +95 -0
- data/lib/converters/plantuml-converter.rb +98 -0
- data/lib/fni-docs-theme.rb +1 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ba5439ab23c84eab01b03238c30f867e62e58e1c6252790cb1197baf24c10c9
|
4
|
+
data.tar.gz: 2aec63e1e343635dfbc12184fc64d72c7fe6128026a7df5cc9c3679b2591df77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec084330a227096c77e00f8fa9acbc985b0e60402dffa61e7d4d414d73203300fe29919518a3cf038a74456620623e2d3baff8b8b386d89e2c04ee95b3a0aeb
|
7
|
+
data.tar.gz: 9d12d80caacf6bb2f981d8f8629807d1187bdf2d01cb720eb68788b39f34a3d977d673de737e3996968b61183275d9ee28cbcc5e10468263af236d407c968e44
|
data/README.md
CHANGED
@@ -2,18 +2,37 @@
|
|
2
2
|
|
3
3
|
Forked from [just-the-docs](https://pmarsceill.github.io/just-the-docs/)
|
4
4
|
|
5
|
+
Pertinent differences:
|
6
|
+
* Nav generation has been moved to a plugin, lib/generators/nav-generator. This ensures the nav is only generated once and can be included
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
|
-
|
10
|
+
This theme is distributed as a Jekyll plugin, to install:
|
11
|
+
|
12
|
+
* Add the plugin to your gemfile (recommend pinning a specific version):
|
13
|
+
```ruby
|
14
|
+
group :jekyll_plugins do
|
15
|
+
gem "fni-docs-theme", "0.4.2"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
Add these lines to your Jekyll site's `_config.yml`:
|
8
20
|
|
9
21
|
```yaml
|
10
|
-
|
22
|
+
theme: fni-docs-theme
|
23
|
+
|
24
|
+
plugins:
|
25
|
+
- fni-docs-theme
|
11
26
|
```
|
12
27
|
|
13
28
|
## Usage
|
14
29
|
|
15
30
|
[View the documentation](https://pmarsceill.github.io/just-the-docs/) for usage information.
|
16
31
|
|
32
|
+
## Publishing
|
33
|
+
|
34
|
+
This theme/plugin is published as fni-docs-theme to rubygems.org.
|
35
|
+
|
17
36
|
## License
|
18
37
|
|
19
38
|
The theme is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/_includes/head.html
CHANGED
@@ -29,8 +29,14 @@
|
|
29
29
|
{% if site.search_enabled != false %}
|
30
30
|
<script type="text/javascript" src="{{ '/assets/js/vendor/lunr.min.js' | relative_url }}"></script>
|
31
31
|
{% endif %}
|
32
|
+
|
33
|
+
<script src="https://cdn.jsdelivr.net/npm/plantuml-encoder@1.4.0/dist/plantuml-encoder.min.js"></script>
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.6.1/dist/svg-pan-zoom.min.js"></script>
|
35
|
+
|
32
36
|
<script type="text/javascript" src="{{ '/assets/js/just-the-docs.js' | relative_url }}"></script>
|
33
37
|
<script type="text/javascript" src="{{ '/assets/js/jtd-nav.js' | relative_url }}"></script>
|
38
|
+
<script type="text/javascript" src="{{ '/assets/js/links.js' | relative_url }}"></script>
|
39
|
+
<script type="text/javascript" src="{{ '/assets/js/plantuml.js' | relative_url }}"></script>
|
34
40
|
|
35
41
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
36
42
|
|
data/_includes/iuml.html
ADDED
data/_sass/modules.scss
CHANGED
data/_sass/plantuml.scss
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
// Style iuml diagrams
|
3
|
+
.plantuml-diagram {
|
4
|
+
position: relative;
|
5
|
+
color: #333;
|
6
|
+
|
7
|
+
svg {
|
8
|
+
border: 2px solid #444;
|
9
|
+
}
|
10
|
+
|
11
|
+
.error-msg {
|
12
|
+
margin: 1em;
|
13
|
+
padding: 0.5em;
|
14
|
+
background-color: #fdd;
|
15
|
+
border: 1px solid #922;
|
16
|
+
}
|
17
|
+
|
18
|
+
.plantuml-diagram-open {
|
19
|
+
position: absolute;
|
20
|
+
right: 5px;
|
21
|
+
bottom: 8px;
|
22
|
+
font-size: smaller;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
data/assets/js/links.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
window.jtd.onReady(() => {
|
3
|
+
externalLinks()
|
4
|
+
})
|
5
|
+
|
6
|
+
// Find all anchor links on the page that reference external pages or static files and open them in a new tab
|
7
|
+
function externalLinks() {
|
8
|
+
const newTabExtensions = ['.pdf', '.png', '.svg']
|
9
|
+
const links = document.getElementsByTagName('a')
|
10
|
+
for (const link of links) {
|
11
|
+
const href = link.getAttribute('href')
|
12
|
+
if (href && link.hostname !== location.hostname) {
|
13
|
+
link.target = "_blank";
|
14
|
+
link.rel = "noopener";
|
15
|
+
} else if (href && newTabExtensions.some(ext => href.indexOf(ext) > 0)) {
|
16
|
+
link.onclick = function () {
|
17
|
+
window.open(this.href)
|
18
|
+
return false
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
window.jtd.onReady(() => {
|
3
|
+
initDiags()
|
4
|
+
})
|
5
|
+
|
6
|
+
async function initDiags() {
|
7
|
+
const defaultWidth = 736
|
8
|
+
const defaultHeight = 400
|
9
|
+
|
10
|
+
const curPath = window.location.pathname
|
11
|
+
const diags = document.getElementsByClassName('plantuml-diagram')
|
12
|
+
|
13
|
+
for (const diag of diags) {
|
14
|
+
const src = diag.dataset.diagramSrc
|
15
|
+
const svgSrc = src.replace('.iuml', '.svg')
|
16
|
+
const diagCont = diag.getElementsByClassName('plantuml-diagram-inner')[0]
|
17
|
+
const viewCont = diag.getElementsByClassName('plantuml-diagram-open')[0]
|
18
|
+
const width = diag.dataset.diagramWidth || defaultWidth
|
19
|
+
const height = diag.dataset.diagramHeight || defaultHeight
|
20
|
+
|
21
|
+
// Fetch the svg
|
22
|
+
const svgRes = await fetch(curPath + svgSrc)
|
23
|
+
if (!svgRes.ok) {
|
24
|
+
diagCont.innerHTML = '<div class="error-msg">Failed to retrieve diagram</div>'
|
25
|
+
continue
|
26
|
+
}
|
27
|
+
|
28
|
+
// Add an open button
|
29
|
+
viewCont.innerHTML = `<a href="${svgSrc}" target="_blank" rel="noopener">open</a>`
|
30
|
+
|
31
|
+
const svg = await svgRes.text()
|
32
|
+
|
33
|
+
diagCont.innerHTML = svg
|
34
|
+
const svgElement = diag.getElementsByTagName('svg')[0]
|
35
|
+
|
36
|
+
svgElement.style.width = width
|
37
|
+
svgElement.style.height = height
|
38
|
+
svgElement.style.backgroundColor = '#333'
|
39
|
+
|
40
|
+
const spz = svgPanZoom(svgElement, {
|
41
|
+
zoomEnabled: true,
|
42
|
+
controlIconsEnabled: false,
|
43
|
+
fit: true,
|
44
|
+
center: true,
|
45
|
+
dblClickZoomEnabled: false,
|
46
|
+
customEventsHandler: {
|
47
|
+
init: options => {
|
48
|
+
// Double click to toggle fullscreen
|
49
|
+
options.svgElement.addEventListener('dblclick', () => {
|
50
|
+
if (options.svgElement.style.position === 'fixed') {
|
51
|
+
options.svgElement.style.position = null
|
52
|
+
options.svgElement.style.left = null
|
53
|
+
options.svgElement.style.top = null
|
54
|
+
options.svgElement.style.zIndex = null
|
55
|
+
options.svgElement.style.width = width
|
56
|
+
options.svgElement.style.height = height
|
57
|
+
} else {
|
58
|
+
options.svgElement.style.position = 'fixed'
|
59
|
+
options.svgElement.style.left = '20px'
|
60
|
+
options.svgElement.style.top = '20px'
|
61
|
+
options.svgElement.style.zIndex = '9999'
|
62
|
+
options.svgElement.style.width = getWidth() - 40
|
63
|
+
options.svgElement.style.height = getHeight() - 40
|
64
|
+
}
|
65
|
+
|
66
|
+
options.instance.updateBBox()
|
67
|
+
options.instance.resize()
|
68
|
+
options.instance.fit()
|
69
|
+
options.instance.center()
|
70
|
+
})
|
71
|
+
}
|
72
|
+
}
|
73
|
+
})
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
function getWidth() {
|
78
|
+
return Math.max(
|
79
|
+
document.body.scrollWidth,
|
80
|
+
document.documentElement.scrollWidth,
|
81
|
+
document.body.offsetWidth,
|
82
|
+
document.documentElement.offsetWidth,
|
83
|
+
document.documentElement.clientWidth
|
84
|
+
);
|
85
|
+
}
|
86
|
+
|
87
|
+
function getHeight() {
|
88
|
+
return Math.max(
|
89
|
+
document.body.scrollHeight,
|
90
|
+
document.documentElement.scrollHeight,
|
91
|
+
document.body.offsetHeight,
|
92
|
+
document.documentElement.offsetHeight,
|
93
|
+
document.documentElement.clientHeight
|
94
|
+
);
|
95
|
+
}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module PlantUmlConverterPlugin
|
6
|
+
# Whitelists *.iuml documents for conversion despite them lacking front matter
|
7
|
+
class PlantUmlGenerator < Jekyll::Generator
|
8
|
+
attr_accessor :site
|
9
|
+
safe true
|
10
|
+
priority :low
|
11
|
+
|
12
|
+
@plantuml_converter
|
13
|
+
|
14
|
+
def initialize(site)
|
15
|
+
@plantuml_converter = PlantUmlConverter.new()
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate(site)
|
19
|
+
diagrams = site.static_files.select { |file| @plantuml_converter.matches(static_file_ext(file)) }
|
20
|
+
site.pages.concat(diagrams.map { |diag| page_from_static_file(site, diag) })
|
21
|
+
site.static_files -= diagrams
|
22
|
+
end
|
23
|
+
|
24
|
+
def static_file_ext(static_file)
|
25
|
+
static_file.extname
|
26
|
+
end
|
27
|
+
|
28
|
+
# Given a Jekyll::StaticFile, returns the file as a Jekyll::Page
|
29
|
+
def page_from_static_file(site, static_file)
|
30
|
+
base = static_file.instance_variable_get("@base")
|
31
|
+
dir = static_file.instance_variable_get("@dir")
|
32
|
+
name = static_file.instance_variable_get("@name")
|
33
|
+
Jekyll::Page.new(site, base, dir, name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class PlantUmlConverter < Jekyll::Converter
|
38
|
+
safe true
|
39
|
+
priority :low
|
40
|
+
|
41
|
+
@config = {}
|
42
|
+
|
43
|
+
def matches(ext)
|
44
|
+
ext =~ /^\.iuml$/i
|
45
|
+
end
|
46
|
+
|
47
|
+
def output_ext(ext)
|
48
|
+
'.svg'
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize(config = {})
|
52
|
+
@config = config['plantuml']
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert(content)
|
56
|
+
dest_uri = URI("#{@config['server_uri']}/svg/")
|
57
|
+
|
58
|
+
begin
|
59
|
+
iuml = filter_iuml(content)
|
60
|
+
svg_res = Net::HTTP.post(dest_uri, iuml, 'Content-Type' => 'text/plain')
|
61
|
+
|
62
|
+
unless (svg_res.kind_of? Net::HTTPSuccess)
|
63
|
+
diag_name = content.lines.first.sub('@startuml ','').sub("\n", '')
|
64
|
+
error_msg = svg_res['X-PlantUML-Diagram-Error']
|
65
|
+
error_line = svg_res['X-PlantUML-Diagram-Error-Line']
|
66
|
+
Jekyll.logger.error "Failed to render .iuml [#{diag_name}]: #{error_msg} at line #{error_line}"
|
67
|
+
return ''
|
68
|
+
end
|
69
|
+
|
70
|
+
svg_res.body
|
71
|
+
rescue => err
|
72
|
+
diag_name = content.lines.first.sub('@startuml ','').sub("\n", '')
|
73
|
+
Jekyll.logger.error "Failed to convert IUML document: #{diag_name} - #{err.message}"
|
74
|
+
return ''
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Clean up markup as needed (matches)
|
79
|
+
# Add "!theme spacelab" if no theme present and set background color
|
80
|
+
# Add an @enduml that only seems to be needed for server rendering
|
81
|
+
def filter_iuml(iuml)
|
82
|
+
iuml_arr = iuml.split("\n")
|
83
|
+
unless (iuml.include? '!theme')
|
84
|
+
iuml_arr = iuml_arr.insert(1, '!theme spacelab')
|
85
|
+
end
|
86
|
+
unless (iuml.include? 'skinparam backgroundColor')
|
87
|
+
iuml_arr = iuml_arr.insert(2, 'skinparam backgroundColor #333')
|
88
|
+
end
|
89
|
+
unless (iuml.include? '@enduml')
|
90
|
+
iuml_arr = iuml_arr.push("@enduml")
|
91
|
+
end
|
92
|
+
iuml_arr.join("\n")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# TODO: Could also define a custom plantuml liquid block instead of the include, would still need to inject scripts into <head>
|
97
|
+
# ref https://github.com/yegor256/jekyll-plantuml/blob/master/lib/jekyll-plantuml.rb
|
98
|
+
end
|
data/lib/fni-docs-theme.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fni-docs-theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Marsceill
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- _includes/head.html
|
121
121
|
- _includes/head_custom.html
|
122
122
|
- _includes/header_custom.html
|
123
|
+
- _includes/iuml.html
|
123
124
|
- _includes/js/custom.js
|
124
125
|
- _includes/nav.html
|
125
126
|
- _includes/title.html
|
@@ -142,6 +143,7 @@ files:
|
|
142
143
|
- _sass/layout.scss
|
143
144
|
- _sass/modules.scss
|
144
145
|
- _sass/navigation.scss
|
146
|
+
- _sass/plantuml.scss
|
145
147
|
- _sass/print.scss
|
146
148
|
- _sass/search.scss
|
147
149
|
- _sass/support/_functions.scss
|
@@ -168,9 +170,12 @@ files:
|
|
168
170
|
- assets/images/search.svg
|
169
171
|
- assets/js/jtd-nav.js
|
170
172
|
- assets/js/just-the-docs.js
|
173
|
+
- assets/js/links.js
|
174
|
+
- assets/js/plantuml.js
|
171
175
|
- assets/js/vendor/lunr.min.js
|
172
176
|
- assets/js/zzzz-search-data.json
|
173
177
|
- bin/just-the-docs
|
178
|
+
- lib/converters/plantuml-converter.rb
|
174
179
|
- lib/fni-docs-theme.rb
|
175
180
|
- lib/generators/nav-generator.rb
|
176
181
|
- lib/tasks/search.rake
|