Sha256: 81d2fe3c621664ab757959de5534a053590659c02d1e6fb1a9d3e44b1df19953

Contents?: true

Size: 1.19 KB

Versions: 54

Compression:

Stored size: 1.19 KB

Contents

module HTML
  class Pipeline
    # Public: Runs a String of content through an HTML processing pipeline,
    # providing easy access to a generated DocumentFragment.
    class BodyContent
      attr_reader :result

      # Public: Initialize a BodyContent.
      #
      # body     - A String body.
      # context  - A Hash of context options for the filters.
      # pipeline - A HTML::Pipeline object with one or more Filters.
      def initialize(body, context, pipeline)
        @body = body
        @context = context
        @pipeline = pipeline
      end

      # Public: Gets the memoized result of the body content as it passed through
      # the Pipeline.
      #
      # Returns a Hash, or something similar as defined by @pipeline.result_class.
      def result
        @result ||= @pipeline.call @body, @context
      end

      # Public: Gets the updated body from the Pipeline result.
      #
      # Returns a String or DocumentFragment.
      def output
        @output ||= result[:output]
      end

      # Public: Parses the output into a DocumentFragment.
      #
      # Returns a DocumentFragment.
      def document
        @document ||= HTML::Pipeline.parse output
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 3 rubygems

Version Path
html-pipeline-0.2.0 lib/html/pipeline/body_content.rb
html-pipeline-0.1.0 lib/html/pipeline/body_content.rb
html-pipeline-0.0.14 lib/html/pipeline/body_content.rb
html-pipeline-0.0.13 lib/html/pipeline/body_content.rb
geothird-html-pipeline-0.0.12 lib/html/pipeline/body_content.rb
html-pipeline-0.0.12 lib/html/pipeline/body_content.rb
html-pipeline-0.0.11 lib/html/pipeline/body_content.rb
html-pipeline-0.0.10 lib/html/pipeline/body_content.rb
html-pipeline-0.0.8 lib/html/pipeline/body_content.rb
html-pipeline-0.0.7 lib/html/pipeline/body_content.rb
html-pipeline-no-charlock-0.0.6 lib/html/pipeline/body_content.rb
html-pipeline-0.0.6 lib/html/pipeline/body_content.rb
html-pipeline-0.0.5 lib/html/pipeline/body_content.rb
html-pipeline-0.0.4 lib/html/pipeline/body_content.rb