Sha256: 27cd2ec2c694929ef9f4e7f7015d4f89e997987d23f73455038354affc97cc65

Contents?: true

Size: 731 Bytes

Versions: 11

Compression:

Stored size: 731 Bytes

Contents

module HTML
  class Pipeline
    # 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
    class HttpsFilter < Filter
      def call
        doc.css(%(a[href^="#{http_url}"])).each do |element|
          element['href'] = element['href'].sub(/^http:/, 'https:')
        end
        doc
      end

      # HTTP url to replace. Falls back to :base_url
      def http_url
        context[:http_url] || context[:base_url]
      end

      # Raise error if :http_url undefined
      def validate
        needs :http_url unless http_url
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
html-pipeline-2.11.0 lib/html/pipeline/https_filter.rb
html-pipeline-2.10.0 lib/html/pipeline/https_filter.rb
html-pipeline-2.9.2 lib/html/pipeline/https_filter.rb
html-pipeline-2.9.1 lib/html/pipeline/https_filter.rb
html-pipeline-2.9.0 lib/html/pipeline/https_filter.rb
html-pipeline-2.8.4 lib/html/pipeline/https_filter.rb
html-pipeline-2.8.3 lib/html/pipeline/https_filter.rb
html-pipeline-2.8.2 lib/html/pipeline/https_filter.rb
html-pipeline-2.8.1 lib/html/pipeline/https_filter.rb
html-pipeline-2.8.0 lib/html/pipeline/https_filter.rb
html-pipeline-2.7.2 lib/html/pipeline/https_filter.rb