Sha256: e6155dc90da76928604a3575fd1246ca2279596a45632cfd00088ef73f30b951

Contents?: true

Size: 799 Bytes

Versions: 11

Compression:

Stored size: 799 Bytes

Contents

# frozen_string_literal: true

require "selma"

class HTMLPipeline
  class NodeFilter < Filter
    def initialize(context: {}, result: {})
      super(context: context, result: {})
      send(:after_initialize) if respond_to?(:after_initialize)
    end

    # The String representation of the document.
    def html
      raise InvalidDocumentException if @html.nil? && @doc.nil?

      @html || doc.to_html
    end

    def reset!
      result = {} # rubocop:disable Lint/UselessAssignment
      send(:after_initialize) if respond_to?(:after_initialize)
    end

    class << self
      def call(html, context: {}, result: {})
        node_filter = new(context: context, result: result)
        Selma::Rewriter.new(sanitizer: nil, handlers: [node_filter]).rewrite(html)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
html-pipeline-3.1.1 lib/html_pipeline/node_filter.rb
html-pipeline-3.1.0 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.3 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.2 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.1 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0.pre6 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0.pre5 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0.pre3 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0.pre2 lib/html_pipeline/node_filter.rb
html-pipeline-3.0.0.pre1 lib/html_pipeline/node_filter.rb