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, to_document, to_html

Constructor Details

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

Instance Method Details

#callObject


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

def call
  doc.css(%(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


19
20
21
# File 'lib/html/pipeline/https_filter.rb', line 19

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

#validateObject

Raise error if :http_url undefined


24
25
26
# File 'lib/html/pipeline/https_filter.rb', line 24

def validate
  needs :http_url unless http_url
end