bade 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Bade.gemspec +1 -0
- data/lib/bade/generator.rb +3 -2
- data/lib/bade/parser.rb +1 -1
- data/lib/bade/ruby_extensions/string.rb +0 -9
- data/lib/bade/runtime/mixin.rb +3 -0
- data/lib/bade/runtime.rb +37 -8
- data/lib/bade/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a90545fdee8d531bb87e12dd7943c0486daf3eac68f1d0c69ba216c7595f452
|
4
|
+
data.tar.gz: cdbf2cbc427cb9dd590768d493f99c91f22ac51a0a3caa172abb0b6c96b81b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88708cad2d3145bfe33fb2ca65acbd795b3f8b3074da64f53e8d053d09925a3f750627893c303c2000fe4e9e8328abf4b9fe60a8e1c925a4ccb8966f37887fff
|
7
|
+
data.tar.gz: 8b21e240977c4f4c0c0387c244dcfb215141e453e04fde9f47762cb59ec22f43ee8056a17c39f41037d52b2a3d2bde8f66ad2b7623d8f8819f9444eebb075741
|
data/Bade.gemspec
CHANGED
data/lib/bade/generator.rb
CHANGED
@@ -41,6 +41,7 @@ module Bade
|
|
41
41
|
code_indent do
|
42
42
|
buff_code "self.#{NEW_LINE_NAME} = #{NEW_LINE_NAME}"
|
43
43
|
buff_code "self.#{BASE_INDENT_NAME} = #{BASE_INDENT_NAME}"
|
44
|
+
buff_code "__buffs_push(#{location(filename: document.file_path, lineno: 0, label: '<top>')})"
|
44
45
|
|
45
46
|
visit_document(document)
|
46
47
|
|
@@ -86,7 +87,6 @@ module Bade
|
|
86
87
|
end
|
87
88
|
|
88
89
|
buff_code("# ----- start file #{document.file_path}") unless document.file_path.nil?
|
89
|
-
buff_code "__buffs_push(#{location(filename: document.file_path, lineno: 0, label: '<top>')})"
|
90
90
|
|
91
91
|
new_root = if @optimize
|
92
92
|
Optimizer.new(document.root).optimize
|
@@ -381,12 +381,13 @@ module Bade
|
|
381
381
|
when :code
|
382
382
|
value = node.value.strip
|
383
383
|
|
384
|
-
%w[end else }].include?(value) || value.match(/^when /)
|
384
|
+
%w[end else }].include?(value) || value.match(/^(when|elsif) /)
|
385
385
|
when :newline
|
386
386
|
true
|
387
387
|
else
|
388
388
|
false
|
389
389
|
end
|
390
|
+
|
390
391
|
return if should_skip
|
391
392
|
return if node.lineno.nil?
|
392
393
|
|
data/lib/bade/parser.rb
CHANGED
@@ -95,13 +95,4 @@ class String
|
|
95
95
|
|
96
96
|
count
|
97
97
|
end
|
98
|
-
|
99
|
-
# source: http://apidock.com/rails/String/strip_heredoc
|
100
|
-
# @return [String]
|
101
|
-
#
|
102
|
-
def strip_heredoc
|
103
|
-
min_val = scan(/^[ \t]*(?=\S)/).min
|
104
|
-
indent = min_val&.size || 0
|
105
|
-
gsub(/^[ \t]{#{indent}}/, '')
|
106
|
-
end
|
107
98
|
end
|
data/lib/bade/runtime/mixin.rb
CHANGED
@@ -49,6 +49,9 @@ module Bade
|
|
49
49
|
|
50
50
|
raise Block::MissingBlockDefinitionError.new(e.name, e.context, msg, render_binding.__location_stack)
|
51
51
|
|
52
|
+
rescue RuntimeError
|
53
|
+
raise
|
54
|
+
|
52
55
|
rescue Exception => e
|
53
56
|
msg = "Exception raised during execution of mixin `#{name}`: #{e}"
|
54
57
|
raise Bade::Runtime::RuntimeError.wrap_existing_error(msg, e, render_binding.__location_stack)
|
data/lib/bade/runtime.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
module Bade
|
4
4
|
module Runtime
|
5
5
|
Location = Struct.new(:path, :lineno, :label, keyword_init: true) do
|
6
|
+
def template?
|
7
|
+
path == TEMPLATE_FILE_NAME || path&.include?('.bade')
|
8
|
+
end
|
9
|
+
|
6
10
|
def to_s
|
7
11
|
"#{path || TEMPLATE_FILE_NAME}:#{lineno}:in `#{label}'"
|
8
12
|
end
|
@@ -13,23 +17,41 @@ module Bade
|
|
13
17
|
#
|
14
18
|
attr_reader :template_backtrace
|
15
19
|
|
20
|
+
# @return [Boolean]
|
21
|
+
#
|
22
|
+
attr_reader :print_locations_warning
|
23
|
+
|
16
24
|
# @param [String] msg
|
17
25
|
# @param [Array<Location>] template_backtrace
|
18
26
|
# @param [Exception, nil] original
|
19
|
-
def initialize(msg, template_backtrace = [], original: nil)
|
27
|
+
def initialize(msg, template_backtrace = [], original: nil, print_locations_warning: false)
|
20
28
|
super(msg)
|
21
29
|
@template_backtrace = template_backtrace
|
22
30
|
@original = original
|
31
|
+
@print_locations_warning = print_locations_warning
|
23
32
|
end
|
24
33
|
|
25
34
|
def message
|
26
35
|
if @template_backtrace.empty?
|
27
36
|
super
|
28
37
|
else
|
38
|
+
warning = if print_locations_warning
|
39
|
+
<<~TEXT
|
40
|
+
|
41
|
+
!!! WARNING !!!, filenames and line numbers of functions can be misleading due to using Ruby
|
42
|
+
functions in different Bade file. Trust only functions names. Mixins are fine.
|
43
|
+
|
44
|
+
This will be fixed in https://github.com/epuber-io/bade/issues/32
|
45
|
+
TEXT
|
46
|
+
else
|
47
|
+
''
|
48
|
+
end
|
49
|
+
|
29
50
|
<<~MSG.rstrip
|
30
51
|
#{super}
|
31
52
|
template backtrace:
|
32
53
|
#{__formatted_backtrace.join("\n")}
|
54
|
+
#{warning}
|
33
55
|
MSG
|
34
56
|
end
|
35
57
|
end
|
@@ -53,14 +75,20 @@ module Bade
|
|
53
75
|
def self.process_locations(locations)
|
54
76
|
return [] if locations.nil?
|
55
77
|
|
56
|
-
|
78
|
+
# map to Bade's Location
|
79
|
+
new_locations = locations.map { |loc| Location.new(path: loc.path, lineno: loc.lineno, label: loc.label) }
|
80
|
+
|
81
|
+
# find location to use or drop
|
82
|
+
index = new_locations.rindex(&:template?)
|
57
83
|
return [] if index.nil?
|
58
84
|
|
59
|
-
|
85
|
+
# get only locations inside template
|
86
|
+
new_locations = new_locations[0...index] || []
|
60
87
|
|
61
|
-
|
62
|
-
|
63
|
-
|
88
|
+
# filter out not interested locations
|
89
|
+
new_locations
|
90
|
+
.reject { |loc| loc.path.start_with?(__dir__) }
|
91
|
+
.reject { |loc| loc.template? && loc.label.include?('lambda_instance') }
|
64
92
|
end
|
65
93
|
|
66
94
|
# @param [String] msg
|
@@ -68,8 +96,9 @@ module Bade
|
|
68
96
|
# @param [Array<Location>] template_backtrace
|
69
97
|
# @return [RuntimeError]
|
70
98
|
def self.wrap_existing_error(msg, error, template_backtrace)
|
71
|
-
|
72
|
-
|
99
|
+
ruby_locs = Bade::Runtime::RuntimeError.process_locations(error.backtrace_locations)
|
100
|
+
locs = ruby_locs + template_backtrace
|
101
|
+
Bade::Runtime::RuntimeError.new(msg, locs, original: error, print_locations_warning: !ruby_locs.empty?)
|
73
102
|
end
|
74
103
|
end
|
75
104
|
|
data/lib/bade/version.rb
CHANGED
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kříž
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2022-03-22 00:00:00.000000000 Z
|
@@ -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
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubygems_version: 3.3.9
|
138
|
-
signing_key:
|
138
|
+
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Minimalistic template engine for Ruby.
|
141
141
|
test_files: []
|