synvert-core 1.24.0 → 1.25.0

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: b80b28538674cde89c7dc0098b53d736abb355874d4736654b48234c38c76e2b
4
- data.tar.gz: 463e9b2616f07146ce551e904912dc2cbfb71e010ffa11eda8ff134c0ea1a5b3
3
+ metadata.gz: 69a5a31926536922320b7184cae70096bba437729c6c4dbe6c0bb2ab98d56e43
4
+ data.tar.gz: afeed86dae83348eccb85859dcc907250ff1e5361d69b7a71839cb88c1fc3e79
5
5
  SHA512:
6
- metadata.gz: 2f25773c6887fe6b676dc1abd92df89b82dddab81e26841d3e1b566b1ab4f84666f7fde4563e864508814b49f7a54313014a88e412946b908e58976641a1223f
7
- data.tar.gz: 13cadd41c39b742837a0b562626b1de9355e63f52f953133139f60c47f6341001f2442bca9276078bfdadea909ef5068db688444ed8e55ceaf9fc2511e7321d4
6
+ metadata.gz: 50d06d1c664c06fac3e7bc163226c3e98305bd26d802919ce73003ad4e8d5e1cf441d2559b32aeada9266d48cb7d3365ef2d39fa37a934bd2e0fe2ad489693ee
7
+ data.tar.gz: 34915fcbb4252d66c9b25318b96e1f4bf6f4a8881f8d85229bc7f6f5cbf80ff50aed3f774cddcbab10495ef865daff0c6d40fd6608382e9e97d7a42b16ca6fc3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.25.0 (2023-04-17)
4
+
5
+ * Update `wrap` dsl
6
+ * Update `node_mutation` to 1.15.1
7
+ * Fix `erb` encoded source
8
+
3
9
  ## 1.24.0 (2023-04-16)
4
10
 
5
11
  * Add `Slim` engine
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.24.0)
4
+ synvert-core (1.25.0)
5
5
  activesupport (< 7.0.0)
6
- node_mutation (>= 1.14.0)
6
+ node_mutation (>= 1.15.1)
7
7
  node_query (>= 1.12.1)
8
8
  parallel
9
9
  parser
@@ -48,7 +48,7 @@ GEM
48
48
  method_source (1.0.0)
49
49
  minitest (5.18.0)
50
50
  nenv (0.3.0)
51
- node_mutation (1.14.0)
51
+ node_mutation (1.15.1)
52
52
  node_query (1.12.1)
53
53
  notiffany (0.1.3)
54
54
  nenv (~> 0.1)
