Sha256: f24d6a86b53d697eead6f3752313f50d4db5103ffd4d5c2dddef92e33fe5ccb2
Contents?: true
Size: 1.24 KB
Versions: 16
Compression:
Stored size: 1.24 KB
Contents
# encoding: utf-8 module Synvert::Core # ReplaceErbStmtWithExprAction to replace erb stmt code to expr, # e.g. <% form_for ... %> => <%= form_for ... %>. class Rewriter::ReplaceErbStmtWithExprAction < Rewriter::Action def initialize(instance, code=nil) super end # Begin position of code to replace. # # @return [Integer] begin position. def begin_pos node_begin_pos = @node.loc.expression.begin_pos while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' ' end node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1 end # End position of code to replace. # # @return [Integer] end position. def end_pos node_begin_pos = @node.loc.expression.begin_pos node_begin_pos += @node.loc.expression.source.index "do" while @node.loc.expression.source_buffer.source[node_begin_pos += 1] != '@' end node_begin_pos end # The rewritten erb expr code. # # @return [String] rewritten code. def rewritten_code @node.loc.expression.source_buffer.source[begin_pos...end_pos].sub(Engine::ERUBY_STMT_SPLITTER, "@output_buffer.append= ") .sub(Engine::ERUBY_STMT_SPLITTER, Engine::ERUBY_EXPR_SPLITTER) end end end
Version data entries
16 entries across 16 versions & 1 rubygems