Skip to content

Commit

Permalink
Merge 50567d2 into 22ecfa4
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Jan 30, 2021
2 parents 22ecfa4 + 50567d2 commit d1d4e2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/synvert/core/engine/erb.rb
Expand Up @@ -31,21 +31,21 @@ def decode(source)
private

def decode_ruby_stmt(source)
source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/m) { "<%#{$1}%>" }
source.gsub(/#{ERUBY_STMT_SPLITTER}(.+?)#{ERUBY_STMT_SPLITTER}/m) { "<%#{Regexp.last_match(1)}%>" }
end

def decode_ruby_output(source)
source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/m) { "<%=#{$1}%>" }.gsub(
source.gsub(/@output_buffer.append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/m) { "<%=#{Regexp.last_match(1)}%>" }.gsub(
/@output_buffer.append= (.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/m
) { |m| "<%=#{m.sub('@output_buffer.append= ', '').sub(ERUBY_EXPR_SPLITTER, '')}%>" }
end

def decode_html_output(source)
source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text($1) }.gsub(
source.gsub(/@output_buffer.safe_append='(.+?)'.freeze;/m) { reverse_escape_text(Regexp.last_match(1)) }.gsub(
/@output_buffer.safe_append=\((.+?)\);#{ERUBY_EXPR_SPLITTER}/m
) { reverse_escape_text($1) }.gsub(
) { reverse_escape_text(Regexp.last_match(1)) }.gsub(
/@output_buffer.safe_append=(.+?)\s+(do|\{)(\s*\|[^|]*\|)?\s*#{ERUBY_EXPR_SPLITTER}/m
) { reverse_escape_text($1) }
) { reverse_escape_text(Regexp.last_match(1)) }
end

def remove_erubis_buf(source)
Expand Down Expand Up @@ -118,9 +118,9 @@ def add_stmt(src, code)
if code != "\n" && code != ''
index =
if code =~ /\A(\s*)\r?\n/
$1.length
Regexp.last_match(1).length
elsif code =~ /\A(\s+)/
$1.end_with?(' ') ? $1.length - 1 : $1.length
Regexp.last_match(1).end_with?(' ') ? Regexp.last_match(1).length - 1 : Regexp.last_match(1).length
else
0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/synvert/core/node_ext.rb
Expand Up @@ -365,7 +365,7 @@ def match?(rules)
# @raise [Synvert::Core::MethodNotSupported] if string in block {{ }} does not support.
def rewritten_source(code)
code.gsub(/{{(.*?)}}/m) do
old_code = $1
old_code = Regexp.last_match(1)
if self.respond_to? old_code.split(/\.|\[/).first
evaluated = self.instance_eval old_code
case evaluated
Expand Down
2 changes: 1 addition & 1 deletion lib/synvert/core/rewriter/helper.rb
Expand Up @@ -65,7 +65,7 @@ def add_curly_brackets_if_necessary(code)
#
# strip_brackets("(1..100)") #=> "1..100"
def strip_brackets(code)
code.sub(/^\((.*)\)$/) { $1 }.sub(/^\[(.*)\]$/) { $1 }.sub(/^{(.*)}$/) { $1 }
code.sub(/^\((.*)\)$/) { Regexp.last_match(1) }.sub(/^\[(.*)\]$/) { Regexp.last_match(1) }.sub(/^{(.*)}$/) { Regexp.last_match(1) }
end
end
end

0 comments on commit d1d4e2b

Please sign in to comment.