raindeer 0.9.1 → 0.9.2
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/cli.rb +1 -1
- data/lib/cli/{static/static.rb → static.rb} +10 -3
- data/lib/pages/pages.rb +39 -30
- data/lib/pages/raindown/nodes/toc_node.rb +2 -2
- data/lib/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: 53220880f52ce3a7fbeec96659fbf6388bc614072b1a759175d3f99f0e5fe572
|
|
4
|
+
data.tar.gz: 0f4a1ea786f9bc421936ea0fced8f233d60376279160a006799748ff12991c95
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bf8b3a92b44923653298d24b2b33a614213c96edd7db24d92bcd6f9c8ac1218f4390b3dfc5312ac431506b21aaf54e65762d7af13962dffc1314ff9b2f3fafc
|
|
7
|
+
data.tar.gz: 57d336165d6d774a968ecd744c73516022c439bd2cfab66b044dbaf1af9ffadd8aa58921b775791db56903dcfa4f86bdb301b589ed8a77830b86c02ae13517ea
|
data/lib/cli/cli.rb
CHANGED
|
@@ -7,12 +7,14 @@ require 'async'
|
|
|
7
7
|
require 'async/http/internet'
|
|
8
8
|
require 'fileutils'
|
|
9
9
|
|
|
10
|
+
require_relative '../pages/pages'
|
|
11
|
+
|
|
10
12
|
module Rain
|
|
11
13
|
module CLI
|
|
12
14
|
module Static
|
|
13
15
|
extend self
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
RequestResult = Data.define(:path, :html)
|
|
16
18
|
|
|
17
19
|
def build(application_path:)
|
|
18
20
|
metadata = LowLoad.dirload(File.expand_path('app', application_path))
|
|
@@ -32,7 +34,12 @@ module Rain
|
|
|
32
34
|
private
|
|
33
35
|
|
|
34
36
|
def request_paths(metadata:, application_path:)
|
|
35
|
-
|
|
37
|
+
file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
|
|
38
|
+
url_paths = file_paths.map { |file_path| Rain::Pages.url_path(file_path:) }.compact
|
|
39
|
+
# Skip files that became solely metadata due to underscores hiding the entire file path.
|
|
40
|
+
url_paths.reject! { |url_path| url_path == '' }
|
|
41
|
+
|
|
42
|
+
tasks = url_paths.map do |file_path|
|
|
36
43
|
Async do
|
|
37
44
|
request_path = request_path(application_path:, file_path:)
|
|
38
45
|
request_url = endpoint + request_path
|
|
@@ -41,7 +48,7 @@ module Rain
|
|
|
41
48
|
response_html = response.read
|
|
42
49
|
response.close
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
RequestResult.new(path: request_path, html: response_html)
|
|
45
52
|
end
|
|
46
53
|
end
|
|
47
54
|
|
data/lib/pages/pages.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Rain
|
|
|
11
11
|
Page = Struct.new(:metadata, :html)
|
|
12
12
|
|
|
13
13
|
def initialize(metadata:)
|
|
14
|
-
@file_paths =
|
|
14
|
+
@file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
|
|
15
15
|
@url_paths = {}
|
|
16
16
|
@tags = {}
|
|
17
17
|
|
|
@@ -20,8 +20,7 @@ module Rain
|
|
|
20
20
|
|
|
21
21
|
def page(path:)
|
|
22
22
|
path = '/home' if path == '/'
|
|
23
|
-
|
|
24
|
-
file_path = @url_paths[url_path] || return
|
|
23
|
+
file_path = @url_paths[path] || return
|
|
25
24
|
|
|
26
25
|
metadata, markdown = parse_file(file_path:)
|
|
27
26
|
raindown = Raindown.render(markdown:)
|
|
@@ -29,32 +28,28 @@ module Rain
|
|
|
29
28
|
Page.new(metadata, raindown)
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
def list(
|
|
31
|
+
def list(**typed_tags)
|
|
32
|
+
file_paths = tagged(**typed_tags)
|
|
33
33
|
sorted_paths = file_paths.sort_by { order(it) }
|
|
34
|
-
|
|
35
|
-
sorted_paths.map do |file_path|
|
|
36
|
-
metadata, markdown = parse_file(file_path:)
|
|
37
|
-
metadata[:content] = markdown.empty? ? '' : Raindown.render(markdown:)
|
|
38
|
-
OpenStruct.new(metadata)
|
|
39
|
-
end
|
|
34
|
+
sorted_paths.map { |file_path| present_file(file_path:) }
|
|
40
35
|
end
|
|
41
36
|
|
|
42
37
|
def tagged(**typed_tags)
|
|
43
|
-
|
|
38
|
+
file_paths = []
|
|
44
39
|
|
|
45
40
|
typed_tags.each do |type, tag|
|
|
46
|
-
|
|
41
|
+
file_paths = [*file_paths, *@tags.dig(type, tag)]
|
|
47
42
|
end
|
|
48
43
|
|
|
49
|
-
|
|
44
|
+
file_paths
|
|
50
45
|
end
|
|
51
46
|
|
|
52
47
|
private
|
|
53
48
|
|
|
54
49
|
def process_files
|
|
55
50
|
@file_paths.each do |file_path|
|
|
56
|
-
url_path = url_path(file_path:)
|
|
57
|
-
@url_paths[url_path] = file_path
|
|
51
|
+
url_path = Pages.url_path(file_path:)
|
|
52
|
+
@url_paths[url_path] = file_path unless url_path.empty?
|
|
58
53
|
|
|
59
54
|
tag(type: :folder, tag: folders(file_path:).last, file_path:)
|
|
60
55
|
|
|
@@ -65,19 +60,6 @@ module Rain
|
|
|
65
60
|
end
|
|
66
61
|
end
|
|
67
62
|
|
|
68
|
-
# Remove segments beginning with "_" and ending with "/" or "-".
|
|
69
|
-
# Example: app/pages/docs/_basics/_1-getting-started.md => app/pages/docs/getting-started.md
|
|
70
|
-
def url_path(file_path:)
|
|
71
|
-
url_path = file_path.split('/').map do |segment|
|
|
72
|
-
next segment.sub(/^_\d\W/, '') if segment.sub(/^_\d\W/, '') != segment
|
|
73
|
-
next nil if segment.sub(/^_/, '') != segment
|
|
74
|
-
|
|
75
|
-
segment
|
|
76
|
-
end.compact.join('/')
|
|
77
|
-
|
|
78
|
-
url_path.delete_suffix(File.extname(url_path))
|
|
79
|
-
end
|
|
80
|
-
|
|
81
63
|
def tag(type:, tag:, file_path:)
|
|
82
64
|
@tags[type] ||= {}
|
|
83
65
|
@tags[type][tag] ||= []
|
|
@@ -86,7 +68,7 @@ module Rain
|
|
|
86
68
|
|
|
87
69
|
def folders(file_path:)
|
|
88
70
|
File.dirname(file_path)
|
|
89
|
-
.split(Regexp.union(['/', '-']))
|
|
71
|
+
.split(Regexp.union(['/', '&', '-']))
|
|
90
72
|
.filter { it.start_with?('_') }
|
|
91
73
|
.map { it.delete_prefix('_') }
|
|
92
74
|
.filter { !number?(it) }
|
|
@@ -94,7 +76,7 @@ module Rain
|
|
|
94
76
|
|
|
95
77
|
def order(file_path)
|
|
96
78
|
file_path
|
|
97
|
-
.split(Regexp.union(['/', '-']))
|
|
79
|
+
.split(Regexp.union(['/', '&', '-']))
|
|
98
80
|
.filter { it.start_with?('_') }
|
|
99
81
|
.map { it.delete_prefix('_') }
|
|
100
82
|
.filter { number?(it) }
|
|
@@ -105,6 +87,14 @@ module Rain
|
|
|
105
87
|
!Float(string, exception: false).nil?
|
|
106
88
|
end
|
|
107
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
|
+
|
|
108
98
|
def parse_file(file_path:, parse_content: true)
|
|
109
99
|
dash_lines = []
|
|
110
100
|
data_lines = []
|
|
@@ -126,5 +116,24 @@ module Rain
|
|
|
126
116
|
|
|
127
117
|
[YAML.safe_load(data_lines.join, symbolize_names: true), text_lines.join.strip]
|
|
128
118
|
end
|
|
119
|
+
|
|
120
|
+
class << self
|
|
121
|
+
# Remove segments beginning with "_" and ending with "&", "-" or "/".
|
|
122
|
+
# Example: app/pages/docs/_basics/_1-getting-started.md => app/pages/docs/getting-started.md
|
|
123
|
+
def url_path(file_path:)
|
|
124
|
+
url_path = file_path.split(Regexp.union(['/', '&'])).map do |segment|
|
|
125
|
+
next segment.sub(/^_\d\W/, '') if segment.sub(/^_\d\W/, '') != segment
|
|
126
|
+
next nil if segment.sub(/^_/, '') != segment
|
|
127
|
+
|
|
128
|
+
segment
|
|
129
|
+
end.compact.join('/')
|
|
130
|
+
|
|
131
|
+
url_path.delete_prefix(pages_path).delete_suffix(File.extname(url_path))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def pages_path
|
|
135
|
+
File.expand_path('app/pages', Dir.pwd)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
129
138
|
end
|
|
130
139
|
end
|
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.9.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -246,7 +246,7 @@ extra_rdoc_files: []
|
|
|
246
246
|
files:
|
|
247
247
|
- bin/rain
|
|
248
248
|
- lib/cli/cli.rb
|
|
249
|
-
- lib/cli/static
|
|
249
|
+
- lib/cli/static.rb
|
|
250
250
|
- lib/matrix/cursor.rb
|
|
251
251
|
- lib/matrix/effects/color_effect.rb
|
|
252
252
|
- lib/matrix/effects/effect.rb
|