Sha256: 4e746697112ce65b8a8640002deec2d5869571a3548c7de6e60b4c53a03c0f71

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
module ThemeCheck
  # Reports missing content_for_header and content_for_layout in theme.liquid
  class RequiredLayoutThemeObject < LiquidCheck
    severity :error
    category :liquid
    doc docs_url(__FILE__)

    LAYOUT_FILENAME = "layout/theme"

    def initialize
      @content_for_layout_found = false
      @content_for_header_found = false
    end

    def on_document(node)
      @layout_theme_node = node if node.theme_file.name == LAYOUT_FILENAME
    end

    def on_variable(node)
      return unless node.value.name.is_a?(Liquid::VariableLookup)

      @content_for_header_found ||= node.value.name.name == "content_for_header"
      @content_for_layout_found ||= node.value.name.name == "content_for_layout"
    end

    def after_document(node)
      return unless node.theme_file.name == LAYOUT_FILENAME

      add_missing_object_offense("content_for_layout") unless @content_for_layout_found
      add_missing_object_offense("content_for_header") unless @content_for_header_found
    end

    private

    def add_missing_object_offense(name)
      add_offense("#{LAYOUT_FILENAME} must include {{#{name}}}", node: @layout_theme_node)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
theme-check-1.7.2 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.7.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.7.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.6.2 lib/theme_check/checks/required_layout_theme_object.rb