docco 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/docco/parser/content_node.rb +3 -6
- data/lib/docco/parser/root.rb +3 -4
- data/lib/docco/parser/section.rb +7 -9
- data/lib/docco/parser.rb +36 -11
- data/lib/docco/themes/default.css +18 -6
- data/lib/docco/themes/default.rb +5 -7
- data/lib/docco/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 913faddd18e853e718722f4a62699a7868633009b4484c7b3ec3eefa32a4901a
|
|
4
|
+
data.tar.gz: ebadd81a683aa2693f2278b006c0ddb5d4ddf89ba8a598f59c69549e5111c8f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccb0dc8e64931c6d4bc7c501a9c666f749e5615f746d26a1073c7d35aeea64edb46ae169bccae5f68b6792a91ecdd2bfc7195014ed6e7641ba541b7e7e9179fc
|
|
7
|
+
data.tar.gz: 4505b54296985860353232647e9b9809ed21203f85466727c8beb18616e14ce276c451255ced6c4765c9c95b7c289865ac5a94bdd9aae23affd60a53a26cee8b
|
|
@@ -3,17 +3,14 @@
|
|
|
3
3
|
module Docco
|
|
4
4
|
class Parser
|
|
5
5
|
class ContentNode
|
|
6
|
-
def initialize(
|
|
7
|
-
@converter = converter
|
|
6
|
+
def initialize(node, html)
|
|
8
7
|
@node = node
|
|
8
|
+
@html = html
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def inspect = %(<#{self.class}:#{@node.type} [#{@node.children}]>)
|
|
12
12
|
def section? = false
|
|
13
|
-
|
|
14
|
-
def to_html
|
|
15
|
-
@to_html ||= @converter.convert(@node, 0)
|
|
16
|
-
end
|
|
13
|
+
def to_html = @html
|
|
17
14
|
end
|
|
18
15
|
end
|
|
19
16
|
end
|
data/lib/docco/parser/root.rb
CHANGED
|
@@ -5,8 +5,7 @@ module Docco
|
|
|
5
5
|
class Root
|
|
6
6
|
attr_reader :nodes, :level
|
|
7
7
|
|
|
8
|
-
def initialize
|
|
9
|
-
@converter = converter
|
|
8
|
+
def initialize
|
|
10
9
|
@nodes = []
|
|
11
10
|
@level = 0
|
|
12
11
|
end
|
|
@@ -18,8 +17,8 @@ module Docco
|
|
|
18
17
|
@nodes << section
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def add_content(node)
|
|
22
|
-
@nodes << ContentNode.new(
|
|
20
|
+
def add_content(node, html)
|
|
21
|
+
@nodes << ContentNode.new(node, html)
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
def to_html
|
data/lib/docco/parser/section.rb
CHANGED
|
@@ -7,9 +7,9 @@ module Docco
|
|
|
7
7
|
|
|
8
8
|
attr_reader :id, :options, :nodes
|
|
9
9
|
|
|
10
|
-
def initialize(
|
|
11
|
-
@converter = converter
|
|
10
|
+
def initialize(node:, html:)
|
|
12
11
|
@node = node
|
|
12
|
+
@title_html = html
|
|
13
13
|
@id = node.attr['id']
|
|
14
14
|
@options = node.options
|
|
15
15
|
@nodes = []
|
|
@@ -24,20 +24,18 @@ module Docco
|
|
|
24
24
|
@nodes << section
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def add_content(node)
|
|
28
|
-
@nodes << ContentNode.new(
|
|
27
|
+
def add_content(node, html)
|
|
28
|
+
@nodes << ContentNode.new(node, html)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def title_html
|
|
32
|
-
@to_html ||= @converter.convert(@node, 0)
|
|
33
|
-
end
|
|
31
|
+
def title_html = @title_html
|
|
34
32
|
|
|
35
33
|
def title
|
|
36
|
-
@title ||= title_html.match(HEADING_EXP)[2]
|
|
34
|
+
@title ||= @title_html.match(HEADING_EXP)[2]
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
def to_html
|
|
40
|
-
@nodes.reduce(title_html) do |str, node|
|
|
38
|
+
@nodes.reduce(+title_html) do |str, node|
|
|
41
39
|
str << "\n" << node.to_html
|
|
42
40
|
end
|
|
43
41
|
end
|
data/lib/docco/parser.rb
CHANGED
|
@@ -4,6 +4,31 @@ require 'kramdown'
|
|
|
4
4
|
|
|
5
5
|
module Docco
|
|
6
6
|
class Parser
|
|
7
|
+
# Subclasses Kramdown's HTML converter so we can capture each top-level
|
|
8
|
+
# child's rendered HTML during a single top-down walk. Overriding only
|
|
9
|
+
# convert_root lets Kramdown drive the recursion normally (so @stack,
|
|
10
|
+
# @footnotes, @used_ids, etc. behave as designed); we just replace the
|
|
11
|
+
# root-level concatenation step with a per-child capture into a hash
|
|
12
|
+
# keyed by Kramdown element identity.
|
|
13
|
+
class Renderer < Kramdown::Converter::Html
|
|
14
|
+
attr_reader :per_element_html
|
|
15
|
+
|
|
16
|
+
def initialize(root, options)
|
|
17
|
+
super
|
|
18
|
+
@per_element_html = {}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def convert_root(el, indent)
|
|
22
|
+
@stack.push(el)
|
|
23
|
+
indent += @indent
|
|
24
|
+
el.children.each do |child|
|
|
25
|
+
@per_element_html[child] = send(@dispatcher[child.type], child, indent)
|
|
26
|
+
end
|
|
27
|
+
@stack.pop
|
|
28
|
+
''
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
7
32
|
def initialize(text, input: 'GFM')
|
|
8
33
|
@text = text
|
|
9
34
|
@input = input
|
|
@@ -14,26 +39,26 @@ module Docco
|
|
|
14
39
|
end
|
|
15
40
|
|
|
16
41
|
private
|
|
17
|
-
|
|
18
|
-
# cc.convert doc.children[0], 1 # <= 1 is indent and it's needed
|
|
42
|
+
|
|
19
43
|
def build
|
|
20
44
|
doc = Kramdown::Document.new(@text, input: @input, auto_ids: true)
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
renderer = Renderer.send(:new, doc.root, doc.options)
|
|
46
|
+
renderer.convert(doc.root)
|
|
47
|
+
|
|
48
|
+
root = Root.new
|
|
23
49
|
last_section = root
|
|
24
50
|
levels = Hash.new { |h, k| h[k] = [] }
|
|
25
|
-
levels[
|
|
51
|
+
levels[root.level] << root
|
|
26
52
|
|
|
27
53
|
doc.root.children.each do |child|
|
|
54
|
+
html = renderer.per_element_html.fetch(child)
|
|
28
55
|
if child.type == :header
|
|
29
|
-
section = Section.new(
|
|
56
|
+
section = Section.new(node: child, html: html)
|
|
30
57
|
levels[section.level] << section
|
|
31
|
-
|
|
32
|
-
parent << section
|
|
33
|
-
end
|
|
58
|
+
levels[section.level - 1].last&.<<(section)
|
|
34
59
|
last_section = section
|
|
35
|
-
else
|
|
36
|
-
last_section.add_content
|
|
60
|
+
else
|
|
61
|
+
last_section.add_content(child, html)
|
|
37
62
|
end
|
|
38
63
|
end
|
|
39
64
|
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
--border-color: #e2e8f0;
|
|
20
20
|
--code-bg: #f1f5f9;
|
|
21
21
|
--code-border: #cbd5e1;
|
|
22
|
+
/* Code blocks. Text colour must stay legible on --code-block-bg for
|
|
23
|
+
blocks highlight.js doesn't highlight (unknown language, JS disabled),
|
|
24
|
+
since those never receive its .hljs class. Defaults match atom-one-dark. */
|
|
25
|
+
--code-block-bg: #282c34;
|
|
26
|
+
--code-block-text: #abb2bf;
|
|
22
27
|
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
|
23
28
|
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
24
29
|
}
|
|
@@ -435,14 +440,14 @@ pre {
|
|
|
435
440
|
overflow-x: auto;
|
|
436
441
|
border-radius: 6px;
|
|
437
442
|
box-shadow: var(--shadow);
|
|
438
|
-
background-color:
|
|
443
|
+
background-color: var(--code-block-bg);
|
|
439
444
|
}
|
|
440
445
|
|
|
441
446
|
pre code {
|
|
442
447
|
display: block;
|
|
443
448
|
padding: 1.25rem;
|
|
444
449
|
background-color: transparent;
|
|
445
|
-
color:
|
|
450
|
+
color: var(--code-block-text);
|
|
446
451
|
border: none;
|
|
447
452
|
border-radius: 6px;
|
|
448
453
|
line-height: 1.6;
|
|
@@ -463,11 +468,18 @@ pre code::-webkit-scrollbar-thumb {
|
|
|
463
468
|
border-radius: 4px;
|
|
464
469
|
}
|
|
465
470
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
padding: 0;
|
|
471
|
+
/* Mermaid diagrams, rendered by Pele (https://pele.run) */
|
|
472
|
+
.mermaid {
|
|
473
|
+
margin: 1.5rem 0;
|
|
470
474
|
text-align: center;
|
|
475
|
+
--pele-bg: var(--content-bg);
|
|
476
|
+
--pele-fg: var(--text-color);
|
|
477
|
+
--pele-muted: var(--text-light);
|
|
478
|
+
--pele-line: var(--secondary-color);
|
|
479
|
+
--pele-surface: var(--code-bg);
|
|
480
|
+
--pele-surface-alt: var(--border-color);
|
|
481
|
+
--pele-border: var(--code-border);
|
|
482
|
+
--pele-accent: var(--primary-color);
|
|
471
483
|
}
|
|
472
484
|
|
|
473
485
|
/* Images */
|
data/lib/docco/themes/default.rb
CHANGED
|
@@ -52,17 +52,15 @@ module Docco
|
|
|
52
52
|
</div>
|
|
53
53
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
|
54
54
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/ruby.min.js"></script>
|
|
55
|
-
|
|
55
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/erb.min.js"></script>
|
|
56
|
+
<script src="https://cdn.jsdelivr.net/npm/pele@1/dist/pele.global.js"></script>
|
|
56
57
|
<script>
|
|
57
58
|
document.querySelectorAll('pre > code.language-mermaid').forEach((code) => {
|
|
58
|
-
const
|
|
59
|
-
const container = document.createElement('pre');
|
|
59
|
+
const container = document.createElement('div');
|
|
60
60
|
container.className = 'mermaid';
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
code.parentElement.replaceWith(container);
|
|
62
|
+
pele.mount(container, code.textContent);
|
|
63
63
|
});
|
|
64
|
-
mermaid.initialize({ startOnLoad: false, theme: 'default' });
|
|
65
|
-
mermaid.run();
|
|
66
64
|
hljs.highlightAll();
|
|
67
65
|
</script>
|
|
68
66
|
<script>
|
data/lib/docco/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: docco
|
|
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
|
- Ismael Celis
|
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
90
|
- !ruby/object:Gem::Version
|
|
91
91
|
version: '0'
|
|
92
92
|
requirements: []
|
|
93
|
-
rubygems_version: 4.0.
|
|
93
|
+
rubygems_version: 4.0.21
|
|
94
94
|
specification_version: 4
|
|
95
95
|
summary: Builds static HTML documentation from a Ruby gem's README
|
|
96
96
|
test_files: []
|