raindeer 0.9.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f5ab8d692028a47cd2cb2098f37d4751b28fbf782b005ea113ec818101cd247
4
- data.tar.gz: fe6b4820b15d0dc1698aa4d0276996575869576fa89c31f5162873b9290c80be
3
+ metadata.gz: d42828c094ed42e854e71771f9ead3dfe12ff79322bf8348fe35eb3c96caec94
4
+ data.tar.gz: 2aa21a01220ecad0e959e8edd05e535482bfe4afb3204703ae82460979d0cd89
5
5
  SHA512:
6
- metadata.gz: 5fed261d28894f9ac83fd2a90e2abb3c3eb044be6e86d05a4fd764b0dcfaf667668dbc5e9804a4352a3c2256ed3692a8dacd75dcd3bb505e9b93d5b06f911c47
7
- data.tar.gz: d9cbb7ce353d72f68e4ca9894a400fc7f371dd3c5c3cfdc038a81b9490b93d4d9627ed8014f029d30bc61e8efb7d3c1b31610b7398106cf44bb620b4570cdae5
6
+ metadata.gz: 8625736bca1b2f5ef9ff7f139a4b8172989fcd302816a5f3216f8b8c4c44c08f90b33b118c85ce4f6b242711be07a5b75c46bc7b475b3bbc9cb75641b122ea0e
7
+ data.tar.gz: b2b025031b825409cbfe418fdf336e5b8747cab209e45d2c935ac0ad5a2028194a3063c9cb48138e0889d3506a174d22d15d76044b8a875ed9711e0ccf700818
data/lib/pages/pages.rb CHANGED
@@ -11,8 +11,11 @@ module Rain
11
11
  Page = Struct.new(:metadata, :html)
12
12
 
13
13
  def initialize(metadata:)
14
- @url_paths = metadata.url_paths
15
- @raindown = Raindown.new(metadata:)
14
+ @file_paths = [*metadata.file_types['md'], *metadata.file_types['markdown']]
15
+ @url_paths = {}
16
+ @tags = {}
17
+
18
+ process_files
16
19
  end
17
20
 
18
21
  def page(path:)
@@ -21,14 +24,88 @@ module Rain
21
24
  file_path = @url_paths[url_path] || return
22
25
 
23
26
  metadata, markdown = parse_file(file_path:)
24
- raindown = @raindown.render(markdown:)
27
+ raindown = Raindown.render(markdown:)
25
28
 
26
29
  Page.new(metadata, raindown)
27
30
  end
28
31
 
32
+ def list(file_paths:)
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
40
+ end
41
+
42
+ def tagged(**typed_tags)
43
+ results = []
44
+
45
+ typed_tags.each do |type, tag|
46
+ results = [*results, *@tags.dig(type, tag)]
47
+ end
48
+
49
+ results
50
+ end
51
+
29
52
  private
30
53
 
31
- def parse_file(file_path:)
54
+ def process_files
55
+ @file_paths.each do |file_path|
56
+ url_path = url_path(file_path:)
57
+ @url_paths[url_path] = file_path
58
+
59
+ tag(type: :folder, tag: folders(file_path:).last, file_path:)
60
+
61
+ metadata, * = parse_file(file_path:, parse_content: false)
62
+ metadata.each do |type, tag|
63
+ tag(type:, tag:, file_path:)
64
+ end
65
+ end
66
+ end
67
+
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
+ def tag(type:, tag:, file_path:)
82
+ @tags[type] ||= {}
83
+ @tags[type][tag] ||= []
84
+ @tags[type][tag] << file_path
85
+ end
86
+
87
+ def folders(file_path:)
88
+ File.dirname(file_path)
89
+ .split(Regexp.union(['/', '-']))
90
+ .filter { it.start_with?('_') }
91
+ .map { it.delete_prefix('_') }
92
+ .filter { !number?(it) }
93
+ end
94
+
95
+ def order(file_path)
96
+ file_path
97
+ .split(Regexp.union(['/', '-']))
98
+ .filter { it.start_with?('_') }
99
+ .map { it.delete_prefix('_') }
100
+ .filter { number?(it) }
101
+ .last
102
+ end
103
+
104
+ def number?(string)
105
+ !Float(string, exception: false).nil?
106
+ end
107
+
108
+ def parse_file(file_path:, parse_content: true)
32
109
  dash_lines = []
33
110
  data_lines = []
34
111
  text_lines = []
@@ -42,6 +119,8 @@ module Rain
42
119
  next
43
120
  end
44
121
 
122
+ break unless parse_content
123
+
45
124
  text_lines << line
46
125
  end
47
126
 
@@ -5,10 +5,8 @@ require 'antlers/elements'
5
5
  require_relative 'elements'
6
6
 
7
7
  module Rain
8
- class Raindown
9
- def initialize(metadata: {})
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindeer
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
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.0
4
+ version: 0.9.1
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: '0.5'
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: '0.5'
109
+ version: 0.6.2
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: low_loop
112
112
  requirement: !ruby/object:Gem::Requirement