Class: ThemeCheck::MissingRequiredTemplateFiles

Inherits:
LiquidCheck show all
Defined in:
lib/theme_check/checks/missing_required_template_files.rb

Overview

Reports missing shopify required theme files required templates: shopify.dev/tutorials/review-theme-store-requirements-files

Constant Summary collapse

REQUIRED_LIQUID_FILES =
%w(layout/theme)
REQUIRED_LIQUID_TEMPLATE_FILES =
%w(
  gift_card customers/account customers/activate_account customers/addresses
  customers/login customers/order customers/register customers/reset_password
).map { |file| "templates/#{file}" }
REQUIRED_JSON_TEMPLATE_FILES =
%w(
  index product collection cart blog article page list-collections search 404
  password
).map { |file| "templates/#{file}" }
REQUIRED_TEMPLATE_FILES =
(REQUIRED_LIQUID_TEMPLATE_FILES + REQUIRED_JSON_TEMPLATE_FILES)

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES

Instance Attribute Summary

Attributes inherited from Check

#ignored_patterns, #offenses, #options, #theme

Instance Method Summary collapse

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

Methods inherited from Check

#==, #add_offense, all, can_disable, #can_disable?, categories, #categories, category, #code_name, doc, #doc, docs_url, #ignore!, #ignored?, #severity, severity, #severity=, #severity_value, severity_value, single_file, #single_file?, #to_s, #whole_theme?

Methods included from JsonHelpers

#format_json_parse_error, #pretty_json

Instance Method Details

#on_endObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/theme_check/checks/missing_required_template_files.rb', line 25

def on_end
  (REQUIRED_LIQUID_FILES - theme.liquid.map(&:name)).each do |file|
    add_offense("'#{file}.liquid' is missing") do |corrector|
      corrector.create_file(@theme.storage, "#{file}.liquid", "")
    end
  end
  (REQUIRED_TEMPLATE_FILES - (theme.liquid + theme.json).map(&:name)).each do |file|
    add_offense("'#{file}.liquid' or '#{file}.json' is missing") do |corrector|
      if REQUIRED_LIQUID_TEMPLATE_FILES.include?(file)
        corrector.create_file(@theme.storage, "#{file}.liquid", "")
      else
        corrector.create_file(@theme.storage, "#{file}.json", JSON.pretty_generate({
          name: "TODO",
          sections: {},
          order: [],
        }))
      end
    end
  end
end