Sha256: 5cd2e44b70e54f5794fa4cdd3d31aa5eec8b0b0dde9a049b1cf57b5d9ba4c3d3
Contents?: true
Size: 1.18 KB
Versions: 9
Compression:
Stored size: 1.18 KB
Contents
module Trickster module Renderer class CommandlineRenderer def render(io,content,options) io.print "<pre><code class='no-highlight'>" content = split_by_commands_and_results(content) content.each do |(prompt,command,result)| io.puts "<span class='cli-prompt'>#{prompt}</span> <span class='cli-element cli-command cli-line'>#{command}</span>" unless result.empty? io.puts "<span class='cli-element cli-result'>#{result.join("\n")}</span>" end end io.puts "</code></pre>" end private def split_by_commands_and_results(content) results = [] current_command_response = [] content.each do |line| if line =~ /^([>%#])(.*)$/ prompt = $1 command = $2 results << current_command_response unless current_command_response.empty? current_command_response = [prompt.gsub(">",">"),command,[]] else current_command_response[2] << "<span class='cli-line'>#{line}</span>" end end results << current_command_response unless current_command_response.empty? end end end end
Version data entries
9 entries across 9 versions & 1 rubygems