template-ruby 0.2.1 → 0.2.2

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: fc096165f8db9f20877bbd67a8d326ecdcaa546bcf9fda19479a267d9e559504
4
- data.tar.gz: ae616ed093aded9378204f0231c2b4be787c3d62d0f9859d8971ea01c4fc8a8f
3
+ metadata.gz: 5e240c31089e37775df02ba1ea0646922413b26860318456d19ed5d2b38ed077
4
+ data.tar.gz: 25f45bb4ef78e1f62e63a960ce3fa46245b60dfab8fd96a273caf823ee2b016f
5
5
  SHA512:
6
- metadata.gz: 317b2f1d710abef57552f540fe756fcd7d8761d485d93332f091672b354cc9339d6f3ce1d2da009807ef0093944fa1ed41b4f4cdce3e666730d1632b88d056dc
7
- data.tar.gz: ffa81e7c9700f6dd30a9d09f18cfc17769446770364ab8dddfdcc8f90fd4ffd9caf35d5c0402106d45af3e9531a0d487a8d9b35a62f3c0f5abf26f290c24df7b
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.1.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.2)
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.2.1)
45
+ syntax_tree (3.5.0)
46
46
  prettier_print
47
- syntax_tree-haml (1.3.0)
47
+ syntax_tree-haml (1.3.1)
48
48
  haml (>= 5.2)
49
49
  prettier_print
50
50
  syntax_tree (>= 2.0.1)
@@ -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 = call.fetch(:right).map do |right|
12
- ::Code::Node::ChainedCall.new(right)
13
- end
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)
@@ -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
 
@@ -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
- .call(
59
- arguments: [::Code::Object::Argument.new(element)],
60
- context: context,
61
- io: io,
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
- .call(
75
- arguments: [::Code::Object::Argument.new(element)],
76
- context: context,
77
- io: io,
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
- list << element while (element = element + argument) < @right
130
+ while (element = element + argument) < @right
131
+ list << element
132
+ end
135
133
  else
136
- list << element while (element = element + argument) <= @right
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
- if other.respond_to?(:raw)
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
- if other.respond_to?(:raw)
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
@@ -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) | whitespace?.ignore
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 >> (right_curly_bracket.ignore | any.absent?)
18
+ left_curly_bracket.ignore >> code >>
19
+ (right_curly_bracket.ignore | any.absent?)
19
20
  end
20
21
 
21
- rule(:template) { (text_part.as(:text) | code_part.as(:code)).repeat(1) }
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
@@ -1,5 +1,5 @@
1
1
  class Template
2
- VERSION = Gem::Version.new("0.2.1")
2
+ VERSION = Gem::Version.new("0.2.2")
3
3
 
4
4
  def initialize(input, io: StringIO.new)
5
5
  @input = input
@@ -21,9 +21,7 @@ RSpec.describe Code::Parser::Call do
21
21
  },
22
22
  },
23
23
  },
24
- right: [{
25
- name: "times",
26
- }],
24
+ right: [{ name: "times" }],
27
25
  },
28
26
  },
29
27
  ],
@@ -12,9 +12,8 @@ RSpec.describe Template do
12
12
  '{ user: { first_name: "Dorian" } }',
13
13
  "Hello Dorian",
14
14
  ],
15
- [<<~TEMPLATE, "", "Hello "]
16
- Hello {
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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié