Sha256: c058622b7b17be80f4b3209e34d51238d03f447b7e5e29d98251860dcaaedabf

Contents?: true

Size: 1.17 KB

Versions: 25

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.template.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.template.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

25 entries across 25 versions & 1 rubygems

Version Path
theme-check-1.6.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.6.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.5.2 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.5.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.5.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.4.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.3.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.2.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.1.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-1.0.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.10.2 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.10.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.10.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.9.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.9.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.8.3 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.8.2 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.8.1 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.8.0 lib/theme_check/checks/required_layout_theme_object.rb
theme-check-0.7.3 lib/theme_check/checks/required_layout_theme_object.rb