Class: HamlLint::RubyExtraction::TagScriptChunk
- Defined in:
- lib/haml_lint/ruby_extraction/tag_script_chunk.rb
Overview
Chunk for handling outputting scripts after a tag, such as ‘%div= spam`
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
-
#transfer_correction_logic(coordinator, to_ruby_lines, haml_lines) ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods inherited from BaseChunk
#assemble_in, #full_assemble, #fuse, #haml_end_line_index, #initialize, #nb_haml_lines, #skip_line_indexes_in_source_map, #start_marker_indent, #transfer_correction, #wrap_in_markers
Constructor Details
This class inherits a constructor from HamlLint::RubyExtraction::BaseChunk
Instance Method Details
#transfer_correction_logic(coordinator, to_ruby_lines, haml_lines) ⇒ Object
rubocop:disable Metrics/AbcSize
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/haml_lint/ruby_extraction/tag_script_chunk.rb', line 6 def transfer_correction_logic(coordinator, to_ruby_lines, haml_lines) # rubocop:disable Metrics/AbcSize # TODO: add checks that we have commas at the end of each line except the last one from_ruby_line = @ruby_lines.first to_ruby_line = to_ruby_lines.first to_line_indent = to_ruby_line.index(/\S/) from_ruby_line = from_ruby_line.sub(coordinator.script_output_prefix, '').sub(/^\s+/, '') to_ruby_line = to_ruby_line.sub(coordinator.script_output_prefix, '').sub(/^\s+/, '') affected_start_index = haml_lines[@haml_line_index].rindex(from_ruby_line) haml_lines[@haml_line_index][affected_start_index..-1] = to_ruby_line indent_delta = affected_start_index - coordinator.script_output_prefix.size - to_line_indent HamlLint::Utils.map_after_first!(to_ruby_lines) do |line| HamlLint::Utils.indent(line, indent_delta) end haml_lines[(@haml_line_index + 1)..haml_end_line_index] = to_ruby_lines[1..] end |