Class: ThemeCheck::Corrector

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

Instance Method Summary collapse

Constructor Details

#initialize(theme_file:) ⇒ Corrector

Returns a new instance of Corrector.



5
6
7
# File 'lib/theme_check/corrector.rb', line 5

def initialize(theme_file:)
  @theme_file = theme_file
end

Instance Method Details

#add_default_translation_key(file, key, value) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/theme_check/corrector.rb', line 43

def add_default_translation_key(file, key, value)
  hash = file.content
  key.reduce(hash) do |pointer, token|
    return pointer[token] = value if token == key.last
    pointer[token] = {} unless pointer.key?(token)
    pointer[token]
  end
  file.update_contents(hash)
end

#create(theme, relative_path, content) ⇒ Object



26
27
28
# File 'lib/theme_check/corrector.rb', line 26

def create(theme, relative_path, content)
  theme.storage.write(relative_path, content)
end

#create_default_locale_json(theme) ⇒ Object



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

def create_default_locale_json(theme)
  theme.default_locale_json = JsonFile.new("locales/#{theme.default_locale}.default.json", theme.storage)
  theme.default_locale_json.update_contents({})
end

#insert_after(node, content) ⇒ Object



9
10
11
# File 'lib/theme_check/corrector.rb', line 9

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

#insert_before(node, content) ⇒ Object



13
14
15
# File 'lib/theme_check/corrector.rb', line 13

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

#mkdir(theme, relative_path) ⇒ Object



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

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

#remove(theme, relative_path) ⇒ Object



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

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

#replace(node, content) ⇒ Object



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

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

#wrap(node, insert_before, insert_after) ⇒ Object



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

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