dirload 0.6.2 → 0.7.0
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 +4 -0
- data/lib/adapters/markdown_adapter.rb +0 -2
- data/lib/adapters/rbx_adapter.rb +5 -8
- data/lib/adapters/ruby_adapter.rb +0 -3
- data/lib/dirload.rb +40 -23
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b730495cdf58d9fd471583c4860289c6de962384bf69060c577fd768351f1c3
|
|
4
|
+
data.tar.gz: c24de8fccddb64f0f8bb16c5250206e6ee06f5be45833ee1a91ab866be291338
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72201134942139589a3133ba434431100d1d4ed8256806277227e427aea4c72e4a2ac46b42d4dae29f88b840fe680642b2f5aba6a54a77cca2b696f2d92705bf
|
|
7
|
+
data.tar.gz: 1e6c599bc9ecfa5a1294ba706f0fa65ddc67326f58c59cff4730818e48aff299413df2858412c817870f41712e1d1389ba36511fb5c3e5e3fd792847b9943abd
|
data/lib/adapters/adapter.rb
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
# rubocop:disable Lint/UnusedMethodArgument
|
|
4
4
|
|
|
5
5
|
module Dirload
|
|
6
|
+
# A step is run on all files before moving on to the next step.
|
|
6
7
|
class Adapter
|
|
7
8
|
EXTENSIONS = [].freeze
|
|
8
9
|
|
|
10
|
+
# Map definitions and dependencies.
|
|
9
11
|
def mapload(file_path:) = nil
|
|
10
12
|
|
|
13
|
+
# Then autoload all dependencies for those files.
|
|
11
14
|
def preload(file_path:) = nil
|
|
12
15
|
|
|
16
|
+
# Now we can load the file into Ruby.
|
|
13
17
|
def evaluate(file_path:, top_level_binding: nil) = nil
|
|
14
18
|
end
|
|
15
19
|
end
|
data/lib/adapters/rbx_adapter.rb
CHANGED
|
@@ -12,20 +12,18 @@ module Dirload
|
|
|
12
12
|
class RBXAdapter < Adapter
|
|
13
13
|
EXTENSIONS = ['rbx'].freeze
|
|
14
14
|
|
|
15
|
-
# Map all definitions and dependencies.
|
|
16
15
|
def mapload(file_path:)
|
|
17
16
|
Lowkey.load(file_path)
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
# Then autoload all dependencies for those files.
|
|
21
19
|
def preload(file_path:)
|
|
22
20
|
Loader.add_autoloads(file_proxy: Lowkey[file_path])
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
# Now we can load the file into Ruby.
|
|
26
23
|
def evaluate(file_path:)
|
|
27
24
|
# 1. "File Load" phase.
|
|
28
|
-
|
|
25
|
+
# Load fresh because wrapping render methods mutates the file proxy, which would break re-evaluating a cached one.
|
|
26
|
+
file_proxy = Lowkey.load(file_path)
|
|
29
27
|
templates = wrap_render_methods(file_proxy:)
|
|
30
28
|
|
|
31
29
|
# 2. "Class Load" phase.
|
|
@@ -33,7 +31,7 @@ module Dirload
|
|
|
33
31
|
eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
|
|
34
32
|
|
|
35
33
|
# 3. "Runtime" phase (before low nodes are rendered).
|
|
36
|
-
# Templates only exist
|
|
34
|
+
# Templates only exist when there's a template engine and the template contains template syntax.
|
|
37
35
|
templates.each do |namespace, method_template|
|
|
38
36
|
klass = Object.const_get(namespace)
|
|
39
37
|
method, template = method_template
|
|
@@ -42,8 +40,7 @@ module Dirload
|
|
|
42
40
|
|
|
43
41
|
next unless supports_templates?(klass) || raise(UnsupportedTemplate, "Template for '#{namespace}' identified but not implemented")
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
klass.build_template(template:, params:, engine: Antlers, namespace:)
|
|
43
|
+
klass.build_template(template:, params:, engine: Dirload.template_engine, namespace:)
|
|
47
44
|
end
|
|
48
45
|
end
|
|
49
46
|
|
|
@@ -64,7 +61,7 @@ module Dirload
|
|
|
64
61
|
|
|
65
62
|
render_method_body = render_method.body.export
|
|
66
63
|
|
|
67
|
-
if
|
|
64
|
+
if Dirload.template_engine && ['{', '<{'].any? { |needle| render_method_body.include?(needle) }
|
|
68
65
|
templates[class_proxy.namespace] = [render_method, render_method_body]
|
|
69
66
|
end
|
|
70
67
|
|
|
@@ -8,17 +8,14 @@ module Dirload
|
|
|
8
8
|
class RubyAdapter < Adapter
|
|
9
9
|
EXTENSIONS = ['rb'].freeze
|
|
10
10
|
|
|
11
|
-
# Map all definitions and dependencies.
|
|
12
11
|
def mapload(file_path:)
|
|
13
12
|
Lowkey.load(file_path)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
# Then autoload all dependencies for those files.
|
|
17
15
|
def preload(file_path:)
|
|
18
16
|
Loader.add_autoloads(file_proxy: Lowkey[file_path])
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
# Now we can load the file into Ruby.
|
|
22
19
|
def evaluate(file_path:)
|
|
23
20
|
load(file_path)
|
|
24
21
|
end
|
data/lib/dirload.rb
CHANGED
|
@@ -7,45 +7,62 @@ require_relative 'loader'
|
|
|
7
7
|
require_relative 'metadata'
|
|
8
8
|
|
|
9
9
|
module Dirload
|
|
10
|
+
module_function
|
|
11
|
+
|
|
10
12
|
class UnsupportedFileType < StandardError; end
|
|
11
13
|
class UnsupportedTemplate < StandardError; end
|
|
12
14
|
|
|
13
15
|
ADAPTERS = [MarkdownAdapter.new, RBXAdapter.new, RubyAdapter.new].freeze
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
absolute_path = File.expand_path(path, pwd)
|
|
17
|
+
Config = Struct.new(:template_engine)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
def config
|
|
20
|
+
@config ||= Config.new(nil)
|
|
21
|
+
end
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
def configure
|
|
24
|
+
yield(config)
|
|
25
|
+
end
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
missed_paths << adapter
|
|
29
|
-
end
|
|
27
|
+
# The engine that RBX templates are built with. Defaults to Antlers when another gem (such as LowNode) requires it.
|
|
28
|
+
def template_engine
|
|
29
|
+
config.template_engine || (Antlers if defined?(Antlers))
|
|
30
|
+
end
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
module KernelMethods
|
|
33
|
+
def dirload(path, pwd = Dir.pwd, error: false) # rubocop:disable Metrics/AbcSize
|
|
34
|
+
absolute_path = File.expand_path(path, pwd)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
step(:preload, loaded_paths:)
|
|
37
|
-
step(:evaluate, loaded_paths:)
|
|
36
|
+
return Dirload.file_load(file_path: absolute_path) unless File.directory?(absolute_path)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
loaded_paths = {}
|
|
39
|
+
missed_paths = []
|
|
40
|
+
file_types = {}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Dirload.file_paths(absolute_path:).each do |file_path|
|
|
43
|
+
if (adapter = Dirload.find_adapter(file_path:))
|
|
44
|
+
loaded_paths[file_path] = adapter
|
|
45
|
+
else
|
|
46
|
+
missed_paths << adapter
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
file_types[Dirload.extension(file_path:)] ||= []
|
|
50
|
+
file_types[Dirload.extension(file_path:)] << file_path
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Dirload.step(:mapload, loaded_paths:)
|
|
54
|
+
Dirload.step(:preload, loaded_paths:)
|
|
55
|
+
Dirload.step(:evaluate, loaded_paths:)
|
|
56
|
+
|
|
57
|
+
Metadata.new(loaded_paths:, missed_paths:, file_types:)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
43
60
|
|
|
44
61
|
def file_paths(absolute_path:)
|
|
45
62
|
Dir["#{absolute_path}/**/*"].filter { !File.directory?(it) }
|
|
46
63
|
end
|
|
47
64
|
|
|
48
|
-
def
|
|
65
|
+
def file_load(file_path:)
|
|
49
66
|
adapter = find_adapter(file_path:)
|
|
50
67
|
|
|
51
68
|
raise(UnsupportedFileType, "Could not load #{file_path}") if adapter.nil?
|
|
@@ -68,4 +85,4 @@ module Dirload
|
|
|
68
85
|
end
|
|
69
86
|
end
|
|
70
87
|
|
|
71
|
-
Kernel.send(:include, Dirload)
|
|
88
|
+
Kernel.send(:include, Dirload::KernelMethods)
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dirload
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-10-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: lowkey
|
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
58
58
|
- !ruby/object:Gem::Version
|
|
59
59
|
version: '0'
|
|
60
60
|
requirements: []
|
|
61
|
-
rubygems_version:
|
|
61
|
+
rubygems_version: 3.6.2
|
|
62
62
|
specification_version: 4
|
|
63
63
|
summary: An autoloader without namespace and folder structure conventions
|
|
64
64
|
test_files: []
|