lowload 0.3.0 → 0.4.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: 9c841ed28307b4d9211362f9e30c4d73d0cf662ce537d2f448a36e030dc3c55e
4
- data.tar.gz: 69e0f32e92d565083b51d2758d8f8acd3b28ea334b32e2143a9614a50f6c4f2d
3
+ metadata.gz: e5859ef089b8753d4130fdfe76cb5c4bae07552b6427b37a87640aacf5a2e82b
4
+ data.tar.gz: d3563b940afe0ad16aef2e240ef2b3f7ccb23fc8bcc8e84a454d458143adf187
5
5
  SHA512:
6
- metadata.gz: 82a9791ac47f662317e94bdbda71c036efe6d5c13896a8a20a712fba57bca88b1461cf2318f56fc7a205ed2bbfb29331398a22c434406d2a2bad76a298a3c101
7
- data.tar.gz: 8306cba1fd04398aa6ed5d83f56a389aa643e091679a71d034ef981c3699f9d10f1e7895dc8e88a2cfbddd67be6005f6c6019197584c9bd9e59bce84f1ce5465
6
+ metadata.gz: d83e401b090280a05aeb14dbff38065b57a3a83aafc35683983570e2071425444511a65f0caf20460d7826b41370479d66cde9b791062c55161096330bd2fb53
7
+ data.tar.gz: 397229cdae86c64b0d655d8aaee5a52f2f3978d2bc09fa356554dc68e13442ce01e4c9afccfbc80488aa4f781ce284d3a3009cae084cafd40b305b1ab9013797
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(file_proxy: Lowkey[file_path] || Lowkey.load(file_path))
41
+ load_rbx(file_path)
40
42
  end
41
43
  end
42
44
 
43
45
  private
44
46
 
45
- def load_rbx(file_proxy:)
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
- next unless class_proxy[:render]
80
+ render_method = class_proxy.respond_to?(:instance_methods) ? class_proxy.instance_methods[:render] : nil
81
+
82
+ next unless render_method
48
83
 
49
- class_proxy[:render].body.wrap(prefix: '%q{', suffix: '}')
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
- # Not a security risk because "eval" is equivalent to "load" or "require_relative" in this context.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowLoad
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
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.3.0
4
+ version: 0.4.1
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: LowLoad lets you use any module namespace convention and mix in manual
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: []
@@ -54,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
53
  - !ruby/object:Gem::Version
55
54
  version: '0'
56
55
  requirements: []
57
- rubygems_version: 3.7.2
56
+ rubygems_version: 4.0.6
58
57
  specification_version: 4
59
58
  summary: An autoloader that is dumb but lets you do you
60
59
  test_files: []
@@ -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