Class: ThemeCheck::ThemeFileRewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/theme_file_rewriter.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, source) ⇒ ThemeFileRewriter

Returns a new instance of ThemeFileRewriter.



7
8
9
10
11
12
# File 'lib/theme_check/theme_file_rewriter.rb', line 7

def initialize(name, source)
  @buffer = Parser::Source::Buffer.new(name, source: source)
  @rewriter = Parser::Source::TreeRewriter.new(
    @buffer
  )
end

Instance Method Details

#insert_after(node, content) ⇒ Object



21
22
23
24
25
26
# File 'lib/theme_check/theme_file_rewriter.rb', line 21

def insert_after(node, content)
  @rewriter.insert_after(
    range(node.start_index, node.end_index),
    content
  )
end

#insert_before(node, content) ⇒ Object



14
15
16
17
18
19
# File 'lib/theme_check/theme_file_rewriter.rb', line 14

def insert_before(node, content)
  @rewriter.insert_before(
    range(node.start_index, node.end_index),
    content
  )
end

#remove(node) ⇒ Object



28
29
30
31
32
# File 'lib/theme_check/theme_file_rewriter.rb', line 28

def remove(node)
  @rewriter.remove(
    range(node.start_token_index, node.end_token_index)
  )
end

#replace(node, content) ⇒ Object



34
35
36
37
38
39
# File 'lib/theme_check/theme_file_rewriter.rb', line 34

def replace(node, content)
  @rewriter.replace(
    range(node.start_index, node.end_index),
    content
  )
end

#replace_body(node, content) ⇒ Object



41
42
43
44
45
46
# File 'lib/theme_check/theme_file_rewriter.rb', line 41

def replace_body(node, content)
  @rewriter.replace(
    range(node.block_body_start_index, node.block_body_end_index),
    content
  )
end

#to_sObject



56
57
58
# File 'lib/theme_check/theme_file_rewriter.rb', line 56

def to_s
  @rewriter.process
end

#wrap(node, insert_before, insert_after) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/theme_check/theme_file_rewriter.rb', line 48

def wrap(node, insert_before, insert_after)
  @rewriter.wrap(
    range(node.start_index, node.end_index),
    insert_before,
    insert_after,
  )
end