data/README.md CHANGED
@@ -94,7 +94,7 @@ Actions:
94
94
  * [replace](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
95
95
  * [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code in specified child nodes
96
96
  * [remove](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#remove-instance_method) - remove the whole code of current node
97
- * [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
97
+ * [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with prefix and suffix code
98
98
  * [replace_with](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
99
99
  * [warn](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
100
100
  * [replace_erb_stmt_with_expr](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
@@ -94,14 +94,14 @@ module Synvert::Core
94
94
  new_code << END_LINE
95
95
  end
96
96
  while scanner.scan(/(.*?)(\\*)#\{/) # it matches interpolation " #{current_user.login}"
97
- new_code << WHITESPACE * scanner.matched.size
97
+ new_code << (WHITESPACE * scanner.matched.size)
98
98
  unless scanner.matched[-3] == '\\'
99
99
  count = 1
100
100
  while scanner.scan(/.*?([\{\}])/)
101
101
  if scanner.matched[-1] == '}'
102
102
  count -= 1
103
103
  if count == 0
104
- new_code << scanner.matched[0..-2] + ';'
104
+ new_code << (scanner.matched[0..-2] + ';')
105
105
  break
106
106
  else
107
107
  new_code << scanner.matched
@@ -114,12 +114,12 @@ module Synvert::Core
114
114
  end
115
115
  end
116
116
  if scanner.scan(/.*?\z/)
117
- new_code << WHITESPACE * scanner.matched.size
117
+ new_code << (WHITESPACE * scanner.matched.size)
118
118
  end
119
119
  if scanner.scan(/.*?\n/)
120
- new_code << WHITESPACE * (scanner.matched.size - 1) + "\n"
120
+ new_code << ((WHITESPACE * (scanner.matched.size - 1)) + "\n")
121
121
  end
122
122
  end
123
123
  end
124
124
  end
125
- end
125
+ end
@@ -9,9 +9,9 @@ module Synvert::Core
9
9
  # @param source [String] erb code.
10
10
  # @return [String] encoded ruby code.
11
11
  def encode(source)
12
- source.gsub(/%>.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
12
+ source.gsub(/%>.*?<%=?/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
13
13
  .sub(/^.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
14
- .sub(/%>.*?$/m) { |str| replace_all_code_but_white_space_characters(str) }
14
+ .sub(/%>.*?$/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
15
15
  end
16
16
 
17
17
  # Generate an empty proc.
@@ -25,7 +25,7 @@ module Synvert::Core
25
25
  new_code << WHITESPACE
26
26
  scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
27
27
  elsif scanner.scan(/[%#\.][a-zA-Z0-9\-_%#\.]+/) # it matches element, id and class " %span.user"
28
- new_code << WHITESPACE * scanner.matched.size
28
+ new_code << (WHITESPACE * scanner.matched.size)
29
29
  scan_matching_wrapper(scanner, new_code, '{', '}')
30
30
  if scanner.scan('=')
31
31
  new_code << WHITESPACE
@@ -6,11 +6,7 @@ module Synvert::Core
6
6
  class << self
7
7
  include Elegant
8
8
 
9
- ATTRIBUTES_PAIR = {
10
- '{' => '}',
11
- '[' => ']',
12
- '(' => ')'
13
- }
9
+ ATTRIBUTES_PAIR = { '{' => '}', '[' => ']', '(' => ')' }
14
10
 
15
11
  # Encode haml string, leave only ruby code, replace other haml code with whitespace.
16
12
  # And insert `end\n` for each if, unless, begin, case to make it a valid ruby code.
@@ -28,16 +24,16 @@ module Synvert::Core
28
24
  new_code << WHITESPACE
29
25
  scan_ruby_statement(scanner, new_code, leading_spaces_counts, leading_spaces_count)
30
26
  elsif scanner.scan(/==?/) # it matches ruby expression " = current_user.login"
31
- new_code << WHITESPACE * scanner.matched.size
27
+ new_code << (WHITESPACE * scanner.matched.size)
32
28
  scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
33
29
  elsif scanner.scan(/[a-z#\.][a-zA-Z0-9\-_%#\.]*/) # it matches element, id and class " span.user"
34
- new_code << WHITESPACE * scanner.matched.size
30
+ new_code << (WHITESPACE * scanner.matched.size)
35
31
  ATTRIBUTES_PAIR.each do |start, ending| # it matches attributes in brackets " span[ class='user' ]"
36
32
  scan_matching_wrapper(scanner, new_code, start, ending)
37
33
  end
38
34
  scan_attributes_between_whitespace(scanner, new_code)
39
35
  if scanner.scan(/ ?==?/) # it matches ruby expression " span= current_user.login"
40
- new_code << WHITESPACE * scanner.matched.size
36
+ new_code << (WHITESPACE * scanner.matched.size)
41
37
  scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
42
38
  else
43
39
  scan_ruby_interpolation_and_plain_text(scanner, new_code, leading_spaces_counts, leading_spaces_count)
@@ -64,7 +60,7 @@ module Synvert::Core
64
60
  while scanner.scan(/.*?[#{Regexp.quote(start)}#{Regexp.quote(ending)}]/m)
65
61
  matched = scanner.matched.gsub(/(\A| ).*?=/) { |key| WHITESPACE * key.size }
66
62
  if scanner.matched[-1] == ending
67
- new_code << matched[0..-2] + ';'
63
+ new_code << (matched[0..-2] + ';')
68
64
  count -= 1
69
65
  break if count == 0
70
66
  else
@@ -77,7 +73,7 @@ module Synvert::Core
77
73
 
78
74
  def scan_attributes_between_whitespace(scanner, new_code)
79
75
  while scanner.scan(/ ?[\w\-_]+==?/) # it matches attributes split by space " span class='user'"
80
- new_code << WHITESPACE * scanner.matched.size
76
+ new_code << (WHITESPACE * scanner.matched.size)
81
77
  stack = []
82
78
  while scanner.scan(/(.*?['"\(\)\[\]\{\}]|.+?\b)/)
83
79
  matched = scanner.matched
@@ -86,7 +82,7 @@ module Synvert::Core
86
82
  stack << matched[-1]
87
83
  elsif [')', ']', '}'].include?(matched[-1])
88
84
  stack.pop
89
- elsif %w[' "].include?(matched[-1])
85
+ elsif %w[' "].include?(matched[-1])
90
86
  stack.last == matched[-1] ? stack.pop : stack << matched[-1]
91
87
  end
92
88
  break if stack.empty?
@@ -362,7 +362,7 @@ module Synvert::Core
362
362
  @current_mutation.delete(@current_node, *selectors, and_comma: and_comma)
363
363
  end
364
364
 
365
- # It wraps current node with code.
365
+ # It wraps current node with prefix and suffix code.
366
366
  # @example
367
367
  # # class Foobar
368
368
  # # end
@@ -372,11 +372,13 @@ module Synvert::Core
372
372
  # # end
373
373
  # # end
374
374
  # within_node type: 'class' do
375
- # wrap with: 'module Synvert'
375
+ # wrap with: 'module Synvert', and: 'end', newline: true
376
376
  # end
377
- # @param with [String] code need to be wrapped with.
378
- def wrap(with:)
379
- @current_mutation.wrap(@current_node, with: with)
377
+ # @param prefix [String] prefix code need to be wrapped with.
378
+ # @param suffix [String] suffix code need to be wrapped with.
379
+ # @param newline [Boolean] if wrap code in newline, default is false
380
+ def wrap(prefix:, suffix:, newline: false)
381
+ @current_mutation.wrap(@current_node, prefix: prefix, suffix: suffix, newline: newline)
380
382
  end
381
383
 
382
384
  # No operation.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.24.0'
5
+ VERSION = '1.25.0'
6
6
  end
7
7
  end
@@ -20,6 +20,8 @@ module Synvert::Core
20
20
  bar = 'foo'
21
21
  %>
22
22
 
23
+ <%= user.first_name %> <%= user.last_name %>
24
+
23
25
  <% if User.current &&
24
26
  User.current.admin %>
25
27
  <%= rounded_content("page") do %>
@@ -40,6 +42,8 @@ module Synvert::Core
40
42
  expect(encoded_source).to be_include 'post = Post.find(:first)'
41
43
  expect(encoded_source).to be_include "link_to_function 'test', \"confirm('test');\""
42
44
  expect(encoded_source).to be_include 'end'
45
+ expect(encoded_source).to be_include 'user.first_name ;'
46
+ expect(encoded_source).to be_include 'user.last_name ;'
43
47
  expect(encoded_source).not_to be_include 'style'
44
48
  expect(encoded_source).not_to be_include 'div'
45
49
  end
@@ -233,14 +233,16 @@ module Synvert::Core
233
233
  instance.delete :dot, :message, and_comma: true
234
234
  end
235
235
 
236
- it 'parses wrap with' do
236
+ it 'parses wrap' do
237
237
  instance.instance_variable_set(:@current_mutation, double)
238
238
  instance.current_node = double
239
239
  expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(
240
240
  instance.current_node,
241
- with: 'module Foobar'
241
+ prefix: 'module Foobar',
242
+ suffix: 'end',
243
+ newline: true
242
244
  )
243
- instance.wrap with: 'module Foobar'
245
+ instance.wrap prefix: 'module Foobar', suffix: 'end', newline: true
244
246
  end
245
247
 
246
248
  it 'parses noop' do
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency "activesupport", "< 7.0.0"
23
23
  spec.add_runtime_dependency "node_query", ">= 1.12.1"
24
- spec.add_runtime_dependency "node_mutation", ">= 1.14.0"
24
+ spec.add_runtime_dependency "node_mutation", ">= 1.15.1"
25
25
  spec.add_runtime_dependency "parser"
26
26
  spec.add_runtime_dependency "parser_node_ext", ">= 1.0.0"
27
27
  spec.add_runtime_dependency "parallel"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.24.0
4
+ version: 1.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-16 00:00:00.000000000 Z
11
+ date: 2023-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.14.0
47
+ version: 1.15.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.14.0
54
+ version: 1.15.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: parser
57
57
  requirement: !ruby/object:Gem::Requirement