Sha256: 98d60fe60daa2d7a65a00a60ab2bec6cd133d5cc8922c3f55b087ab0a48032e2

Contents?: true

Size: 919 Bytes

Versions: 2

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

module ThemeCheck
  class Corrector
    def initialize(template:)
      @template = template
    end

    def insert_after(node, content)
      line = @template.full_line(node.line_number)
      line.insert(node.range[1] + 1, content)
      @template.update!
    end

    def insert_before(node, content)
      line = @template.full_line(node.line_number)
      line.insert(node.range[0], content)
      @template.update!
    end

    def replace(node, content)
      line = @template.full_line(node.line_number)
      line[node.range[0]..node.range[1]] = content
      node.markup = content
      @template.update!
    end

    def wrap(node, insert_before, insert_after)
      line = @template.full_line(node.line_number)
      line.insert(node.range[0], insert_before)
      line.insert(node.range[1] + 1 + insert_before.length, insert_after)
      @template.update!
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
theme-check-0.2.2 lib/theme_check/corrector.rb
theme-check-0.2.0 lib/theme_check/corrector.rb