lowload 0.6.0 → 0.6.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 +4 -4
- data/lib/adapters/adapter.rb +5 -6
- data/lib/adapters/markdown_adapter.rb +21 -4
- data/lib/metadata.rb +13 -19
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0a6b7db4c15bb23eea273eb0a2d63bfed6d182b03a9964eb4c8adabc947fe93
|
|
4
|
+
data.tar.gz: 4ae8e96140a5f5560204aa7aac365167dd500068e7cef9415ef4b919b8271239
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1aee43560dc727fd1093d933805dee8f6fb8f9d466a60c594cd4c6635f007f77830c143d05827efe412b48430705636d556ee8ab554d8973e73e19f04a944df4
|
|
7
|
+
data.tar.gz: 88c59f0e36586302d1457b00926afe013fbdef453815a38b56ef1cf0b15c74edd38d081e6d263403d5f062d0a9b47b44af635da504bebf63709f040f6f0d9570
|
data/lib/adapters/adapter.rb
CHANGED
|
@@ -4,13 +4,12 @@ module LowLoad
|
|
|
4
4
|
class Adapter
|
|
5
5
|
EXTENSIONS = []
|
|
6
6
|
|
|
7
|
-
def metadata(file_path:)
|
|
8
|
-
end
|
|
7
|
+
def metadata(file_path:) = nil
|
|
9
8
|
|
|
10
|
-
def preload(file_path:)
|
|
11
|
-
end
|
|
9
|
+
def preload(file_path:) = nil
|
|
12
10
|
|
|
13
|
-
def evaluate(file_path:, top_level_binding: nil)
|
|
14
|
-
|
|
11
|
+
def evaluate(file_path:, top_level_binding: nil) = nil
|
|
12
|
+
|
|
13
|
+
def url_path(file_path:) = nil
|
|
15
14
|
end
|
|
16
15
|
end
|
|
@@ -9,19 +9,36 @@ module LowLoad
|
|
|
9
9
|
EXTENSIONS = ['md', 'rd', 'markdown', 'raindown']
|
|
10
10
|
|
|
11
11
|
def metadata(file_path:)
|
|
12
|
-
|
|
12
|
+
line_numbers = []
|
|
13
13
|
yaml_lines = []
|
|
14
14
|
|
|
15
15
|
File.foreach(file_path).with_index do |line, index|
|
|
16
16
|
if line.strip == '---'
|
|
17
|
-
|
|
18
|
-
break if
|
|
19
|
-
|
|
17
|
+
line_numbers << index + 1
|
|
18
|
+
break if line_numbers.count > 1
|
|
19
|
+
elsif line_numbers.count > 0
|
|
20
20
|
yaml_lines << line
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# TODO: Test that this returns an empty hash when no yaml lines found.
|
|
24
25
|
YAML.safe_load(yaml_lines.join, symbolize_names: true)
|
|
25
26
|
end
|
|
27
|
+
|
|
28
|
+
def url_path(file_path:)
|
|
29
|
+
# Remove "_number-" and segments beginning with "_".
|
|
30
|
+
url_path = file_path.split('/').map do |segment|
|
|
31
|
+
next segment.sub(/^_\d\W/, '') if segment.sub(/^_\d\W/, '') != segment
|
|
32
|
+
next nil if segment.sub(/^_/, '') != segment
|
|
33
|
+
|
|
34
|
+
segment
|
|
35
|
+
end.compact.join('/')
|
|
36
|
+
|
|
37
|
+
EXTENSIONS.each do |extension|
|
|
38
|
+
url_path.delete_suffix!(".#{extension}")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
url_path
|
|
42
|
+
end
|
|
26
43
|
end
|
|
27
44
|
end
|
data/lib/metadata.rb
CHANGED
|
@@ -10,41 +10,35 @@ module LowLoad
|
|
|
10
10
|
*::LowLoad::RubyAdapter::EXTENSIONS,
|
|
11
11
|
]
|
|
12
12
|
|
|
13
|
-
attr_accessor :
|
|
13
|
+
attr_accessor :loaded_paths, :missed_paths, :file_types, :url_paths, :tags
|
|
14
14
|
|
|
15
15
|
def initialize
|
|
16
|
-
@
|
|
17
|
-
|
|
18
|
-
@file_types = EXTENSIONS.each_with_object({}) do |extension, hash|
|
|
19
|
-
hash[extension] = []
|
|
20
|
-
end
|
|
16
|
+
@loaded_paths = []
|
|
17
|
+
@missed_paths = []
|
|
21
18
|
|
|
19
|
+
@file_types = EXTENSIONS.each_with_object({}) { |extension, hash| hash[extension] = [] }
|
|
20
|
+
@url_paths = {}
|
|
22
21
|
@tags = {}
|
|
23
22
|
end
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
def process(file_path_adapters:)
|
|
26
25
|
file_path_adapters.each do |file_path, adapter|
|
|
27
26
|
if (metadata = adapter&.metadata(file_path:))
|
|
28
|
-
metadata
|
|
29
|
-
file_path:,
|
|
30
|
-
file_type: File.extname(file_path).delete_prefix('.'),
|
|
31
|
-
file_loaded: true,
|
|
32
|
-
})
|
|
27
|
+
append(file_path:, adapter:, metadata:)
|
|
33
28
|
else
|
|
34
|
-
|
|
29
|
+
@missed_paths << file_path
|
|
35
30
|
end
|
|
36
|
-
|
|
37
|
-
append(metadata:)
|
|
38
31
|
end
|
|
39
32
|
end
|
|
40
33
|
|
|
41
|
-
def append(metadata:)
|
|
42
|
-
@
|
|
43
|
-
@file_types[
|
|
34
|
+
def append(file_path:, adapter:, metadata:)
|
|
35
|
+
@loaded_paths << file_path
|
|
36
|
+
@file_types[File.extname(file_path).delete_prefix('.')] << file_path
|
|
37
|
+
@url_paths[adapter.url_path(file_path:)] = file_path
|
|
44
38
|
|
|
45
39
|
metadata[:tags]&.each do |tag|
|
|
46
40
|
@tags[tag] ||= []
|
|
47
|
-
@tags[tag] =
|
|
41
|
+
@tags[tag] = file_path
|
|
48
42
|
end
|
|
49
43
|
end
|
|
50
44
|
end
|
data/lib/version.rb
CHANGED