Class: HamlLint::RubyExtraction::InterpolationChunk

Inherits:
BaseChunk
  • Object
show all
Defined in:
lib/haml_lint/ruby_extraction/interpolation_chunk.rb

Overview

Deals with interpolation within a plain text, filter, etc. Can only handling single line interpolation, so will be skipped if it takes more than one line or if the correction takes more than one line.

Stores the char index to know where in the line to do the replacements.

Constant Summary

Constants inherited from BaseChunk

BaseChunk::COMMA_CHANGES_LINES

Instance Attribute Summary

Attributes inherited from BaseChunk

#end_marker_indent, #haml_line_index, #node, #ruby_lines, #start_marker_line_number

Instance Method Summary collapse

Methods inherited from BaseChunk

#assemble_in, #full_assemble, #fuse, #haml_end_line_index, #nb_haml_lines, #skip_line_indexes_in_source_map, #start_marker_indent, #transfer_correction, #wrap_in_markers

Constructor Details

#initialize(*args, start_char_index:, **kwargs) ⇒ InterpolationChunk

Returns a new instance of InterpolationChunk.



10
11
12
13
# File 'lib/haml_lint/ruby_extraction/interpolation_chunk.rb', line 10

def initialize(*args, start_char_index:, **kwargs)
  super(*args, **kwargs)
  @start_char_index = start_char_index
end

Instance Method Details

#transfer_correction_logic(coordinator, to_ruby_lines, haml_lines) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/haml_lint/ruby_extraction/interpolation_chunk.rb', line 15

def transfer_correction_logic(coordinator, to_ruby_lines, haml_lines)
  return if @ruby_lines.size != 1
  return if to_ruby_lines.size != 1

  from_ruby_line = @ruby_lines.first.partition(coordinator.script_output_prefix).last
  to_ruby_line = to_ruby_lines.first.partition(coordinator.script_output_prefix).last

  haml_line = haml_lines[@haml_line_index]
  haml_line[@start_char_index...(@start_char_index + from_ruby_line.size)] = to_ruby_line
end