Class: Pact::Doc::Markdown::InteractionRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/doc/markdown/interaction_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interaction, pact) ⇒ InteractionRenderer

Returns a new instance of InteractionRenderer.



11
12
13
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 11

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

Instance Attribute Details

#interactionObject (readonly)

Returns the value of attribute interaction.



9
10
11
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 9

def interaction
  @interaction
end

Instance Method Details

#h(text) ⇒ Object



40
41
42
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 40

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

#render(template_file) ⇒ Object



24
25
26
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 24

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

#render_full_interactionObject



20
21
22
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 20

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

#render_summaryObject



15
16
17
18
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 15

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

#template_contents(template_file) ⇒ Object



36
37
38
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 36

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

#template_string(template_file) ⇒ Object

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.



32
33
34
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 32

def template_string(template_file)
  File.read(template_contents(template_file), external_encoding: Encoding::UTF_8).force_encoding(__ENCODING__)
end