Class: HamlLint::RubyExtraction::RubyFilterChunk

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

Overview

Chunk for dealing with ‘:ruby` filter.

Constant Summary

Constants inherited from BaseChunk

BaseChunk::COMMA_CHANGES_LINES

Instance Attribute Summary collapse

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, #transfer_correction, #wrap_in_markers

Constructor Details

#initialize(*args, start_marker_indent:, **kwargs) ⇒ RubyFilterChunk

Returns a new instance of RubyFilterChunk.



8
9
10
11
# File 'lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb', line 8

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

Instance Attribute Details

#start_marker_indentObject (readonly)

Returns the value of attribute start_marker_indent.



6
7
8
# File 'lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb', line 6

def start_marker_indent
  @start_marker_indent
end

Instance Method Details

#transfer_correction_logic(coordinator, to_ruby_lines, haml_lines) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb', line 13

def transfer_correction_logic(coordinator, to_ruby_lines, haml_lines)
  marker_index = coordinator.find_line_index_of_marker_in_corrections(@start_marker_line_number)

  new_name_indent = coordinator.corrected_ruby_lines[marker_index].index(/\S/)

  delta_indent = new_name_indent - @start_marker_indent
  haml_lines[@haml_line_index - 1] = HamlLint::Utils.indent(haml_lines[@haml_line_index - 1], delta_indent)

  to_haml_lines = to_ruby_lines.map do |line|
    if line !~ /\S/
      # whitespace or empty
      ''
    else
      "  #{line}"
    end
  end

  haml_lines[@haml_line_index..haml_end_line_index] = to_haml_lines
end