Sha256: f9de4a46659e0b5e3abb7eafa60f5b2e861788b7168218e4b90f4920ad257d07

Contents?: true

Size: 847 Bytes

Versions: 5

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # ReplaceErbStmtWithExprAction to replace erb stmt code to expr,
  # @example
  #   e.g. <% form_for ... %> => <%= form_for ... %>.
  class Rewriter::ReplaceErbStmtWithExprAction < NodeMutation::Action
    # Initialize a ReplaceErbStmtWithExprAction.
    #
    # @param node [Synvert::Core::Rewriter::Node]
    def initialize(node, erb_source)
      super(node, nil)
      @erb_source = erb_source
    end

    # The new erb expr code.
    #
    # @return [String] new code.
    def new_code
      '='
    end

    private

    # Calculate the begin the end positions.
    def calculate_position
      @start = NodeMutation.adapter.get_start(@node)
      loop do
        @start -= 1
        break if @erb_source[@start] == '%'
      end
      @start += 1
      @end = @start
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
synvert-core-1.25.0 lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
synvert-core-1.24.0 lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
synvert-core-1.23.1 lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
synvert-core-1.23.0 lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
synvert-core-1.22.2 lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb