Class: Grell::Page::VisitedPage::Link
- Inherits:
-
Object
- Object
- Grell::Page::VisitedPage::Link
- Defined in:
- lib/grell/page.rb
Overview
Private class to group all the methods related to links.
Instance Method Summary collapse
-
#disabled? ⇒ Boolean
Is the link disabled by either Javascript or CSS?.
-
#href ⇒ Object
Some links may use data-href + javascript to do interesting things.
-
#initialize(anchor) ⇒ Link
constructor
A new instance of Link.
-
#inside_header? ⇒ Boolean
<link> can only be used in the <head> as of: developer.mozilla.org/en/docs/Web/HTML/Element/link.
-
#js_href? ⇒ Boolean
Does the href use javascript?.
-
#to_url(host) ⇒ Object
We only accept links in this same host that start with a path.
Constructor Details
#initialize(anchor) ⇒ Link
Returns a new instance of Link.
221 222 223 |
# File 'lib/grell/page.rb', line 221 def initialize(anchor) @anchor = anchor end |
Instance Method Details
#disabled? ⇒ Boolean
Is the link disabled by either Javascript or CSS?
231 232 233 |
# File 'lib/grell/page.rb', line 231 def disabled? @anchor.disabled? || !!@anchor.native.attributes['disabled'] end |
#href ⇒ Object
Some links may use data-href + javascript to do interesting things
241 242 243 |
# File 'lib/grell/page.rb', line 241 def href @anchor['href'] || @anchor['data-href'] end |
#inside_header? ⇒ Boolean
<link> can only be used in the <head> as of: developer.mozilla.org/en/docs/Web/HTML/Element/link
226 227 228 |
# File 'lib/grell/page.rb', line 226 def inside_header? @anchor.tag_name == 'link' end |
#js_href? ⇒ Boolean
Does the href use javascript?
236 237 238 |
# File 'lib/grell/page.rb', line 236 def js_href? href.start_with?('javascript:') end |
#to_url(host) ⇒ Object
We only accept links in this same host that start with a path
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/grell/page.rb', line 246 def to_url(host) uri = URI.parse(href) if uri.absolute? if uri.host != URI.parse(host).host Grell.logger.debug "GRELL does not follow links to external hosts: #{href}" nil else href # Absolute link to our own host end else if uri.path.nil? Grell.logger.debug "GRELL does not follow links without a path: #{uri}" nil end if uri.path.start_with?('/') host + href # convert to full URL else # links like href="google.com" the browser would go to http://google.com like "http://#{link}" Grell.logger.debug "GRELL Bad formatted link: #{href}, assuming external" nil end end rescue URI::InvalidURIError # Invalid links propagating till we navigate to them href end |