dirload 0.7.1 → 0.7.3

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: 8a30d8a79c221d8fda4edf9cad844a97240456d0c8e9137ae6c12afdbab1d5aa
4
- data.tar.gz: 3c6938f80e498d7293822fdb832a32f16af0eefc90570c51e25decbdcfc01930
3
+ metadata.gz: ec0a5fb0f9791f9c86bd426942bd8b97fd37c4dde99ddea3a2988bf7700cdbf4
4
+ data.tar.gz: d7dd2153288bbab8c9eba9212830f0c6d8035e654089526747871e52628a0636
5
5
  SHA512:
6
- metadata.gz: '081c03cca43649d143bb0181b975e8eda9bfb904bf161684398cf56b0bf07f29d7610d31c5ba9001ee489c98fea5af289c2f88a593869c1e13b4dd4960978cef'
7
- data.tar.gz: 2e0eeb3f8e38995ca8ef1f484a822ca216dc0a59860730a31a0605f0cd95136fd70183a73174fe76a95904a0b1786e2190faf67fbbc56f56efab226282e05d47
6
+ metadata.gz: bd29235c6e86da989b986489d31187af619c45b5bb93b6b19d2c1c2a46ba246cdbf57cba83fd7afa92ba80ed0e10ad83c247ded9383c5f72819dd89dcf1c3768
7
+ data.tar.gz: f754e46247f236b8571bf286590776d53cc244aa4d38ee8d08c0cf0790b64caffc541147d57bbdffda5ee77e3b1b30606bca4c1ffeba31662d11e302304bd108
@@ -22,13 +22,14 @@ module Dirload
22
22
 
23
23
  def evaluate(file_path:)
24
24
  # 1. "File Load" phase.
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)
27
- templates = wrap_render_methods(file_proxy:)
25
+ # Wraps a copy of the file's lines so the file proxy mapload cached stays as the file is.
26
+ file_proxy = Lowkey[file_path] || Lowkey.load(file_path)
27
+ lines = file_proxy.lines.dup
28
+ templates = wrap_render_methods(file_proxy:, lines:)
28
29
 
29
30
  # 2. "Class Load" phase.
30
31
  # Not a security risk because "eval" is equivalent to "load" or "require_relative" in this context.
31
- eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
32
+ eval(lines.join, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval
32
33
 
33
34
  # 3. "Runtime" phase (before low nodes are rendered).
34
35
  # Templates only exist when there's a template engine and the template contains template syntax.
@@ -50,7 +51,7 @@ module Dirload
50
51
  klass.respond_to?(:render) && klass.respond_to?(:template) && klass.respond_to?(:build_template)
51
52
  end
52
53
 
53
- def wrap_render_methods(file_proxy:)
54
+ def wrap_render_methods(file_proxy:, lines:)
54
55
  # GOAL: Templates could be organised by method and template rendering engine.
55
56
  templates = {}
56
57
 
@@ -66,10 +67,15 @@ module Dirload
66
67
  end
67
68
 
68
69
  # Intended to target HTML or Antlers tags. Use HEREDOC "<<~" in a plain Ruby (".rb") file, not RBX.
69
- render_method.body.wrap(prefix: '%q{', suffix: '}') if render_method_body.strip.start_with?('<')
70
+ wrap_lines(lines:, body: render_method.body) if render_method_body.strip.start_with?('<')
70
71
  end
71
72
 
72
73
  templates
73
74
  end
75
+
76
+ def wrap_lines(lines:, body:)
77
+ lines[body.start_index] = lines[body.start_index].sub(/\A(\s*)/, '\\1%q{')
78
+ lines[body.end_index] += '}'
79
+ end
74
80
  end
75
81
  end
@@ -17,7 +17,7 @@ module Dirload
17
17
  end
18
18
 
19
19
  def evaluate(file_path:)
20
- load(file_path)
20
+ require(file_path)
21
21
  end
22
22
  end
23
23
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dirload
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi
@@ -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: 4.0.6
61
+ rubygems_version: 4.0.20
62
62
  specification_version: 4
63
63
  summary: An autoloader without namespace and folder structure conventions
64
64
  test_files: []