Class: ScriptCheck

Inherits:
HTMLProofer::Check show all
Defined in:
lib/html-proofer/check/scripts.rb

Instance Attribute Summary collapse

Attributes inherited from HTMLProofer::Check

#element, #external_urls, #issues, #node, #options, #path

Instance Method Summary collapse

Methods inherited from HTMLProofer::Check

#add_issue, #add_path_for_url, #add_to_external_urls, #blank?, #create_element, #initialize, subchecks

Constructor Details

This class inherits a constructor from HTMLProofer::Check

Instance Attribute Details

#srcObject (readonly)

Returns the value of attribute src.



2
3
4
# File 'lib/html-proofer/check/scripts.rb', line 2

def src
  @src
end

Instance Method Details

#missing_src?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/html-proofer/check/scripts.rb', line 4

def missing_src?
  !@script.src
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/html-proofer/check/scripts.rb', line 8

def run
  @html.css('script').each do |node|
    @script = create_element(node)
    line = node.line

    next if @script.ignore?
    next unless node.text.strip.empty?

    # does the script exist?
    if missing_src?
      add_issue('script is empty and has no src attribute', line: line)
    elsif @script.remote?
      add_to_external_urls(@script.src, line)
    elsif !@script.exists?
      add_issue("internal script #{@script.src} does not exist", line: line)
    end
  end

  external_urls
end