Sha256: 7ade6bf44f9e8828e8e9b9cd12b8a9e0038e645290af99ea47a3e7e4e94f629c

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  # Reports missing content_for_layout in layouts
  class RequiredLayoutObject < LiquidCheck
    severity :error
    category :liquid
    doc docs_url(__FILE__)

    def initialize
      @content_for_layout_found = false
    end

    def on_document(node)
      @layout_platformos_app_node = node if node.app_file.layout?
    end

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

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

    def after_document(node)
      return unless node.app_file.layout?

      add_missing_object_offense("content_for_layout", "</body>") unless @content_for_layout_found
    end

    private

    def add_missing_object_offense(name, tag)
      add_offense("layout must include {{#{name}}}", node: @layout_platformos_app_node) do
        if @layout_platformos_app_node.source.index(tag)

          @layout_platformos_app_node.source.insert(@layout_platformos_app_node.source.index(tag), "  {{ #{name} }}\n  ")
          @layout_platformos_app_node.markup = @layout_platformos_app_node.source
          @content_for_layout_found = true
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.13 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.12 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.11 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.10 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.9 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.8 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.7 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.6 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.5 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.4 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.3 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.2 lib/platformos_check/checks/required_layout_object.rb
platformos-check-0.4.1 lib/platformos_check/checks/required_layout_object.rb