Sha256: 1e5c508fe48e465f88042cfca5124ed0367dc50b1f9f84b840693cccae5c03ac

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

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

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

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

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

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

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

    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

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

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
theme-check-1.6.1 lib/theme_check/corrector.rb
theme-check-1.6.0 lib/theme_check/corrector.rb