Class: ThemeCheck::Corrector

Inherits:
Object
  • Object
show all
Includes:
JsonHelpers
Defined in:
lib/theme_check/corrector.rb

Instance Method Summary collapse

Methods included from JsonHelpers

#format_json_parse_error, #pretty_json

Constructor Details

#initialize(theme_file:) ⇒ Corrector

Returns a new instance of Corrector.



7
8
9
# File 'lib/theme_check/corrector.rb', line 7

def initialize(theme_file:)
  @theme_file = theme_file
end

Instance Method Details

#add_translation(json_file, path, value) ⇒ Object



52
53
54
55
56
# File 'lib/theme_check/corrector.rb', line 52

def add_translation(json_file, path, value)
  hash = json_file.content
  SchemaHelper.set(hash, path, value)
  json_file.update_contents(hash)
end

#create_file(storage, relative_path, content) ⇒ Object



40
41
42
# File 'lib/theme_check/corrector.rb', line 40

def create_file(storage, relative_path, content)
  storage.write(relative_path, content)
end

#insert_after(node, content, character_range = nil) ⇒ Object



11
12
13
# File 'lib/theme_check/corrector.rb', line 11

def insert_after(node, content, character_range = nil)
  @theme_file.rewriter.insert_after(node, content, character_range)
end

#insert_before(node, content, character_range = nil) ⇒ Object



15
16
17
# File 'lib/theme_check/corrector.rb', line 15

def insert_before(node, content, character_range = nil)
  @theme_file.rewriter.insert_before(node, content, character_range)
end

#mkdir(storage, relative_path) ⇒ Object



48
49
50
# File 'lib/theme_check/corrector.rb', line 48

def mkdir(storage, relative_path)
  storage.mkdir(relative_path)
end

#remove(node) ⇒ Object



19
20
21
# File 'lib/theme_check/corrector.rb', line 19

def remove(node)
  @theme_file.rewriter.remove(node)
end

#remove_file(storage, relative_path) ⇒ Object



44
45
46
# File 'lib/theme_check/corrector.rb', line 44

def remove_file(storage, relative_path)
  storage.remove(relative_path)
end

#remove_translation(json_file, path) ⇒ Object



58
59
60
61
62
# File 'lib/theme_check/corrector.rb', line 58

def remove_translation(json_file, path)
  hash = json_file.content
  SchemaHelper.delete(hash, path)
  json_file.update_contents(hash)
end

#replace(node, content, character_range = nil) ⇒ Object



23
24
25
26
# File 'lib/theme_check/corrector.rb', line 23

def replace(node, content, character_range = nil)
  @theme_file.rewriter.replace(node, content, character_range)
  node.markup = content
end

#replace_inner_json(node, json, **pretty_json_opts) ⇒ Object



32
33
34
# File 'lib/theme_check/corrector.rb', line 32

def replace_inner_json(node, json, **pretty_json_opts)
  replace_inner_markup(node, pretty_json(json, **pretty_json_opts))
end

#replace_inner_markup(node, content) ⇒ Object



28
29
30
# File 'lib/theme_check/corrector.rb', line 28

def replace_inner_markup(node, content)
  @theme_file.rewriter.replace_inner_markup(node, content)
end

#wrap(node, insert_before, insert_after) ⇒ Object



36
37
38
# File 'lib/theme_check/corrector.rb', line 36

def wrap(node, insert_before, insert_after)
  @theme_file.rewriter.wrap(node, insert_before, insert_after)
end