Class: HTML::Pipeline::HttpsFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/html/pipeline/https_filter.rb

Overview

HTML Filter for replacing http references to :http_url with https versions. Subdomain references are not rewritten.

Context options:

:http_url - The HTTP url to force HTTPS. Falls back to :base_url

Instance Attribute Summary

Attributes inherited from Filter

#context, #result

Instance Method Summary collapse

Methods inherited from Filter

#base_url, call, #current_user, #doc, #has_ancestor?, #html, #initialize, #needs, #parse_html, #repository, #search_text_nodes, to_document, to_html

Constructor Details

This class inherits a constructor from HTML::Pipeline::Filter

Instance Method Details

#callObject



9
10
11
12
13
14
# File 'lib/html/pipeline/https_filter.rb', line 9

def call
  doc.css(%Q(a[href^="#{http_url}"])).each do |element|
    element['href'] = element['href'].sub(/^http:/,'https:')
  end
  doc
end

#http_urlObject

HTTP url to replace. Falls back to :base_url



17
18
19
# File 'lib/html/pipeline/https_filter.rb', line 17

def http_url
  context[:http_url] || context[:base_url]
end

#validateObject

Raise error if :http_url undefined



22
23
24
# File 'lib/html/pipeline/https_filter.rb', line 22

def validate
  needs :http_url unless http_url
end