Sha256: 1e7098ac44c120c929113f39b2f4c3ff0d9919519fa1a76a4249fa8878f9ef13

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

require 'rhet-butler/stasis/document-transform'
module RhetButler
  module Stasis
    require 'nokogiri'
    class HTMLTransform < DocumentTransform
      register "text/html"

      NAV_AND_EMBED = %w[
        //a/@href
        //applet/@codebase
        //area/@href
        //base/@href
        //body/@background
        //frame/@longdesc
        //frame/@src
        //iframe/@longdesc
        //iframe/@src
        //img/@longdesc
        //img/@src
        //input/@src
        //link/@href
        //object/@codebase
        //object/@data
        //script/@src
        //audio/@src
        //command/@icon
        //embed/@src
        //html/@manifest
        //source/@src
        //video/@poster
        //video/@src
      ]

      def parse_document
        @parsed = Nokogiri::HTML(document.body)
      end

      def translate_links
        NAV_AND_EMBED.each do |xpath|
          @parsed.xpath(xpath).each do |attr|
            attr.value = get_link_translation(attr.value)
          end
        end
      end

      def render_document
        @parsed.to_html
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rhet-butler-0.14.1 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.14.0 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.13.0 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.12.1 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.11.1 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.11.0 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.10.0 lib/rhet-butler/stasis/html-transform.rb
rhet-butler-0.9.0 lib/rhet-butler/stasis/html-transform.rb