Sha256: 2d1d4fc92ee45655badec090447547dc8ad47d4bd2873a6ad2e135a65a9866c2

Contents?: true

Size: 1.25 KB

Versions: 91

Compression:

Stored size: 1.25 KB

Contents

require 'erb'
require 'pact/doc/interaction_view_model'

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 #{interaction.provider_state}" : ""
          "* [#{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

      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
pact-1.30.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.29.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.28.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.28.0.rc1 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.27.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.26.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.25.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.24.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.23.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.22.2 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.22.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.21.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.20.1 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.20.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.19.2 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.19.1 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.19.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.18.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.17.0 lib/pact/doc/markdown/interaction_renderer.rb
pact-1.16.1 lib/pact/doc/markdown/interaction_renderer.rb