bade 0.3.5 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bade/generator.rb +26 -5
- data/lib/bade/runtime/globals_tracker.rb +1 -0
- data/lib/bade/runtime/render_binding.rb +5 -1
- data/lib/bade/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a481b2a1a19745d8660df10476ca85cfa6687a47115cf7f964d40c63dd36327e
|
4
|
+
data.tar.gz: 5996a6dd699189cc5059619558524a65c892a751ffbedeb3fd09cdf41e7d8b18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0675d10d28933ee600d2530a3ae863cdfe53bae8632c6eb92e59e49a37fddc7eb3a6b62b6f492d88734597e988c0361d5f0b1f4b68d069e7e55789d061d55ed2
|
7
|
+
data.tar.gz: 149cb3709994965d70e3552b7f548b0c04d39610176379ed09b8ff21d6c2444d26546fceca0976c813cb86f997c174343cb418a480697551058b20dd7c1b2ede
|
data/lib/bade/generator.rb
CHANGED
@@ -14,6 +14,8 @@ module Bade
|
|
14
14
|
|
15
15
|
DEFAULT_BLOCK_NAME = 'default_block'.freeze
|
16
16
|
|
17
|
+
REQUIRE_RELATIVE_REGEX = /require_relative\s+['"](.+)['"]/
|
18
|
+
|
17
19
|
# @param [Document] document
|
18
20
|
#
|
19
21
|
# @return [String]
|
@@ -28,7 +30,7 @@ module Bade
|
|
28
30
|
# @return [String] string to parse with Ruby
|
29
31
|
#
|
30
32
|
def generate_lambda_string(document, optimize: false)
|
31
|
-
@
|
33
|
+
@documents = []
|
32
34
|
@buff = []
|
33
35
|
@indent = 0
|
34
36
|
@code_indent = 0
|
@@ -52,9 +54,6 @@ module Bade
|
|
52
54
|
|
53
55
|
buff_code 'end'
|
54
56
|
|
55
|
-
|
56
|
-
@document = nil
|
57
|
-
|
58
57
|
@buff.join("\n")
|
59
58
|
end
|
60
59
|
|
@@ -76,12 +75,16 @@ module Bade
|
|
76
75
|
end
|
77
76
|
|
78
77
|
def buff_code(text)
|
78
|
+
text = _fix_required_relative(text)
|
79
|
+
|
79
80
|
@buff << "#{' ' * @code_indent}#{text}"
|
80
81
|
end
|
81
82
|
|
82
83
|
# @param document [Bade::Document]
|
83
84
|
#
|
84
85
|
def visit_document(document)
|
86
|
+
@documents.append(document)
|
87
|
+
|
85
88
|
document.sub_documents.each do |sub_document|
|
86
89
|
visit_document(sub_document)
|
87
90
|
end
|
@@ -97,6 +100,8 @@ module Bade
|
|
97
100
|
visit_node(new_root)
|
98
101
|
|
99
102
|
buff_code("# ----- end file #{document.file_path}") unless document.file_path.nil?
|
103
|
+
|
104
|
+
@documents.pop
|
100
105
|
end
|
101
106
|
|
102
107
|
# @param current_node [Node]
|
@@ -162,7 +167,7 @@ module Bade
|
|
162
167
|
when :newline
|
163
168
|
# no-op
|
164
169
|
when :import
|
165
|
-
base_path = File.expand_path(current_node.value, File.dirname(@
|
170
|
+
base_path = File.expand_path(current_node.value, File.dirname(@documents.last.file_path))
|
166
171
|
load_path = if base_path.end_with?('.rb') && File.exist?(base_path)
|
167
172
|
base_path
|
168
173
|
elsif File.exist?("#{base_path}.rb")
|
@@ -422,6 +427,22 @@ module Bade
|
|
422
427
|
|
423
428
|
location(filename: node.filename, lineno: node.lineno, label: label)
|
424
429
|
end
|
430
|
+
|
431
|
+
# Fix require_relative paths to be relative to the main Bade file (instead of the current file)
|
432
|
+
#
|
433
|
+
# @param [String] text
|
434
|
+
# @return [String]
|
435
|
+
#
|
436
|
+
def _fix_required_relative(text)
|
437
|
+
text.gsub(REQUIRE_RELATIVE_REGEX) do
|
438
|
+
relative_path = Regexp.last_match[1]
|
439
|
+
abs_path = File.expand_path(relative_path, File.dirname(@documents.last.file_path))
|
440
|
+
document_abs_path = Pathname.new(File.expand_path(File.dirname(@documents.first.file_path)))
|
441
|
+
new_relative_path = Pathname.new(abs_path).relative_path_from(document_abs_path).to_s
|
442
|
+
|
443
|
+
"require_relative '#{new_relative_path}'"
|
444
|
+
end
|
445
|
+
end
|
425
446
|
end
|
426
447
|
|
427
448
|
# backward compatibility
|
@@ -99,7 +99,11 @@ module Bade
|
|
99
99
|
eval(File.read(filename), __get_binding, filename)
|
100
100
|
# rubocop:enable Security/Eval
|
101
101
|
else
|
102
|
-
|
102
|
+
context_path = caller_locations(1, 1).first.path
|
103
|
+
|
104
|
+
abs_path = File.expand_path(filename, File.dirname(context_path))
|
105
|
+
|
106
|
+
Kernel.require(abs_path)
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
data/lib/bade/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kříž
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: psych
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.14'
|
75
|
-
description:
|
75
|
+
description:
|
76
76
|
email:
|
77
77
|
- samnung@gmail.com
|
78
78
|
executables: []
|
@@ -119,7 +119,7 @@ licenses:
|
|
119
119
|
- MIT
|
120
120
|
metadata:
|
121
121
|
rubygems_mfa_required: 'true'
|
122
|
-
post_install_message:
|
122
|
+
post_install_message:
|
123
123
|
rdoc_options: []
|
124
124
|
require_paths:
|
125
125
|
- lib
|
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
137
|
+
rubygems_version: 3.4.20
|
138
|
+
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Minimalistic template engine for Ruby.
|
141
141
|
test_files: []
|