lowload 0.6.1 → 0.6.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/adapters/adapter.rb +6 -4
- data/lib/adapters/markdown_adapter.rb +1 -34
- data/lib/adapters/rbx_adapter.rb +3 -5
- data/lib/adapters/ruby_adapter.rb +2 -4
- data/lib/lowload.rb +28 -13
- data/lib/metadata.rb +7 -31
- 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: 6e6ef1c86c15e9d8f7318a024bfbfac163defc88e21b01269f8f1f32167b70ec
|
|
4
|
+
data.tar.gz: 0d30281fef9813da99ddd0326724af9399bb4c9a68aaf181469599bdf174eefb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12ba3c16d52fdcc5f9a8edea188891456367f9e9d4c7fa73b223dff4130732944edae68339b30fc8361c787293ca6baed0ff7afb439c7b1936756867dcd62768
|
|
7
|
+
data.tar.gz: a1ad316c6b3581df9db76b0281c26da17342847473e819dca73ba8f63ff2a73a7c59edeec6cf8eca00b4b68e9f5606577b3b172ef90fe197325345d304c15c8e
|
data/lib/adapters/adapter.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
|
4
|
+
|
|
3
5
|
module LowLoad
|
|
4
6
|
class Adapter
|
|
5
|
-
EXTENSIONS = []
|
|
7
|
+
EXTENSIONS = [].freeze
|
|
6
8
|
|
|
7
|
-
def
|
|
9
|
+
def mapload(file_path:) = nil
|
|
8
10
|
|
|
9
11
|
def preload(file_path:) = nil
|
|
10
12
|
|
|
11
13
|
def evaluate(file_path:, top_level_binding: nil) = nil
|
|
12
|
-
|
|
13
|
-
def url_path(file_path:) = nil
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
+
|
|
17
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
|
@@ -6,39 +6,6 @@ require_relative 'adapter'
|
|
|
6
6
|
|
|
7
7
|
module LowLoad
|
|
8
8
|
class MarkdownAdapter < Adapter
|
|
9
|
-
EXTENSIONS = [
|
|
10
|
-
|
|
11
|
-
def metadata(file_path:)
|
|
12
|
-
line_numbers = []
|
|
13
|
-
yaml_lines = []
|
|
14
|
-
|
|
15
|
-
File.foreach(file_path).with_index do |line, index|
|
|
16
|
-
if line.strip == '---'
|
|
17
|
-
line_numbers << index + 1
|
|
18
|
-
break if line_numbers.count > 1
|
|
19
|
-
elsif line_numbers.count > 0
|
|
20
|
-
yaml_lines << line
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# TODO: Test that this returns an empty hash when no yaml lines found.
|
|
25
|
-
YAML.safe_load(yaml_lines.join, symbolize_names: true)
|
|
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
|
|
9
|
+
EXTENSIONS = %w[md rd markdown raindown].freeze
|
|
43
10
|
end
|
|
44
11
|
end
|
data/lib/adapters/rbx_adapter.rb
CHANGED
|
@@ -10,13 +10,11 @@ end
|
|
|
10
10
|
|
|
11
11
|
module LowLoad
|
|
12
12
|
class RBXAdapter < Adapter
|
|
13
|
-
EXTENSIONS = ['rbx']
|
|
13
|
+
EXTENSIONS = ['rbx'].freeze
|
|
14
14
|
|
|
15
15
|
# Map all definitions and dependencies.
|
|
16
|
-
def
|
|
16
|
+
def mapload(file_path:)
|
|
17
17
|
Lowkey.load(file_path)
|
|
18
|
-
|
|
19
|
-
{ file_path: }
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
# Then autoload all dependencies for those files.
|
|
@@ -35,7 +33,7 @@ module LowLoad
|
|
|
35
33
|
eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
|
|
36
34
|
|
|
37
35
|
# 3. "Runtime" phase (before low nodes are rendered).
|
|
38
|
-
# Templates only exist if antlers gem has been required by another gem (
|
|
36
|
+
# Templates only exist if antlers gem has been required by another gem (like LowNode) and the template contains antlers syntax.
|
|
39
37
|
templates.each do |namespace, method_template|
|
|
40
38
|
klass = Object.const_get(namespace)
|
|
41
39
|
method, template = method_template
|
|
@@ -6,13 +6,11 @@ require_relative '../loader'
|
|
|
6
6
|
|
|
7
7
|
module LowLoad
|
|
8
8
|
class RubyAdapter < Adapter
|
|
9
|
-
EXTENSIONS = ['rb']
|
|
9
|
+
EXTENSIONS = ['rb'].freeze
|
|
10
10
|
|
|
11
11
|
# Map all definitions and dependencies.
|
|
12
|
-
def
|
|
12
|
+
def mapload(file_path:)
|
|
13
13
|
Lowkey.load(file_path)
|
|
14
|
-
|
|
15
|
-
{ file_path: }
|
|
16
14
|
end
|
|
17
15
|
|
|
18
16
|
# Then autoload all dependencies for those files.
|
data/lib/lowload.rb
CHANGED
|
@@ -11,22 +11,32 @@ module LowLoad
|
|
|
11
11
|
class UnsupportedTemplate < StandardError; end
|
|
12
12
|
|
|
13
13
|
class << self
|
|
14
|
-
ADAPTERS = [MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new]
|
|
14
|
+
ADAPTERS = [MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new].freeze
|
|
15
15
|
|
|
16
|
-
def dirload(path, pwd = Dir.pwd)
|
|
16
|
+
def dirload(path, pwd = Dir.pwd) # rubocop:disable Metrics/AbcSize
|
|
17
17
|
absolute_path = File.expand_path(path, pwd)
|
|
18
18
|
file_paths = Dir["#{absolute_path}/**/*"].filter { !File.directory?(it) }
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
loaded_paths = {}
|
|
21
|
+
missed_paths = []
|
|
22
|
+
file_types = {}
|
|
23
|
+
|
|
24
|
+
file_paths.each do |file_path|
|
|
25
|
+
if (adapter = find_adapter(file_path:))
|
|
26
|
+
loaded_paths[file_path] = adapter
|
|
27
|
+
else
|
|
28
|
+
missed_paths << adapter
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
file_types[extension(file_path:)] ||= []
|
|
32
|
+
file_types[extension(file_path:)] << file_path
|
|
22
33
|
end
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
step(:
|
|
27
|
-
step(:evaluate, file_path_adapters:)
|
|
35
|
+
step(:mapload, loaded_paths:)
|
|
36
|
+
step(:preload, loaded_paths:)
|
|
37
|
+
step(:evaluate, loaded_paths:)
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
Metadata.new(loaded_paths:, missed_paths:, file_types:)
|
|
30
40
|
end
|
|
31
41
|
|
|
32
42
|
def lowload(file_path)
|
|
@@ -37,15 +47,20 @@ module LowLoad
|
|
|
37
47
|
adapter.evaluate(file_path:)
|
|
38
48
|
end
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def step(step, loaded_paths:)
|
|
53
|
+
loaded_paths.each do |file_path, adapter|
|
|
42
54
|
adapter&.send(step, file_path:)
|
|
43
55
|
end
|
|
44
56
|
end
|
|
45
57
|
|
|
46
58
|
def find_adapter(file_path:)
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
ADAPTERS.find { |adapter| adapter.class::EXTENSIONS.include?(extension(file_path:)) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def extension(file_path:)
|
|
63
|
+
File.extname(file_path).delete_prefix('.')
|
|
49
64
|
end
|
|
50
65
|
end
|
|
51
66
|
end
|
data/lib/metadata.rb
CHANGED
|
@@ -7,39 +7,15 @@ module LowLoad
|
|
|
7
7
|
EXTENSIONS = [
|
|
8
8
|
*::LowLoad::MarkdownAdapter::EXTENSIONS,
|
|
9
9
|
*::LowLoad::RBXAdapter::EXTENSIONS,
|
|
10
|
-
*::LowLoad::RubyAdapter::EXTENSIONS
|
|
11
|
-
]
|
|
10
|
+
*::LowLoad::RubyAdapter::EXTENSIONS
|
|
11
|
+
].freeze
|
|
12
12
|
|
|
13
|
-
attr_accessor :loaded_paths, :missed_paths, :file_types
|
|
13
|
+
attr_accessor :loaded_paths, :missed_paths, :file_types
|
|
14
14
|
|
|
15
|
-
def initialize
|
|
16
|
-
@loaded_paths =
|
|
17
|
-
@missed_paths =
|
|
18
|
-
|
|
19
|
-
@file_types = EXTENSIONS.each_with_object({}) { |extension, hash| hash[extension] = [] }
|
|
20
|
-
@url_paths = {}
|
|
21
|
-
@tags = {}
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def process(file_path_adapters:)
|
|
25
|
-
file_path_adapters.each do |file_path, adapter|
|
|
26
|
-
if (metadata = adapter&.metadata(file_path:))
|
|
27
|
-
append(file_path:, adapter:, metadata:)
|
|
28
|
-
else
|
|
29
|
-
@missed_paths << file_path
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
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
|
|
38
|
-
|
|
39
|
-
metadata[:tags]&.each do |tag|
|
|
40
|
-
@tags[tag] ||= []
|
|
41
|
-
@tags[tag] = file_path
|
|
42
|
-
end
|
|
15
|
+
def initialize(loaded_paths:, missed_paths:, file_types:)
|
|
16
|
+
@loaded_paths = loaded_paths
|
|
17
|
+
@missed_paths = missed_paths
|
|
18
|
+
@file_types = file_types
|
|
43
19
|
end
|
|
44
20
|
end
|
|
45
21
|
end
|
data/lib/version.rb
CHANGED