raindeer 0.8.2 → 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: e437d6ae9ff2fd31adeb9fa1d31e41d1d6574bcdc8d128f22f8eeb0d0c6a0f7f
4
- data.tar.gz: 34ea26b8ccccbf6f1104d050641e293bed7649dfa4036f4b2694210796fb049e
3
+ metadata.gz: d42828c094ed42e854e71771f9ead3dfe12ff79322bf8348fe35eb3c96caec94
4
+ data.tar.gz: 2aa21a01220ecad0e959e8edd05e535482bfe4afb3204703ae82460979d0cd89
5
5
  SHA512:
6
- metadata.gz: e50cd8a1cdc7fa52d60556ac60ee071b0ddc6899310d39a4169fd0119cbb6a11182cbe2c6557ef63ea2c6d8124a62a7e3b18f8a3dec5757f261638d9e956b3f6
7
- data.tar.gz: 6dadafc16826077a08bb81265480ae34b0d29d92b3c61a3aec96794b14efb2728b8d6f0002766326bd8e9f2c207a9945df7483a7da749c8866f3c0dfd8488fc3
6
+ metadata.gz: 8625736bca1b2f5ef9ff7f139a4b8172989fcd302816a5f3216f8b8c4c44c08f90b33b118c85ce4f6b242711be07a5b75c46bc7b475b3bbc9cb75641b122ea0e
7
+ data.tar.gz: b2b025031b825409cbfe418fdf336e5b8747cab209e45d2c935ac0ad5a2028194a3063c9cb48138e0889d3506a174d22d15d76044b8a875ed9711e0ccf700818
data/lib/pages/pages.rb CHANGED
@@ -8,23 +8,104 @@ module Rain
8
8
 
9
9
  attr_reader :url_paths
10
10
 
11
- Result = Struct.new(:metadata, :html)
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
- def process(file_path:)
21
+ def page(path:)
22
+ path = '/home' if path == '/'
23
+ url_path = File.expand_path("app/pages#{path}", Dir.pwd)
24
+ file_path = @url_paths[url_path] || return
25
+
19
26
  metadata, markdown = parse_file(file_path:)
20
- raindown = @raindown.render(markdown:)
27
+ raindown = Raindown.render(markdown:)
28
+
29
+ Page.new(metadata, raindown)
30
+ end
21
31
 
22
- Result.new(metadata, raindown)
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
23
50
  end
24
51
 
25
52
  private
26
53
 
27
- 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)
28
109
  dash_lines = []
29
110
  data_lines = []
30
111
  text_lines = []
@@ -38,6 +119,8 @@ module Rain
38
119
  next
39
120
  end
40
121
 
122
+ break unless parse_content
123
+
41
124
  text_lines << line
42
125
  end
43
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/raindeer/boot.rb CHANGED
@@ -45,13 +45,7 @@ end
45
45
  # FRAMEWORK EXTERNAL API
46
46
  #################################################
47
47
 
48
- module Raindeer
49
- class << self
50
- def router(&block)
51
- Providers['rain.router'].instance_eval(&block)
52
- end
53
- end
54
- end
48
+ require_relative 'raindeer'
55
49
 
56
50
  #################################################
57
51
  # APPLICATION CODE
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ module Raindeer
6
+ class << self
7
+ def router(&block)
8
+ Providers['rain.router'].instance_eval(&block)
9
+ end
10
+
11
+ def pages
12
+ Providers['rain.pages']
13
+ end
14
+ end
15
+ end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raindeer
4
- VERSION = '0.8.2'
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.8.2
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
@@ -260,6 +260,7 @@ files:
260
260
  - lib/pages/raindown/raindown.rb
261
261
  - lib/raindeer/boot.rb
262
262
  - lib/raindeer/cli.rb
263
+ - lib/raindeer/raindeer.rb
263
264
  - lib/router/route.rb
264
265
  - lib/router/route_event.rb
265
266
  - lib/router/router.rb