Class: Synvert::Core::Rewriter::ReplaceErbStmtWithExprAction
- Defined in:
- lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
Overview
ReplaceErbStmtWithExprAction to replace erb stmt code to expr,
e.g. <% form_for ... %> => <%= form_for ... %>.
Constant Summary
Constants inherited from Action
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
- #calculate_position ⇒ Object
-
#initialize(instance, code = nil) ⇒ ReplaceErbStmtWithExprAction
constructor
A new instance of ReplaceErbStmtWithExprAction.
-
#rewritten_code ⇒ String
The rewritten erb expr code.
Methods inherited from Action
Constructor Details
#initialize(instance, code = nil) ⇒ ReplaceErbStmtWithExprAction
Returns a new instance of ReplaceErbStmtWithExprAction.
7 8 9 |
# File 'lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb', line 7 def initialize(instance, code = nil) super end |
Instance Method Details
#calculate_position ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb', line 11 def calculate_position node_begin_pos = @node.loc.expression.begin_pos while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' ' end @begin_pos = node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1 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 @end_pos = node_begin_pos end |
#rewritten_code ⇒ String
The rewritten erb expr code.
27 28 29 30 31 |
# File 'lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb', line 27 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 |