Sha256: 916f9679eaae8120a7052bdb1dd634bd1370e00e4d5f11058e86d9014762dde9

Contents?: true

Size: 793 Bytes

Versions: 3

Compression:

Stored size: 793 Bytes

Contents

# encoding: utf-8

class Script < ::HTML::Proofer::Checkable

  def src
    @src unless @src.nil? || @src.empty?
  end

  def missing_src?
    !src
  end

  def blank?
    @content.strip.empty?
  end

end

class Scripts < ::HTML::Proofer::Checks::Check
  def run
    @html.xpath('//script[not(ancestor::pre or ancestor::code)]').each do |s|
      script = Script.new s, "script", self

      next if script.ignore?
      next unless script.blank?

      # does the script exist?
      if script.missing_src?
        self.add_issue "script is empty and has no src attribute"
      elsif script.remote?
        add_to_external_urls script.src
      else
        self.add_issue("internal script #{script.src} does not exist") unless script.exists?
      end

    end

    external_urls
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
html-proofer-1.1.3 lib/html/proofer/checks/scripts.rb
html-proofer-1.1.2 lib/html/proofer/checks/scripts.rb
html-proofer-1.1.1 lib/html/proofer/checks/scripts.rb