Class: Pact::Doc::Markdown::InteractionRenderer
- Inherits:
-
Object
- Object
- Pact::Doc::Markdown::InteractionRenderer
- Defined in:
- lib/pact/doc/markdown/interaction_renderer.rb
Instance Attribute Summary collapse
-
#interaction ⇒ Object
readonly
Returns the value of attribute interaction.
Instance Method Summary collapse
-
#initialize(interaction, pact) ⇒ InteractionRenderer
constructor
A new instance of InteractionRenderer.
- #render(template_file) ⇒ Object
- #render_full_interaction ⇒ Object
- #render_summary ⇒ Object
- #template_contents(template_file) ⇒ Object
-
#template_string(template_file) ⇒ Object
The template file is written with only ASCII range characters, so we can read as UTF-8.
Constructor Details
#initialize(interaction, pact) ⇒ InteractionRenderer
Returns a new instance of InteractionRenderer.
10 11 12 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 10 def initialize interaction, pact @interaction = InteractionViewModel.new(interaction, pact) end |
Instance Attribute Details
#interaction ⇒ Object (readonly)
Returns the value of attribute interaction.
8 9 10 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 8 def interaction @interaction end |
Instance Method Details
#render(template_file) ⇒ Object
23 24 25 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 23 def render template_file ERB.new(template_string(template_file)).result(binding) end |
#render_full_interaction ⇒ Object
19 20 21 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 19 def render_full_interaction render('/interaction.erb') end |
#render_summary ⇒ Object
14 15 16 17 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 14 def render_summary suffix = interaction.has_provider_state? ? " given #{interaction.provider_state}" : "" "* [#{interaction.description(true)}](##{interaction.id})#{suffix}\n\n" end |
#template_contents(template_file) ⇒ Object
35 36 37 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 35 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.
31 32 33 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 31 def template_string(template_file) File.read(template_contents(template_file), external_encoding: Encoding::UTF_8).force_encoding(__ENCODING__) end |