class Parade::Renderers::CommandLineRenderer
Slides that have been marked as ‘commandline’ will be processed here to ensure that the command portion is played out as if typed. Followed by the result which appears after the command is completed.
@example Slide
marker to denote a command-line slide
!SLIDE commandline incremental
To denote the command, it needs to be prefaced with a ‘$`. The remaining code is considered to be the result.
@example Contents of a slide to show a command and a result
```bash $ git commit -am 'incremental bullet points working' [master ac5fd8a] incremental bullet points working 2 files changed, 32 insertions(+), 5 deletions(-) ```
Public Class Methods
render(html_content)
click to toggle source
@param [String] html_content the html content of a single slide that
will have the commandline rendered correctly if it is a class on the slide.
@return [String] the same html content if there is no commandline class
or the new rendered html content with the new required HTML elements.
# File lib/parade/renderers/command_line_renderer.rb, line 36 def self.render(html_content) html = Nokogiri::HTML.fragment(html_content) parser = CommandlineParser.new html.css('.commandline pre').each do |code| out = code.text code.content = '' tree = parser.parse(out) transform = Parslet::Transform.new do rule(:prompt => simple(:prompt), :input => simple(:input), :output => simple(:output)) do command = Nokogiri::XML::Node.new('pre', html) command.set_attribute('class', 'command') node_prompt = Nokogiri::XML::Node.new('span', html) # The 'nv' class specifically gives it the same code syntax highlighting node_prompt.set_attribute('class','prompt nv') node_prompt.content = prompt separator = Nokogiri::XML::Text.new(' ',html) node_input = Nokogiri::XML::Node.new('span',html) node_input.content = input # The 'nb' class specifically gives it the same syntax highlighting node_input.set_attribute('class','input nb') command << node_prompt command << separator command << node_input code << command # Add newline after the input so that users can # advance faster than the typewriter effect # and still keep inputs on separate lines. code << "\n" unless output.to_s.empty? result = Nokogiri::XML::Node.new('pre', html) result.set_attribute('class', 'result') result.content = output code << result end end end transform.apply(tree) end html.to_s end