Class: Synvert::Core::Rewriter::ReplaceErbStmtWithExprAction

Inherits:
Action
  • Object
show all
Defined in:
lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb

Overview

ReplaceErbStmtWithExprAction to replace erb stmt code to expr,

Examples:

e.g. <% form_for ... %> => <%= form_for ... %>.

Constant Summary

Constants inherited from Action

Action::DEFAULT_INDENT

Instance Attribute Summary

Attributes inherited from Action

#begin_pos, #end_pos

Instance Method Summary collapse

Methods inherited from Action

#process

Constructor Details

#initialize(instance) ⇒ ReplaceErbStmtWithExprAction

Initialize a ReplaceErbStmtWithExprAction.

Parameters:



11
12
13
# File 'lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb', line 11

def initialize(instance)
  super(instance, nil)
end

Instance Method Details

#rewritten_codeString

The rewritten erb expr code.

Returns:

  • (String)

    rewritten code.



18
19
20
21
22
# File 'lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb', line 18

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