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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d42828c094ed42e854e71771f9ead3dfe12ff79322bf8348fe35eb3c96caec94
4
- data.tar.gz: 2aa21a01220ecad0e959e8edd05e535482bfe4afb3204703ae82460979d0cd89
3
+ metadata.gz: 53220880f52ce3a7fbeec96659fbf6388bc614072b1a759175d3f99f0e5fe572
4
+ data.tar.gz: 0f4a1ea786f9bc421936ea0fced8f233d60376279160a006799748ff12991c95
5
5
  SHA512:
6
- metadata.gz: 8625736bca1b2f5ef9ff7f139a4b8172989fcd302816a5f3216f8b8c4c44c08f90b33b118c85ce4f6b242711be07a5b75c46bc7b475b3bbc9cb75641b122ea0e
7
- data.tar.gz: b2b025031b825409cbfe418fdf336e5b8747cab209e45d2c935ac0ad5a2028194a3063c9cb48138e0889d3506a174d22d15d76044b8a875ed9711e0ccf700818
6
+ metadata.gz: 9bf8b3a92b44923653298d24b2b33a614213c96edd7db24d92bcd6f9c8ac1218f4390b3dfc5312ac431506b21aaf54e65762d7af13962dffc1314ff9b2f3fafc
7
+ data.tar.gz: 57d336165d6d774a968ecd744c73516022c439bd2cfab66b044dbaf1af9ffadd8aa58921b775791db56903dcfa4f86bdb301b589ed8a77830b86c02ae13517ea
data/lib/cli/cli.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'trees'
4
- require_relative 'static/static'
4
+ require_relative 'static'
5
5
 
6
6
  module Rain
7
7
  module CLI
@@ -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
- Result = Data.define(:path, :html)
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
- tasks = metadata.url_paths.keys.compact.map do |file_path|
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
- Result.new(path: request_path, html: response_html)
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 = [*metadata.file_types['md'], *metadata.file_types['markdown']]
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
- url_path = File.expand_path("app/pages#{path}", Dir.pwd)
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(file_paths:)
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
- results = []
38
+ file_paths = []
44
39
 
45
40
  typed_tags.each do |type, tag|
46
- results = [*results, *@tags.dig(type, tag)]
41
+ file_paths = [*file_paths, *@tags.dig(type, tag)]
47
42
  end
48
43
 
49
- results
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
@@ -23,8 +23,8 @@ module Rain
23
23
  "<li class='#{h.name}'><a href='\##{h['id']}'>#{h.text.strip}</a></li>"
24
24
  }.join("\n")}
25
25
  </ul>
26
- </div>
27
- </details>
26
+ </details>
27
+ </div>
28
28
  HTML
29
29
  end
30
30
 
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindeer
4
- VERSION = '0.9.1'
4
+ VERSION = '0.9.2'
5
5
  end
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.1
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/static.rb
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