Class: HTML::Proofer::Checkable
- Inherits:
-
Object
- Object
- HTML::Proofer::Checkable
show all
- Defined in:
- lib/html/proofer/checkable.rb
Instance Method Summary
collapse
Constructor Details
#initialize(obj, type, check) ⇒ Checkable
Returns a new instance of Checkable.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/html/proofer/checkable.rb', line 4
def initialize(obj, type, check)
@src = obj['src']
@href = obj['href']
@alt = obj['alt']
@name = obj['name']
@id = obj['id']
@rel = obj['rel']
@data_ignore_proofer = obj['data-proofer-ignore']
@content = obj.content
@check = check
@checked_paths = {}
@type = type
if @href && @check.options[:href_swap]
@check.options[:href_swap].each do |link, replace|
@href = @href.gsub(link, replace)
end
end
@href.insert 0, "http:" if @href =~ /^\/\//
@src.insert 0, "http:" if @src =~ /^\/\//
end
|
Instance Method Details
#absolute_path ⇒ Object
122
123
124
125
|
# File 'lib/html/proofer/checkable.rb', line 122
def absolute_path
path = file_path || @check.path
File.expand_path path, Dir.pwd
end
|
#exists? ⇒ Boolean
checks if a file exists relative to the current pwd
117
118
119
120
|
# File 'lib/html/proofer/checkable.rb', line 117
def exists?
return @checked_paths[absolute_path] if @checked_paths.has_key? absolute_path
@checked_paths[absolute_path] = File.exist? absolute_path
end
|
#external? ⇒ Boolean
path is external to the file
86
87
88
|
# File 'lib/html/proofer/checkable.rb', line 86
def external?
!internal?
end
|
#file_path ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/html/proofer/checkable.rb', line 95
def file_path
return if path.nil?
if path =~ /^\// base = File.directory?(@check.src) ? @check.src : File.dirname(@check.src)
elsif File.exist?(File.expand_path path, @check.src) base = File.dirname @check.path
elsif File.exist?(File.join(File.dirname(@check.path), path)) base = File.dirname @check.path
else base = @check.path
end
file = File.join base, path
file = File.join path, "index.html" if File.directory? File.expand_path file, @check.src
file
end
|
#hash ⇒ Object
50
51
52
|
# File 'lib/html/proofer/checkable.rb', line 50
def hash
parts.fragment
end
|
#ignore? ⇒ Boolean
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/html/proofer/checkable.rb', line 64
def ignore?
return true if @data_ignore_proofer
case @type
when "favicon"
return true if url.match(/^data:image/)
when "link"
return true if ignores_pattern_check(@check.additional_href_ignores)
when "image"
return true if url.match(/^data:image/)
return true if ignores_pattern_check(@check.additional_alt_ignores)
end
uri = URI.parse url
%w( mailto tel ).include?(uri.scheme)
rescue URI::BadURIError
false
rescue URI::InvalidURIError
false
end
|
#ignores_pattern_check(links) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/html/proofer/checkable.rb', line 127
def ignores_pattern_check(links)
links.each do |ignore|
if ignore.is_a? String
return true if ignore == url
elsif ignore.is_a? Regexp
return true if ignore =~ url
end
end
false
end
|
#internal? ⇒ Boolean
91
92
93
|
# File 'lib/html/proofer/checkable.rb', line 91
def internal?
url[0] == "#"
end
|
#parts ⇒ Object
42
43
44
|
# File 'lib/html/proofer/checkable.rb', line 42
def parts
URI.parse url
end
|
#path ⇒ Object
46
47
48
|
# File 'lib/html/proofer/checkable.rb', line 46
def path
parts.path
end
|
#remote? ⇒ Boolean
path is to an external server
55
56
57
58
59
60
61
62
|
# File 'lib/html/proofer/checkable.rb', line 55
def remote?
uri = URI.parse url
%w( http https ).include?(uri.scheme)
rescue URI::BadURIError
false
rescue URI::InvalidURIError
false
end
|
#url ⇒ Object
30
31
32
|
# File 'lib/html/proofer/checkable.rb', line 30
def url
@src || @href || ""
end
|
#valid? ⇒ Boolean
34
35
36
37
38
39
40
|
# File 'lib/html/proofer/checkable.rb', line 34
def valid?
begin
URI.parse url
rescue
false
end
end
|