raindeer 0.9.0 → 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 +94 -6
- data/lib/pages/raindown/nodes/toc_node.rb +2 -2
- data/lib/pages/raindown/raindown.rb +2 -4
- data/lib/version.rb +1 -1
- metadata +4 -4
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,24 +11,91 @@ module Rain
|
|
|
11
11
|
Page = Struct.new(:metadata, :html)
|
|
12
12
|
|
|
13
13
|
def initialize(metadata:)
|
|
14
|
-
@
|
|
15
|
-
@
|
|
14
|
+
@file_paths = metadata.file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact
|
|
15
|
+
@url_paths = {}
|
|
16
|
+
@tags = {}
|
|
17
|
+
|
|
18
|
+
process_files
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def page(path:)
|
|
19
22
|
path = '/home' if path == '/'
|
|
20
|
-
|
|
21
|
-
file_path = @url_paths[url_path] || return
|
|
23
|
+
file_path = @url_paths[path] || return
|
|
22
24
|
|
|
23
25
|
metadata, markdown = parse_file(file_path:)
|
|
24
|
-
raindown =
|
|
26
|
+
raindown = Raindown.render(markdown:)
|
|
25
27
|
|
|
26
28
|
Page.new(metadata, raindown)
|
|
27
29
|
end
|
|
28
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
|
|
45
|
+
end
|
|
46
|
+
|
|
29
47
|
private
|
|
30
48
|
|
|
31
|
-
def
|
|
49
|
+
def process_files
|
|
50
|
+
@file_paths.each do |file_path|
|
|
51
|
+
url_path = Pages.url_path(file_path:)
|
|
52
|
+
@url_paths[url_path] = file_path unless url_path.empty?
|
|
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)
|
|
32
99
|
dash_lines = []
|
|
33
100
|
data_lines = []
|
|
34
101
|
text_lines = []
|
|
@@ -42,10 +109,31 @@ module Rain
|
|
|
42
109
|
next
|
|
43
110
|
end
|
|
44
111
|
|
|
112
|
+
break unless parse_content
|
|
113
|
+
|
|
45
114
|
text_lines << line
|
|
46
115
|
end
|
|
47
116
|
|
|
48
117
|
[YAML.safe_load(data_lines.join, symbolize_names: true), text_lines.join.strip]
|
|
49
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
|
|
50
138
|
end
|
|
51
139
|
end
|
|
@@ -5,10 +5,8 @@ require 'antlers/elements'
|
|
|
5
5
|
require_relative 'elements'
|
|
6
6
|
|
|
7
7
|
module Rain
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@metadata = metadata
|
|
11
|
-
end
|
|
8
|
+
module Raindown
|
|
9
|
+
extend self
|
|
12
10
|
|
|
13
11
|
def render(markdown:)
|
|
14
12
|
template = markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->')
|
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
|
|
@@ -99,14 +99,14 @@ dependencies:
|
|
|
99
99
|
requirements:
|
|
100
100
|
- - "~>"
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
|
-
version:
|
|
102
|
+
version: 0.6.2
|
|
103
103
|
type: :runtime
|
|
104
104
|
prerelease: false
|
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
107
|
- - "~>"
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
109
|
+
version: 0.6.2
|
|
110
110
|
- !ruby/object:Gem::Dependency
|
|
111
111
|
name: low_loop
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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
|