Sha256: 18ccb99936573bae604d6ed245da7839f05986852d02ecf21205d9b274cf3fb3

Contents?: true

Size: 1.35 KB

Versions: 51

Compression:

Stored size: 1.35 KB

Contents

require 'erb'
require 'pact/doc/interaction_view_model'
require 'rack/utils'

module Pact
  module Doc
    module Markdown
      class InteractionRenderer
        attr_reader :interaction

        def initialize interaction, pact
          @interaction = InteractionViewModel.new(interaction, pact)
        end

        def render_summary
          suffix = interaction.has_provider_state? ? " given #{h(interaction.provider_state)}" : ""
          "* [#{h(interaction.description(true))}](##{interaction.id})#{suffix}\n\n"
        end

        def render_full_interaction
          render('/interaction.erb')
        end

        def render template_file
          ERB.new(template_string(template_file)).result(binding)
        end

        # The template file is written with only ASCII range characters, so we
        # can read as UTF-8. But rendered strings must have same encoding as
        # script encoding because it will joined to strings which are produced by
        # string literal.
        def template_string(template_file)
          File.read(template_contents(template_file), external_encoding: Encoding::UTF_8).force_encoding(__ENCODING__)
        end

        def template_contents(template_file)
          File.dirname(__FILE__) + template_file
        end

        def h(text)
          Rack::Utils.escape_html(text)
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
pact_broker-2.68.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.68.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.67.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.66.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.65.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.64.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.63.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.62.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.61.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.60.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.60.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.59.2 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.59.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.59.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.58.3 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.58.2 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.58.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.57.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.56.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.56.0 lib/pact/doc/markdown/interaction_renderer.rb