Class: RSpecDocumentation::HtmlElement
- Inherits:
-
Object
- Object
- RSpecDocumentation::HtmlElement
- Defined in:
- lib/rspec_documentation/html_element.rb
Overview
Receives a spec manifest and generates a ‘Kramdown::Document` contaning an HTML node with a tabbed view displaying the example’s code, its output and, if format is ‘:html`, the rendered HTML of the output. Injected into the parsed `Kramdown::Document` for the root Markdown file, replacing the code block it was produced from.
Instance Method Summary collapse
- #code_source ⇒ Object
- #element ⇒ Object
- #element_id ⇒ Object
-
#initialize(spec:) ⇒ HtmlElement
constructor
A new instance of HtmlElement.
- #prettified_output ⇒ Object
- #render_raw? ⇒ Boolean
- #rendered_output ⇒ Object
Constructor Details
#initialize(spec:) ⇒ HtmlElement
Returns a new instance of HtmlElement.
9 10 11 |
# File 'lib/rspec_documentation/html_element.rb', line 9 def initialize(spec:) @spec = spec end |
Instance Method Details
#code_source ⇒ Object
17 18 19 20 21 |
# File 'lib/rspec_documentation/html_element.rb', line 17 def code_source formatter = Rouge::Formatters::HTML.new lexer = Rouge::Lexers::Ruby.new Formatters.with_translated_html_entities(formatter.format(lexer.lex(spec.source))) end |
#element ⇒ Object
13 14 15 |
# File 'lib/rspec_documentation/html_element.rb', line 13 def element Kramdown::Document.new(tabbed_spec, input: 'html').root end |
#element_id ⇒ Object
37 38 39 |
# File 'lib/rspec_documentation/html_element.rb', line 37 def element_id @element_id ||= SecureRandom.uuid end |
#prettified_output ⇒ Object
23 24 25 |
# File 'lib/rspec_documentation/html_element.rb', line 23 def prettified_output Formatters.with_translated_html_entities(formatter.prettified_output) end |
#render_raw? ⇒ Boolean
33 34 35 |
# File 'lib/rspec_documentation/html_element.rb', line 33 def render_raw? formatter.render_raw? end |
#rendered_output ⇒ Object
27 28 29 30 31 |
# File 'lib/rspec_documentation/html_element.rb', line 27 def rendered_output return formatter.rendered_output if render_raw? Formatters.with_translated_html_entities(formatter.rendered_output) end |