erb-formatter 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddc79db481ece2c7a1a3c3dedbce6f65f176ad045805125cbd997fdaf5f4fb11
4
- data.tar.gz: e27fe52c37feb8fe80386af2fb0083a5b6398a9319189ec0baec5251db4a1a31
3
+ metadata.gz: a957537254444c222e81398e138e7d3bd22512b782cd3a67302ad9b1de8c12bc
4
+ data.tar.gz: 23eee273e38701317b779ec455353fa801212b80b78c786d5a01b61fc54942c0
5
5
  SHA512:
6
- metadata.gz: 3e08e5783a5315111f5bbe0acc0f8d819b7e8b80f0a6626ec6283006441005dcba10526282ea6d331b54e7e6fc56c8a24cecb93c235f11b2394448195cf2f264
7
- data.tar.gz: 5ca38f5fd851e57056a87490d5f668a0fa2a9374e6ff46cf0efe7b6cb39af0dc813e0026cee9bf7fc57f99a86833c5385979e1b0bd8c2d03a7d83f969daf494f
6
+ metadata.gz: 05176b2dca77e2500ed5d00ce531e395cf4a11a35d38132fb7539f516d98e007480a32b690f53715a6ca79f967aa773d9698856464e24145e329c8389adad54c
7
+ data.tar.gz: 2d088aa641242b2a30b8d4a21abe739cf365838950ea9c8aa9d39b395aaf3bda966f3159ee66bb03ad486e337fd6536694b064bdd834d7d138eb59518db44cfe
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency "syntax_tree", '~> 5.0'
31
+ spec.add_dependency "syntax_tree", '~> 6.0'
32
32
  end
@@ -3,5 +3,5 @@
3
3
  require 'erb'
4
4
 
5
5
  class ERB::Formatter
6
- VERSION = "0.4.2"
6
+ VERSION = "0.4.3"
7
7
  end
data/lib/erb/formatter.rb CHANGED
@@ -38,8 +38,6 @@ class ERB::Formatter
38
38
 
39
39
  ERB_TAG = %r{(<%(?:==|=|-|))\s*(.*?)\s*(-?%>)}m
40
40
  ERB_PLACEHOLDER = %r{erb[a-z0-9]+tag}
41
- ERB_END = %r{(<%-?)\s*(end)\s*(-?%>)}
42
- ERB_ELSE = %r{(<%-?)\s*(else|elsif\b.*)\s*(-?%>)}
43
41
 
44
42
  TAG_NAME = /[a-z0-9_:-]+/
45
43
  TAG_NAME_ONLY = /\A#{TAG_NAME}\z/
@@ -49,10 +47,12 @@ class ERB::Formatter
49
47
 
50
48
  SELF_CLOSING_TAG = /\A(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)\z/i
51
49
 
52
- ERB_OPEN_BLOCK = ->(code) do
50
+ RUBY_OPEN_BLOCK = ->(code) do
53
51
  # is nil when the parsing is broken, meaning it's an open expression
54
52
  Ripper.sexp(code).nil?
55
53
  end.freeze
54
+ RUBY_CLOSE_BLOCK = /\Aend\z/
55
+ RUBY_REOPEN_BLOCK = /\A(else|elsif\b(.*)|when\b(.*))\z/
56
56
 
57
57
  RUBOCOP_STDIN_MARKER = "===================="
58
58
 
@@ -146,45 +146,6 @@ class ERB::Formatter
146
146
  attr_html
147
147
  end
148
148
 
149
- def format_erb_attributes(string)
150
- erb_scanner = StringScanner.new(string.to_s)
151
- erb_pre_pos = 0
152
- until erb_scanner.eos?
153
- if erb_scanner.scan_until(erb_tags_regexp)
154
- erb_pre_match = erb_scanner.pre_match
155
- erb_pre_match = erb_pre_match[erb_pre_pos..]
156
- erb_pre_pos = erb_scanner.pos
157
-
158
- erb_code = erb_tags[erb_scanner.captures.first]
159
-
160
- format_attributes(erb_pre_match)
161
-
162
- erb_open, ruby_code, erb_close = ERB_TAG.match(erb_code).captures
163
- full_erb_tag = "#{erb_open} #{ruby_code} #{erb_close}"
164
-
165
- case ruby_code
166
- when /\Aend\z/
167
- tag_stack_pop('%erb%', ruby_code)
168
- html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
169
- when /\A(else|elsif\b(.*))\z/
170
- tag_stack_pop('%erb%', ruby_code)
171
- html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
172
- tag_stack_push('%erb%', ruby_code)
173
- when ERB_OPEN_BLOCK
174
- html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
175
- tag_stack_push('%erb%', ruby_code)
176
- else
177
- ruby_code = format_ruby(ruby_code, autoclose: false)
178
- html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
179
- end
180
- else
181
- rest = erb_scanner.rest.to_s
182
- format_erb_attributes(rest)
183
- erb_scanner.terminate
184
- end
185
- end
186
- end
187
-
188
149
  def tag_stack_push(tag_name, code)
189
150
  tag_stack << [tag_name, code]
190
151
  p PUSH: tag_stack if @debug
@@ -258,8 +219,8 @@ class ERB::Formatter
258
219
 
259
220
  def format_ruby(code, autoclose: false)
260
221
  if autoclose
261
- code += "\nend" unless ERB_OPEN_BLOCK["#{code}\nend"]
262
- code += "\n}" unless ERB_OPEN_BLOCK["#{code}\n}"]
222
+ code += "\nend" unless RUBY_OPEN_BLOCK["#{code}\nend"]
223
+ code += "\n}" unless RUBY_OPEN_BLOCK["#{code}\n}"]
263
224
  end
264
225
  p RUBY_IN_: code if @debug
265
226
 
@@ -303,16 +264,16 @@ class ERB::Formatter
303
264
  erb_open << ' ' unless ruby_code.start_with?('#')
304
265
 
305
266
  case ruby_code
306
- when /\Aend\z/
267
+ when RUBY_CLOSE_BLOCK
307
268
  full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
308
269
  tag_stack_pop('%erb%', ruby_code)
309
270
  html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
310
- when /\A(else|elsif\b(.*))\z/
271
+ when RUBY_REOPEN_BLOCK
311
272
  full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
312
273
  tag_stack_pop('%erb%', ruby_code)
313
274
  html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
314
275
  tag_stack_push('%erb%', ruby_code)
315
- when ERB_OPEN_BLOCK
276
+ when RUBY_OPEN_BLOCK
316
277
  full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
317
278
  html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
318
279
  tag_stack_push('%erb%', ruby_code)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-03 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '6.0'
27
27
  description:
28
28
  email:
29
29
  - elia@schito.me
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.4.5
71
+ rubygems_version: 3.3.7
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: Format ERB files with speed and precision.