Sha256: e424e285249effb3acf2c288c4d2374bba2647ef2848e9a6f8d6e49cc639d436

Contents?: true

Size: 773 Bytes

Versions: 25

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

require "nokogiri"
require "forwardable"

module PlatformosCheck
  class HtmlVisitor
    attr_reader :checks

    def initialize(checks)
      @checks = checks
    end

    def visit_liquid_file(liquid_file)
      visit(HtmlNode.parse(liquid_file))
    rescue ArgumentError => e
      call_checks(:on_parse_error, e, liquid_file)
    end

    private

    def visit(node)
      call_checks(:on_element, node) if node.element?
      call_checks(:"on_#{node.name}", node)
      node.children.each { |child| visit(child) }
      return if node.literal?

      call_checks(:"after_#{node.name}", node)
      call_checks(:after_element, node) if node.element?
    end

    def call_checks(method, *)
      checks.call(method, *)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.2.0 lib/platformos_check/html_visitor.rb
platformos-check-0.1.0 lib/platformos_check/html_visitor.rb
platformos-check-0.0.3 lib/platformos_check/html_visitor.rb
platformos-check-0.0.2 lib/platformos_check/html_visitor.rb
platformos-check-0.0.1 lib/platformos_check/html_visitor.rb