node_mutation 1.9.2 → 1.9.3

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: ccf182b956fa95424444237b856f0eaf8a184079ad3c0a4288d73dfe826ba288
4
- data.tar.gz: 6bfb14607647b18b00dfaf9dd64f238aef07aa3f12df72706ffea054ec1b09d6
3
+ metadata.gz: 1e20b2ab8c6e7c9f01e01b97dfd8b0315d6fb6e474e8176a2f83609ff4e565da
4
+ data.tar.gz: cc6bcbb6ddbb098b2dbe9090e20cb6d9b7466eea2041a6ae6a0880470e0f8d01
5
5
  SHA512:
6
- metadata.gz: dd147fa9473293c29053b372d21de52fd197a936d3b1c615bf461702630612386851b592c28f6e06ff70831799ca28c493e63044c3cbbc2bb5f631dbe369790d
7
- data.tar.gz: aa523832bc7421c0f2a4090d2e685ddb09ee3f818c4df39499ed796a84ec2a54f28b7b29f7fff0749e387597f6ea4cfe2f9fb06fc3caba49a20be503207e2370
6
+ metadata.gz: 22b95e80c34f121736637a069cebc2d8e717e1e6cc9461937a9c00dff9253db473dccb945d6463edaee4a3c54df9392597fe6b65e1825a56425742f1beaf80b2
7
+ data.tar.gz: 7134108cd2d15fd4dd6a4ee73a23f31917bfff251f403297be2f636fa0e4ab580482da4971c87815c22e2b3e182ec585b39fc688963b6495f38781e764372bdf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.9.3 (2023-02-15)
4
+
5
+ * Remove engine
6
+
3
7
  ## 1.9.2 (2023-02-11)
4
8
 
5
9
  * Squeeze space if end with space, newline or semicolon
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.9.2)
4
+ node_mutation (1.9.3)
5
5
  erubis
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.9.2"
4
+ VERSION = "1.9.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-11 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -51,8 +51,6 @@ files:
51
51
  - lib/node_mutation/action/replace_with_action.rb
52
52
  - lib/node_mutation/action/wrap_action.rb
53
53
  - lib/node_mutation/adapter.rb
54
- - lib/node_mutation/engine.rb
55
- - lib/node_mutation/engine/erb.rb
56
54
  - lib/node_mutation/parser_adapter.rb
57
55
  - lib/node_mutation/result.rb
58
56
  - lib/node_mutation/strategy.rb
@@ -1,148 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'erubis'
4
-
5
- module NodeMutation::Engine
6
- ERUBY_EXPR_SPLITTER = '; ;'
7
- ERUBY_STMT_SPLITTER = '; ;'
8
-
9
- class Erb
10
- class << self
11
- # convert erb to ruby code.
12
- #
13
- # @param source [String] erb source code.
14
- # @return [String] ruby source code.
15
- def encode(source)
16
- Erubis.new(source.gsub('-%>', '%>'), escape: false, trim: false).src
17
- end
18
-
19
- # convert ruby code to erb.
20
- #
21
- # @param source [String] ruby source code.
22
- # @return [String] erb source code.
23
- def decode(source)
24
- source = decode_ruby_stmt(source)
25
- source = decode_ruby_output(source)
26
- source = decode_html_output(source)
27
- source = remove_erubis_buf(source)
28
- end
29
-
30
- private
31
-
32
- def decode_ruby_stmt(source)
33
- source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/mo) { "<%#{Regexp.last_match(1)}%>" }
34
- end
35
-
36
- def decode_ruby_output(source)
37
- source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo) {
38
- "<%=#{Regexp.last_match(1)}%>"
39
- }.gsub(/@output_buffer.append= (.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo) { |m|
40
- "<%=#{m.sub('@output_buffer.append= ', '').sub(ERUBY_EXPR_SPLITTER, '')}%>"
41
- }
42
- end
43
-
44
- def decode_html_output(source)
45
- source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text(Regexp.last_match(1)) }
46
- .gsub(
47
- /@output_buffer.safe_append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/mo
48
- ) { reverse_escape_text(Regexp.last_match(1)) }
49
- .gsub(
50
- /@output_buffer.safe_append=(.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/mo
51
- ) { reverse_escape_text(Regexp.last_match(1)) }
52
- end
53
-
54
- def remove_erubis_buf(source)
55
- source
56
- .sub('@output_buffer = output_buffer || ActionView::OutputBuffer.new;', '')
57
- .sub('@output_buffer.to_s', '')
58
- end
59
-
60
- def reverse_escape_text(source)
61
- source.gsub("\\\\", "\\").gsub("\\'", "'")
62
- end
63
- end
64
- end
65
-
66
- # borrowed from rails
67
- class Erubis < ::Erubis::Eruby
68
- BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
69
- def add_preamble(src)
70
- @newline_pending = 0
71
- src << '@output_buffer = output_buffer || ActionView::OutputBuffer.new;'
72
- end
73
-
74
- def add_text(src, text)
75
- return if text.empty?
76
-
77
- if text == "\n"
78
- @newline_pending += 1
79
- else
80
- src << "@output_buffer.safe_append='"
81
- src << ("\n" * @newline_pending) if @newline_pending > 0
82
- src << escape_text(text)
83
- src << "'.freeze;"
84
-
85
- @newline_pending = 0
86
- end
87
- end
88
-
89
- # Erubis toggles <%= and <%== behavior when escaping is enabled.
90
- # We override to always treat <%== as escaped.
91
- def add_expr(src, code, indicator)
92
- case indicator
93
- when '=='
94
- add_expr_escaped(src, code)
95
- else
96
- super
97
- end
98
- end
99
-
100
- def add_expr_literal(src, code)
101
- flush_newline_if_pending(src)
102
- if BLOCK_EXPR.match?(code)
103
- src << '@output_buffer.append= ' << code << ERUBY_EXPR_SPLITTER
104
- else
105
- src << '@output_buffer.append=(' << code << ');' << ERUBY_EXPR_SPLITTER
106
- end
107
- end
108
-
109
- def add_expr_escaped(src, code)
110
- flush_newline_if_pending(src)
111
- if BLOCK_EXPR.match?(code)
112
- src << '@output_buffer.safe_append= ' << code << ERUBY_EXPR_SPLITTER
113
- else
114
- src << '@output_buffer.safe_append=(' << code << ');' << ERUBY_EXPR_SPLITTER
115
- end
116
- end
117
-
118
- def add_stmt(src, code)
119
- flush_newline_if_pending(src)
120
- if code != "\n" && code != ''
121
- index =
122
- case code
123
- when /\A(\s*)\r?\n/
124
- Regexp.last_match(1).length
125
- when /\A(\s+)/
126
- Regexp.last_match(1).end_with?(' ') ? Regexp.last_match(1).length - 1 : Regexp.last_match(1).length
127
- else
128
- 0
129
- end
130
- code.insert(index, ERUBY_STMT_SPLITTER)
131
- code.insert(-1, ERUBY_STMT_SPLITTER[0...-1])
132
- end
133
- super
134
- end
135
-
136
- def add_postamble(src)
137
- flush_newline_if_pending(src)
138
- src << '@output_buffer.to_s'
139
- end
140
-
141
- def flush_newline_if_pending(src)
142
- if @newline_pending > 0
143
- src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
144
- @newline_pending = 0
145
- end
146
- end
147
- end
148
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NodeMutation::Engine
4
- # Engine defines how to encode / decode other files (like erb).
5
- autoload :Erb, 'node_mutation/engine/erb'
6
- end