raindeer 0.9.12 → 0.10.1
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/cli/static.rb +3 -3
- data/lib/matrix/matrix.rb +2 -2
- data/lib/matrix/stream.rb +1 -1
- data/lib/pages/pages.rb +19 -102
- data/lib/raindeer/boot.rb +8 -8
- data/lib/raindeer/cli.rb +2 -2
- data/lib/router/events/route_event.rb +1 -1
- data/lib/router/events/wildcard_event.rb +1 -1
- data/lib/router/router.rb +1 -1
- data/lib/version.rb +1 -1
- metadata +30 -76
- data/lib/pages/raindown/elements.rb +0 -21
- data/lib/pages/raindown/lexemes/toc_lexeme.rb +0 -21
- data/lib/pages/raindown/nodes/toc_node.rb +0 -41
- data/lib/pages/raindown/raindown.rb +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52e3ce521b166d3df697806260de0c1446e901c5fc5249fa646879346161d441
|
|
4
|
+
data.tar.gz: 1e3e444642ca2c4f380d6892d95d8eb8294156d31d6ad0a3728d61f55bf71944
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a43f006044f5ac5b4b40c01c64018614d03b79451fa11d613212dc08206464866d693ab7f1421327e43dcf3659e6bf4f91daec32fdb68f7c662e746c97b3fac8
|
|
7
|
+
data.tar.gz: 727e862a41348eb57840bc7954bc090c0765f97b956a9eddd4f0f3e9d632f60861c88072b131e30ba3a86ff1e05b8857532ea859fafcf4ee90563acf2c8807c6
|
data/lib/cli/static.rb
CHANGED
|
@@ -4,8 +4,8 @@ require 'fileutils'
|
|
|
4
4
|
require 'protocol/http'
|
|
5
5
|
require 'ruby-progressbar'
|
|
6
6
|
|
|
7
|
-
require 'antlers' # Adds antlers support to
|
|
8
|
-
require '
|
|
7
|
+
require 'antlers' # Adds antlers support to dirload.
|
|
8
|
+
require 'dirload'
|
|
9
9
|
|
|
10
10
|
require_relative '../pages/pages'
|
|
11
11
|
|
|
@@ -41,7 +41,7 @@ module Rain
|
|
|
41
41
|
private
|
|
42
42
|
|
|
43
43
|
def load_user_application(app_path:)
|
|
44
|
-
metadata =
|
|
44
|
+
metadata = dirload(app_path)
|
|
45
45
|
|
|
46
46
|
if Dir.exist?(File.expand_path('pages', app_path))
|
|
47
47
|
Providers.define('rain.pages', eager: true) do
|
data/lib/matrix/matrix.rb
CHANGED
data/lib/matrix/stream.rb
CHANGED
data/lib/pages/pages.rb
CHANGED
|
@@ -1,137 +1,54 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'raindown'
|
|
4
4
|
|
|
5
5
|
module Rain
|
|
6
|
-
|
|
6
|
+
# Generates static site pages and those pages have file paths that match a route "{page.path}".
|
|
7
|
+
# Unlike the Raindown CLI we don't write-back and we hide directives "<{}>" in the html output.
|
|
8
|
+
# This repo's .raindown/config.yml is for its own Markdown/Raindown files, not the static site.
|
|
9
|
+
class Pages < Raindown::Pages
|
|
7
10
|
include LowType
|
|
8
11
|
|
|
9
12
|
attr_reader :url_paths
|
|
10
13
|
|
|
11
14
|
Page = Struct.new(:metadata, :html)
|
|
15
|
+
RENDER_OPTIONS = { hide_directives: true }.freeze
|
|
12
16
|
|
|
13
17
|
def initialize(metadata:)
|
|
14
|
-
@file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
|
|
15
18
|
@url_paths = {}
|
|
16
|
-
@tags = {}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
super(metadata:, root: Pages.pages_path, render_options: RENDER_OPTIONS)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def page(path:)
|
|
22
24
|
path = '/home' if path == '/'
|
|
23
25
|
file_path = @url_paths[path] || return
|
|
24
26
|
|
|
25
|
-
metadata,
|
|
26
|
-
raindown = Raindown.render(markdown:)
|
|
27
|
-
|
|
28
|
-
Page.new(metadata, raindown)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def list(**typed_tags)
|
|
32
|
-
file_paths = tagged(**typed_tags)
|
|
33
|
-
sorted_paths = file_paths.sort_by { order(it) }
|
|
34
|
-
sorted_paths.map { |file_path| present_file(file_path:) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def tagged(**typed_tags)
|
|
38
|
-
file_paths = []
|
|
39
|
-
|
|
40
|
-
typed_tags.each do |type, tag|
|
|
41
|
-
file_paths = [*file_paths, *@tags.dig(type, tag)]
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
file_paths
|
|
27
|
+
Page.new(@metadata[file_path], Raindown.render_file(path: file_path, metadata: self, **RENDER_OPTIONS))
|
|
45
28
|
end
|
|
46
29
|
|
|
47
30
|
private
|
|
48
31
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
tag(type: :folder, tag: folders(file_path:).last, file_path:)
|
|
55
|
-
|
|
56
|
-
metadata, * = parse_file(file_path:, parse_content: false)
|
|
57
|
-
metadata.each do |type, tag|
|
|
58
|
-
tag(type:, tag:, file_path:)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def tag(type:, tag:, file_path:)
|
|
64
|
-
@tags[type] ||= {}
|
|
65
|
-
@tags[type][tag] ||= []
|
|
66
|
-
@tags[type][tag] << file_path
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def folders(file_path:)
|
|
70
|
-
File.dirname(file_path)
|
|
71
|
-
.split(Regexp.union(['/', '&', '-']))
|
|
72
|
-
.filter { it.start_with?('_') }
|
|
73
|
-
.map { it.delete_prefix('_') }
|
|
74
|
-
.filter { !number?(it) }
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def order(file_path)
|
|
78
|
-
file_path
|
|
79
|
-
.split(Regexp.union(['/', '&', '-']))
|
|
80
|
-
.filter { it.start_with?('_') }
|
|
81
|
-
.map { it.delete_prefix('_') }
|
|
82
|
-
.filter { number?(it) }
|
|
83
|
-
.last
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def number?(string)
|
|
87
|
-
!Float(string, exception: false).nil?
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def present_file(file_path:)
|
|
91
|
-
metadata, markdown = parse_file(file_path:)
|
|
92
|
-
metadata[:content] = markdown.empty? ? '' : Raindown.render(markdown:)
|
|
93
|
-
metadata[:path] = Pages.url_path(file_path:)
|
|
94
|
-
|
|
95
|
-
OpenStruct.new(metadata)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def parse_file(file_path:, parse_content: true)
|
|
99
|
-
dash_lines = []
|
|
100
|
-
data_lines = []
|
|
101
|
-
text_lines = []
|
|
102
|
-
|
|
103
|
-
File.foreach(file_path) do |line|
|
|
104
|
-
line.force_encoding('UTF-8')
|
|
105
|
-
|
|
106
|
-
if line.strip == '---' && dash_lines.count < 2
|
|
107
|
-
dash_lines << line
|
|
108
|
-
next
|
|
109
|
-
elsif dash_lines.count > 0 && dash_lines.count < 2
|
|
110
|
-
data_lines << line
|
|
111
|
-
next
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
break unless parse_content
|
|
115
|
-
|
|
116
|
-
text_lines << line
|
|
117
|
-
end
|
|
32
|
+
# Adds the URL path to Raindown's metadata for the file, in place of its file path.
|
|
33
|
+
def implicit_metadata(file_path:)
|
|
34
|
+
url_path = Pages.url_path(file_path:)
|
|
35
|
+
@url_paths[url_path] = file_path unless url_path.empty?
|
|
118
36
|
|
|
119
|
-
|
|
120
|
-
[metadata, text_lines.join.strip]
|
|
37
|
+
super.merge(path: url_path)
|
|
121
38
|
end
|
|
122
39
|
|
|
123
40
|
class << self
|
|
124
|
-
# Remove segments beginning with "_" and ending with "&", "-" or "/".
|
|
125
|
-
# Example: app/pages/docs/_basics/_1-getting-started.md =>
|
|
41
|
+
# Remove segments beginning with "_" and ending with "&", "-" or "/", from the path under app/pages.
|
|
42
|
+
# Example: app/pages/docs/_basics/_1-getting-started.md => /docs/getting-started
|
|
126
43
|
def url_path(file_path:)
|
|
127
|
-
url_path = file_path.split(Regexp.union(['/', '&'])).map do |segment|
|
|
128
|
-
next segment.sub(/^_\d
|
|
129
|
-
next nil if segment.
|
|
44
|
+
url_path = file_path.delete_prefix(pages_path).split(Regexp.union(['/', '&'])).map do |segment|
|
|
45
|
+
next segment.sub(/^_\d+\W/, '') if segment.match?(/^_\d+\W/)
|
|
46
|
+
next nil if segment.start_with?('_')
|
|
130
47
|
|
|
131
48
|
segment
|
|
132
49
|
end.compact.join('/')
|
|
133
50
|
|
|
134
|
-
url_path.
|
|
51
|
+
url_path.delete_suffix(File.extname(url_path))
|
|
135
52
|
end
|
|
136
53
|
|
|
137
54
|
def pages_path
|
data/lib/raindeer/boot.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
4
|
-
require '
|
|
5
|
-
require '
|
|
3
|
+
require 'lowevent'
|
|
4
|
+
require 'lownode'
|
|
5
|
+
require 'lowtype'
|
|
6
6
|
require 'observers'
|
|
7
7
|
require 'plugs'
|
|
8
8
|
require 'providers'
|
|
@@ -37,7 +37,7 @@ module Rain
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
Providers.define('low.loop') do
|
|
40
|
-
require '
|
|
40
|
+
require 'lowloop'
|
|
41
41
|
LowLoop.new(config:, router: Providers['rain.router'], renderer: Providers['rain.matrix'])
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -53,14 +53,14 @@ require_relative 'raindeer'
|
|
|
53
53
|
# APPLICATION CODE
|
|
54
54
|
#################################################
|
|
55
55
|
|
|
56
|
-
require 'antlers' # Adds antlers support to
|
|
57
|
-
require '
|
|
58
|
-
|
|
56
|
+
require 'antlers' # Adds antlers support to dirload.
|
|
57
|
+
require 'dirload'
|
|
58
|
+
dirload(File.expand_path('../system', __dir__))
|
|
59
59
|
|
|
60
60
|
application_path = File.expand_path('app', Dir.pwd)
|
|
61
61
|
return unless Dir.exist?(application_path)
|
|
62
62
|
|
|
63
|
-
metadata =
|
|
63
|
+
metadata = dirload(application_path)
|
|
64
64
|
|
|
65
65
|
if Dir.exist?(File.expand_path('pages', application_path))
|
|
66
66
|
Providers.define('rain.pages', eager: true) do
|
data/lib/raindeer/cli.rb
CHANGED
data/lib/router/router.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: raindeer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.10.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -9,34 +9,6 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: commonmarker
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - ">="
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0'
|
|
19
|
-
type: :runtime
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - ">="
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '0'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: nokogiri
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
12
|
- !ruby/object:Gem::Dependency
|
|
41
13
|
name: ostruct
|
|
42
14
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,20 +37,6 @@ dependencies:
|
|
|
65
37
|
- - ">="
|
|
66
38
|
- !ruby/object:Gem::Version
|
|
67
39
|
version: '0'
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: rouge
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - ">="
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '0'
|
|
75
|
-
type: :runtime
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - ">="
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '0'
|
|
82
40
|
- !ruby/object:Gem::Dependency
|
|
83
41
|
name: ruby-progressbar
|
|
84
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,77 +52,77 @@ dependencies:
|
|
|
94
52
|
- !ruby/object:Gem::Version
|
|
95
53
|
version: '0'
|
|
96
54
|
- !ruby/object:Gem::Dependency
|
|
97
|
-
name:
|
|
55
|
+
name: dirload
|
|
98
56
|
requirement: !ruby/object:Gem::Requirement
|
|
99
57
|
requirements:
|
|
100
58
|
- - "~>"
|
|
101
59
|
- !ruby/object:Gem::Version
|
|
102
|
-
version:
|
|
60
|
+
version: 0.7.0
|
|
103
61
|
type: :runtime
|
|
104
62
|
prerelease: false
|
|
105
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
64
|
requirements:
|
|
107
65
|
- - "~>"
|
|
108
66
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
67
|
+
version: 0.7.0
|
|
110
68
|
- !ruby/object:Gem::Dependency
|
|
111
|
-
name:
|
|
69
|
+
name: lowevent
|
|
112
70
|
requirement: !ruby/object:Gem::Requirement
|
|
113
71
|
requirements:
|
|
114
72
|
- - "~>"
|
|
115
73
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: 0.
|
|
74
|
+
version: 0.8.1
|
|
117
75
|
type: :runtime
|
|
118
76
|
prerelease: false
|
|
119
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
120
78
|
requirements:
|
|
121
79
|
- - "~>"
|
|
122
80
|
- !ruby/object:Gem::Version
|
|
123
|
-
version: 0.
|
|
81
|
+
version: 0.8.1
|
|
124
82
|
- !ruby/object:Gem::Dependency
|
|
125
|
-
name:
|
|
83
|
+
name: lowloop
|
|
126
84
|
requirement: !ruby/object:Gem::Requirement
|
|
127
85
|
requirements:
|
|
128
86
|
- - "~>"
|
|
129
87
|
- !ruby/object:Gem::Version
|
|
130
|
-
version:
|
|
88
|
+
version: 0.8.1
|
|
131
89
|
type: :runtime
|
|
132
90
|
prerelease: false
|
|
133
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
134
92
|
requirements:
|
|
135
93
|
- - "~>"
|
|
136
94
|
- !ruby/object:Gem::Version
|
|
137
|
-
version:
|
|
95
|
+
version: 0.8.1
|
|
138
96
|
- !ruby/object:Gem::Dependency
|
|
139
|
-
name:
|
|
97
|
+
name: lownode
|
|
140
98
|
requirement: !ruby/object:Gem::Requirement
|
|
141
99
|
requirements:
|
|
142
|
-
- - "
|
|
100
|
+
- - "~>"
|
|
143
101
|
- !ruby/object:Gem::Version
|
|
144
|
-
version:
|
|
102
|
+
version: 0.5.3
|
|
145
103
|
type: :runtime
|
|
146
104
|
prerelease: false
|
|
147
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
148
106
|
requirements:
|
|
149
|
-
- - "
|
|
107
|
+
- - "~>"
|
|
150
108
|
- !ruby/object:Gem::Version
|
|
151
|
-
version:
|
|
109
|
+
version: 0.5.3
|
|
152
110
|
- !ruby/object:Gem::Dependency
|
|
153
|
-
name:
|
|
111
|
+
name: lowtype
|
|
154
112
|
requirement: !ruby/object:Gem::Requirement
|
|
155
113
|
requirements:
|
|
156
|
-
- - "
|
|
114
|
+
- - "~>"
|
|
157
115
|
- !ruby/object:Gem::Version
|
|
158
|
-
version: '
|
|
116
|
+
version: '1.6'
|
|
159
117
|
type: :runtime
|
|
160
118
|
prerelease: false
|
|
161
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
162
120
|
requirements:
|
|
163
|
-
- - "
|
|
121
|
+
- - "~>"
|
|
164
122
|
- !ruby/object:Gem::Version
|
|
165
|
-
version: '
|
|
123
|
+
version: '1.6'
|
|
166
124
|
- !ruby/object:Gem::Dependency
|
|
167
|
-
name:
|
|
125
|
+
name: antlers
|
|
168
126
|
requirement: !ruby/object:Gem::Requirement
|
|
169
127
|
requirements:
|
|
170
128
|
- - "~>"
|
|
@@ -178,7 +136,7 @@ dependencies:
|
|
|
178
136
|
- !ruby/object:Gem::Version
|
|
179
137
|
version: '1.0'
|
|
180
138
|
- !ruby/object:Gem::Dependency
|
|
181
|
-
name:
|
|
139
|
+
name: expressions
|
|
182
140
|
requirement: !ruby/object:Gem::Requirement
|
|
183
141
|
requirements:
|
|
184
142
|
- - ">="
|
|
@@ -192,7 +150,7 @@ dependencies:
|
|
|
192
150
|
- !ruby/object:Gem::Version
|
|
193
151
|
version: '0'
|
|
194
152
|
- !ruby/object:Gem::Dependency
|
|
195
|
-
name:
|
|
153
|
+
name: observers
|
|
196
154
|
requirement: !ruby/object:Gem::Requirement
|
|
197
155
|
requirements:
|
|
198
156
|
- - ">="
|
|
@@ -206,7 +164,7 @@ dependencies:
|
|
|
206
164
|
- !ruby/object:Gem::Version
|
|
207
165
|
version: '0'
|
|
208
166
|
- !ruby/object:Gem::Dependency
|
|
209
|
-
name:
|
|
167
|
+
name: plugs
|
|
210
168
|
requirement: !ruby/object:Gem::Requirement
|
|
211
169
|
requirements:
|
|
212
170
|
- - ">="
|
|
@@ -220,7 +178,7 @@ dependencies:
|
|
|
220
178
|
- !ruby/object:Gem::Version
|
|
221
179
|
version: '0'
|
|
222
180
|
- !ruby/object:Gem::Dependency
|
|
223
|
-
name:
|
|
181
|
+
name: providers
|
|
224
182
|
requirement: !ruby/object:Gem::Requirement
|
|
225
183
|
requirements:
|
|
226
184
|
- - ">="
|
|
@@ -234,19 +192,19 @@ dependencies:
|
|
|
234
192
|
- !ruby/object:Gem::Version
|
|
235
193
|
version: '0'
|
|
236
194
|
- !ruby/object:Gem::Dependency
|
|
237
|
-
name:
|
|
195
|
+
name: raindown
|
|
238
196
|
requirement: !ruby/object:Gem::Requirement
|
|
239
197
|
requirements:
|
|
240
|
-
- - "
|
|
198
|
+
- - "~>"
|
|
241
199
|
- !ruby/object:Gem::Version
|
|
242
|
-
version: '0'
|
|
200
|
+
version: '0.2'
|
|
243
201
|
type: :runtime
|
|
244
202
|
prerelease: false
|
|
245
203
|
version_requirements: !ruby/object:Gem::Requirement
|
|
246
204
|
requirements:
|
|
247
|
-
- - "
|
|
205
|
+
- - "~>"
|
|
248
206
|
- !ruby/object:Gem::Version
|
|
249
|
-
version: '0'
|
|
207
|
+
version: '0.2'
|
|
250
208
|
- !ruby/object:Gem::Dependency
|
|
251
209
|
name: trees
|
|
252
210
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -282,10 +240,6 @@ files:
|
|
|
282
240
|
- lib/matrix/matrix.rb
|
|
283
241
|
- lib/matrix/stream.rb
|
|
284
242
|
- lib/pages/pages.rb
|
|
285
|
-
- lib/pages/raindown/elements.rb
|
|
286
|
-
- lib/pages/raindown/lexemes/toc_lexeme.rb
|
|
287
|
-
- lib/pages/raindown/nodes/toc_node.rb
|
|
288
|
-
- lib/pages/raindown/raindown.rb
|
|
289
243
|
- lib/raindeer/boot.rb
|
|
290
244
|
- lib/raindeer/cli.rb
|
|
291
245
|
- lib/raindeer/integrations.rb
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'plugs'
|
|
4
|
-
|
|
5
|
-
module Rain
|
|
6
|
-
class Elements
|
|
7
|
-
include Plugs
|
|
8
|
-
|
|
9
|
-
plug(:toc) do
|
|
10
|
-
plug(:lexeme) do
|
|
11
|
-
require_relative 'lexemes/toc_lexeme'
|
|
12
|
-
TOCLexeme
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
plug(:node) do
|
|
16
|
-
require_relative 'nodes/toc_node'
|
|
17
|
-
TOCNode
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'interfaces/lexeme' # From antlers gem, too generic.
|
|
4
|
-
|
|
5
|
-
module Rain
|
|
6
|
-
module TOCLexeme
|
|
7
|
-
include Antlers::Lexeme
|
|
8
|
-
|
|
9
|
-
module_function
|
|
10
|
-
|
|
11
|
-
KEYWORDS = [':toc'].freeze
|
|
12
|
-
|
|
13
|
-
def match?(keywords:, **)
|
|
14
|
-
keywords.keys.include?(':toc')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def lexeme(**)
|
|
18
|
-
{ toc: :default }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'antlers'
|
|
4
|
-
require 'nokogiri'
|
|
5
|
-
|
|
6
|
-
module Rain
|
|
7
|
-
class TOCNode < Antlers::LeafNode
|
|
8
|
-
def initialize(name:, template:)
|
|
9
|
-
super(name:)
|
|
10
|
-
|
|
11
|
-
@template = template
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def render(current_binding: nil, parent_binding: nil, slot_node: nil)
|
|
15
|
-
doc = Nokogiri::HTML(@template)
|
|
16
|
-
|
|
17
|
-
<<~HTML
|
|
18
|
-
<div class="floating">
|
|
19
|
-
<details id="toc" open>
|
|
20
|
-
<summary>Table of contents</summary>
|
|
21
|
-
<ul>
|
|
22
|
-
#{doc.css('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').map do |h|
|
|
23
|
-
"<li class='#{h.name}'><a href='\##{h['id']}'>#{h.text.strip}</a></li>"
|
|
24
|
-
end.join("\n")}
|
|
25
|
-
</ul>
|
|
26
|
-
</details>
|
|
27
|
-
</div>
|
|
28
|
-
HTML
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
class << self
|
|
32
|
-
def match?(segment:)
|
|
33
|
-
segment[:toc]
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def build(template:, **)
|
|
37
|
-
new(name: :toc, template:)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'commonmarker'
|
|
4
|
-
require 'antlers/elements'
|
|
5
|
-
require_relative 'elements'
|
|
6
|
-
|
|
7
|
-
module Rain
|
|
8
|
-
module Raindown
|
|
9
|
-
module_function
|
|
10
|
-
|
|
11
|
-
def render(markdown:)
|
|
12
|
-
template = markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->')
|
|
13
|
-
|
|
14
|
-
doc = Commonmarker.parse(template.force_encoding('UTF-8'), options: { extension: { alerts: true }})
|
|
15
|
-
doc.walk do |node|
|
|
16
|
-
if %i[code code_block].include?(node.type)
|
|
17
|
-
node.string_content = node.string_content.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
template = doc.to_html(options: { render: { unsafe: true } })
|
|
22
|
-
template = template.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
|
|
23
|
-
|
|
24
|
-
return template unless template.include?('<{') || template.include?('{')
|
|
25
|
-
|
|
26
|
-
ast = Antlers.ast(template:, elements: Antlers::Elements[:html, :prop] + Rain::Elements[:toc])
|
|
27
|
-
|
|
28
|
-
Antlers.render(ast:, current_binding: binding)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|