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
- #h(text) ⇒ Object
-
#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.
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
#interaction ⇒ Object (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
41 42 43 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 41 def h(text) Rack::Utils.escape_html(text) end |
#render(template_file) ⇒ Object
25 26 27 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 25 def render template_file ERB.new(template_string(template_file)).result(binding) end |
#render_full_interaction ⇒ Object
21 22 23 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 21 def render_full_interaction render("/interaction.erb") end |
#render_summary ⇒ Object
15 16 17 18 19 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 15 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 |
#template_contents(template_file) ⇒ Object
37 38 39 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 37 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.
33 34 35 |
# File 'lib/pact/doc/markdown/interaction_renderer.rb', line 33 def template_string(template_file) File.read(template_contents(template_file), external_encoding: Encoding::UTF_8).force_encoding(__ENCODING__) end |