template-ruby 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -2
- data/Gemfile.lock +4 -4
- data/lib/code/node/call.rb +4 -3
- data/lib/code/object/list.rb +4 -4
- data/lib/code/object/range.rb +18 -18
- data/lib/code/object.rb +2 -10
- data/lib/code/parser/code.rb +2 -1
- data/lib/template/parser/template.rb +6 -2
- data/lib/template.rb +1 -1
- data/spec/code/parser/call_spec.rb +1 -3
- data/spec/template_spec.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e240c31089e37775df02ba1ea0646922413b26860318456d19ed5d2b38ed077
|
4
|
+
data.tar.gz: 25f45bb4ef78e1f62e63a960ce3fa46245b60dfab8fd96a273caf823ee2b016f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2870be4d39f138c269946c935985d2de54c4364307630011b8de8095d50dd7a72de3a71f401414c64e416832c2d4f6e9a8e92d7e6038855725e35c7e0cbbdd9
|
7
|
+
data.tar.gz: 77fd004c7464e2715726dfec039925e8c4653d6a78993cf6d1c6cecb717f08fcb5e04f9cebf7acf130bb3ed7fcac7891e65ef8fe0db37ab9c66724ef9b2cd923
|
data/CHANGELOG.md
CHANGED
@@ -5,9 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## 0.2.2 / 2022-08-31
|
9
|
+
|
10
|
+
- Fix parsing error when the template is empty, e.g. ""
|
11
|
+
|
8
12
|
## 0.2.1 / 2022-08-31
|
9
13
|
|
10
|
-
- Fix error on empty code like `Hello {`
|
14
|
+
- Fix parsing error on empty code like `Hello {`
|
11
15
|
|
12
16
|
## 0.2.0 / 2022-08-30
|
13
17
|
|
@@ -16,4 +20,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
16
20
|
## 0.1.0 / 2022-07-28
|
17
21
|
|
18
22
|
- Initial version with interpolation
|
19
|
-
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
template-ruby (0.
|
4
|
+
template-ruby (0.2.2)
|
5
5
|
activesupport (~> 7)
|
6
6
|
parslet (~> 2)
|
7
7
|
zeitwerk (~> 2.6)
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
tilt
|
22
22
|
i18n (1.12.0)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
minitest (5.16.
|
24
|
+
minitest (5.16.3)
|
25
25
|
parslet (2.0.0)
|
26
26
|
prettier (3.2.0)
|
27
27
|
syntax_tree (>= 2.7.1)
|
@@ -42,9 +42,9 @@ GEM
|
|
42
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
43
|
rspec-support (~> 3.11.0)
|
44
44
|
rspec-support (3.11.0)
|
45
|
-
syntax_tree (3.
|
45
|
+
syntax_tree (3.5.0)
|
46
46
|
prettier_print
|
47
|
-
syntax_tree-haml (1.3.
|
47
|
+
syntax_tree-haml (1.3.1)
|
48
48
|
haml (>= 5.2)
|
49
49
|
prettier_print
|
50
50
|
syntax_tree (>= 2.0.1)
|
data/lib/code/node/call.rb
CHANGED
@@ -8,9 +8,10 @@ class Code
|
|
8
8
|
@arguments.map! { |argument| ::Code::Node::CallArgument.new(argument) }
|
9
9
|
|
10
10
|
if call.key?(:right)
|
11
|
-
@right =
|
12
|
-
|
13
|
-
|
11
|
+
@right =
|
12
|
+
call
|
13
|
+
.fetch(:right)
|
14
|
+
.map { |right| ::Code::Node::ChainedCall.new(right) }
|
14
15
|
end
|
15
16
|
|
16
17
|
if call.key?(:block)
|
data/lib/code/object/list.rb
CHANGED
@@ -59,7 +59,7 @@ class Code
|
|
59
59
|
else
|
60
60
|
acc + [element]
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end,
|
63
63
|
)
|
64
64
|
end
|
65
65
|
|
@@ -138,7 +138,7 @@ class Code
|
|
138
138
|
argument.call(
|
139
139
|
arguments: [
|
140
140
|
::Code::Object::Argument.new(acc),
|
141
|
-
::Code::Object::Argument.new(element)
|
141
|
+
::Code::Object::Argument.new(element),
|
142
142
|
],
|
143
143
|
context: context,
|
144
144
|
io: io,
|
@@ -169,7 +169,7 @@ class Code
|
|
169
169
|
context: context,
|
170
170
|
io: io,
|
171
171
|
).truthy?
|
172
|
-
end
|
172
|
+
end,
|
173
173
|
)
|
174
174
|
end
|
175
175
|
|
@@ -183,7 +183,7 @@ class Code
|
|
183
183
|
context: context,
|
184
184
|
io: io,
|
185
185
|
)
|
186
|
-
end
|
186
|
+
end,
|
187
187
|
)
|
188
188
|
end
|
189
189
|
|
data/lib/code/object/range.rb
CHANGED
@@ -54,13 +54,11 @@ class Code
|
|
54
54
|
argument = arguments.first.value
|
55
55
|
::Code::Object::Boolean.new(
|
56
56
|
raw.any? do |element|
|
57
|
-
argument
|
58
|
-
.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
)
|
63
|
-
.truthy?
|
57
|
+
argument.call(
|
58
|
+
arguments: [::Code::Object::Argument.new(element)],
|
59
|
+
context: context,
|
60
|
+
io: io,
|
61
|
+
).truthy?
|
64
62
|
end,
|
65
63
|
)
|
66
64
|
end
|
@@ -70,13 +68,11 @@ class Code
|
|
70
68
|
argument = arguments.first.value
|
71
69
|
::Code::Object::Boolean.new(
|
72
70
|
raw.all? do |element|
|
73
|
-
argument
|
74
|
-
.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
)
|
79
|
-
.truthy?
|
71
|
+
argument.call(
|
72
|
+
arguments: [::Code::Object::Argument.new(element)],
|
73
|
+
context: context,
|
74
|
+
io: io,
|
75
|
+
).truthy?
|
80
76
|
end,
|
81
77
|
)
|
82
78
|
end
|
@@ -104,7 +100,7 @@ class Code
|
|
104
100
|
context: context,
|
105
101
|
io: io,
|
106
102
|
).truthy?
|
107
|
-
end
|
103
|
+
end,
|
108
104
|
)
|
109
105
|
end
|
110
106
|
|
@@ -118,7 +114,7 @@ class Code
|
|
118
114
|
context: context,
|
119
115
|
io: io,
|
120
116
|
)
|
121
|
-
end
|
117
|
+
end,
|
122
118
|
)
|
123
119
|
end
|
124
120
|
|
@@ -131,9 +127,13 @@ class Code
|
|
131
127
|
list << element
|
132
128
|
|
133
129
|
if @exlucde_end
|
134
|
-
|
130
|
+
while (element = element + argument) < @right
|
131
|
+
list << element
|
132
|
+
end
|
135
133
|
else
|
136
|
-
|
134
|
+
while (element = element + argument) <= @right
|
135
|
+
list << element
|
136
|
+
end
|
137
137
|
end
|
138
138
|
|
139
139
|
list
|
data/lib/code/object.rb
CHANGED
@@ -45,11 +45,7 @@ class Code
|
|
45
45
|
|
46
46
|
def <=>(other)
|
47
47
|
if respond_to?(:raw)
|
48
|
-
|
49
|
-
raw <=> other.raw
|
50
|
-
else
|
51
|
-
raw <=> other
|
52
|
-
end
|
48
|
+
other.respond_to?(:raw) ? raw <=> other.raw : raw <=> other
|
53
49
|
else
|
54
50
|
other <=> self
|
55
51
|
end
|
@@ -57,11 +53,7 @@ class Code
|
|
57
53
|
|
58
54
|
def ==(other)
|
59
55
|
if respond_to?(:raw)
|
60
|
-
|
61
|
-
raw == other.raw
|
62
|
-
else
|
63
|
-
raw == other
|
64
|
-
end
|
56
|
+
other.respond_to?(:raw) ? raw == other.raw : raw == other
|
65
57
|
else
|
66
58
|
other == self
|
67
59
|
end
|
data/lib/code/parser/code.rb
CHANGED
@@ -9,7 +9,8 @@ class Code
|
|
9
9
|
rule(:whitespace?) { whitespace.maybe }
|
10
10
|
|
11
11
|
rule(:code) do
|
12
|
-
(whitespace?.ignore >> statement >> whitespace?.ignore).repeat(1) |
|
12
|
+
(whitespace?.ignore >> statement >> whitespace?.ignore).repeat(1) |
|
13
|
+
whitespace?.ignore
|
13
14
|
end
|
14
15
|
|
15
16
|
root(:code)
|
@@ -15,10 +15,14 @@ class Template
|
|
15
15
|
end
|
16
16
|
|
17
17
|
rule(:code_part) do
|
18
|
-
left_curly_bracket.ignore >> code >>
|
18
|
+
left_curly_bracket.ignore >> code >>
|
19
|
+
(right_curly_bracket.ignore | any.absent?)
|
19
20
|
end
|
20
21
|
|
21
|
-
rule(:template)
|
22
|
+
rule(:template) do
|
23
|
+
(text_part.as(:text) | code_part.as(:code)).repeat(1) |
|
24
|
+
str("").as(:text).repeat(1, 1)
|
25
|
+
end
|
22
26
|
|
23
27
|
root(:template)
|
24
28
|
end
|
data/lib/template.rb
CHANGED
data/spec/template_spec.rb
CHANGED
@@ -12,9 +12,8 @@ RSpec.describe Template do
|
|
12
12
|
'{ user: { first_name: "Dorian" } }',
|
13
13
|
"Hello Dorian",
|
14
14
|
],
|
15
|
-
[
|
16
|
-
|
17
|
-
TEMPLATE
|
15
|
+
["Hello {", "", "Hello "],
|
16
|
+
["", "", ""],
|
18
17
|
].each do |(input, input_context, expected)|
|
19
18
|
context "#{input.inspect} #{input_context.inspect}" do
|
20
19
|
let(:input) { input }
|