Class: HamlLint::RubyExtraction::NonRubyFilterChunk

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

Overview

Chunk for dealing with every HAML filter other than ‘:ruby` The generated Ruby for these is just a HEREDOC, so interpolation is corrected at the same time by RuboCop.

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

Constructor Details

This class inherits a constructor from HamlLint::RubyExtraction::BaseChunk

Instance Method Details

#skip_line_indexes_in_source_mapObject



28
29
30
# File 'lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb', line 28

def skip_line_indexes_in_source_map
  [@ruby_lines.size - 1]
end

#transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb', line 8

def transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines)
  delta_indent = to_ruby_lines.first.index(/\S/) - @ruby_lines.first.index(/\S/)

  haml_lines[@haml_line_index] = HamlLint::Utils.indent(haml_lines[@haml_line_index], delta_indent)

  # Ignoring the starting <<~HAML_LINT_FILTER and ending end
  to_content_lines = to_ruby_lines[1...-1]

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

  haml_lines[(@haml_line_index + 1)..haml_end_line_index] = to_haml_lines
end