lowload 0.3.0 → 0.4.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/lowload.rb +49 -6
- data/lib/version.rb +1 -1
- metadata +3 -4
- data/lib/maps/dependency_map.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7315b8d32b8990ee21d2678f1c01636ec97ece08a11b65cbe06f79c2994f7a20
|
|
4
|
+
data.tar.gz: 182c287de93df1b0dc4da5fd1bfb31c13dd0410d2030d6babf0f977b37ae1bb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 687c06c911126c216366dd22e7449de109b4ef3dfb65e9a30b593c44dd4152a25ddd644209c6da818af87e14e5597e9f5096705c6ec50673061541b7590429d8
|
|
7
|
+
data.tar.gz: 11d2cb73f9da57fb05b80f18757fae12f56cead641e5cd6d7d580b2f0c8120e967cf21482d0bc6989c9cef6c363ab7a22abf79d3d8438f3d36858986e958005a
|
data/lib/lowload.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'antlers'
|
|
3
4
|
require 'lowkey'
|
|
5
|
+
|
|
4
6
|
require_relative 'loader'
|
|
5
7
|
|
|
6
8
|
def top_level_binding
|
|
@@ -36,21 +38,62 @@ module LowLoad
|
|
|
36
38
|
when 'rb'
|
|
37
39
|
load(file_path)
|
|
38
40
|
when 'rbx'
|
|
39
|
-
load_rbx(
|
|
41
|
+
load_rbx(file_path)
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
private
|
|
44
46
|
|
|
45
|
-
def load_rbx(
|
|
47
|
+
def load_rbx(file_path)
|
|
48
|
+
# 1. "File Load" phase.
|
|
49
|
+
file_proxy = Lowkey[file_path] || Lowkey.load(file_path)
|
|
50
|
+
templates = wrap_render_methods(file_proxy:)
|
|
51
|
+
|
|
52
|
+
# 2. "Class Load" phase.
|
|
53
|
+
# Not a security risk because "eval" is equivalent to "load" or "require_relative" in this context.
|
|
54
|
+
eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
|
|
55
|
+
|
|
56
|
+
# 3. "Runtime" phase (before LowNode instances are rendered).
|
|
57
|
+
# Templates only exist if antlers gem has been required by another gem (such as LowNode) and the template contains antlers syntax.
|
|
58
|
+
templates.each do |namespace, method_template|
|
|
59
|
+
klass = const_get(namespace)
|
|
60
|
+
method, template = method_template
|
|
61
|
+
# TODO: If params contain "**props" or similar then send that so that lownode can replicate it.
|
|
62
|
+
params = method.params.map(&:name)
|
|
63
|
+
|
|
64
|
+
next unless supports_templates?(klass)
|
|
65
|
+
|
|
66
|
+
# TODO: Make template engine configurable.
|
|
67
|
+
klass.load_template(template:, params:, engine: Antlers, namespace:)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def supports_templates?(klass)
|
|
72
|
+
klass.respond_to?(:render) && klass.respond_to?(:template) && klass.respond_to?(:load_template)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def wrap_render_methods(file_proxy:)
|
|
76
|
+
# GOAL: Templates could be organised by method and template rendering engine.
|
|
77
|
+
templates = {}
|
|
78
|
+
|
|
46
79
|
file_proxy.definitions.each_value do |class_proxy|
|
|
47
|
-
|
|
80
|
+
render_method = class_proxy.respond_to?(:instance_methods) ? class_proxy.instance_methods[:render] : nil
|
|
81
|
+
|
|
82
|
+
next unless render_method
|
|
48
83
|
|
|
49
|
-
|
|
84
|
+
render_method_body = render_method.body.export
|
|
85
|
+
|
|
86
|
+
if defined?(Antlers) && ['{', '<{'].any? { |needle| render_method_body.include?(needle) }
|
|
87
|
+
templates[class_proxy.namespace] = [render_method, render_method_body]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Intended to target HTML or Antlers tags. Use HEREDOC "<<~" in a plain Ruby (".rb") file, not RBX.
|
|
91
|
+
if render_method_body.strip.start_with?('<')
|
|
92
|
+
render_method.body.wrap(prefix: '%q{', suffix: '}')
|
|
93
|
+
end
|
|
50
94
|
end
|
|
51
95
|
|
|
52
|
-
|
|
53
|
-
eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
|
|
96
|
+
templates
|
|
54
97
|
end
|
|
55
98
|
end
|
|
56
99
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lowload
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -23,8 +23,8 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
-
description:
|
|
27
|
-
require statements.
|
|
26
|
+
description: An autoloader that lets you use any module namespace convention with
|
|
27
|
+
any folder structure and mix in manual require statements.
|
|
28
28
|
email:
|
|
29
29
|
- maediprichard@gmail.com
|
|
30
30
|
executables: []
|
|
@@ -33,7 +33,6 @@ extra_rdoc_files: []
|
|
|
33
33
|
files:
|
|
34
34
|
- lib/loader.rb
|
|
35
35
|
- lib/lowload.rb
|
|
36
|
-
- lib/maps/dependency_map.rb
|
|
37
36
|
- lib/version.rb
|
|
38
37
|
homepage: https://github.com/low-rb/lowload
|
|
39
38
|
licenses: []
|
data/lib/maps/dependency_map.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module LowLoad
|
|
4
|
-
class FileProxy
|
|
5
|
-
attr_reader :path, :scope
|
|
6
|
-
attr_accessor :start_line, :end_line
|
|
7
|
-
|
|
8
|
-
def initialize(path:, scope:, start_line:, end_line: nil)
|
|
9
|
-
@path = path
|
|
10
|
-
@start_line = start_line
|
|
11
|
-
@end_line = end_line || start_line
|
|
12
|
-
@scope = scope
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def lines?
|
|
16
|
-
start_line && end_line
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|