Sha256: 75c566368dabdd10f4dce8537a40e767ad8060a84bb0cdfc7e90ee4c64457f79

Contents?: true

Size: 1.42 KB

Versions: 44

Compression:

Stored size: 1.42 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
          formatted_provider_states = h(interaction.formatted_provider_states)
          suffix = formatted_provider_states.empty? ? "" : " given #{formatted_provider_states}"
          "* [#{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

44 entries across 44 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.111.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.109.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.109.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.108.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.107.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.107.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.107.0.beta.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.106.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.105.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.104.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.103.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.102.2 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.102.1 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.102.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.101.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.100.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.99.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.98.0 lib/pact/doc/markdown/interaction_renderer.rb
pact_broker-2.97.0 lib/pact/doc/markdown/interaction_renderer.rb