Class: HtmlStepOutputter
- Inherits:
-
Object
- Object
- HtmlStepOutputter
- Defined in:
- lib/html_step_outputter.rb
Instance Method Summary collapse
- #close ⇒ Object
- #end_all ⇒ Object
- #end_directory ⇒ Object
- #footer ⇒ Object
-
#header ⇒ Object
HTML file header - customize as needed.
-
#initialize(file) ⇒ HtmlStepOutputter
constructor
A new instance of HtmlStepOutputter.
- #start_all ⇒ Object
- #start_directory(dir) ⇒ Object
- #step(step) ⇒ Object
Constructor Details
#initialize(file) ⇒ HtmlStepOutputter
Returns a new instance of HtmlStepOutputter.
9 10 11 12 13 |
# File 'lib/html_step_outputter.rb', line 9 def initialize(file) @file = File.open(file, 'w') @previous_type = "" @id_number = 0 end |
Instance Method Details
#close ⇒ Object
62 63 64 |
# File 'lib/html_step_outputter.rb', line 62 def close @file.close end |
#end_all ⇒ Object
84 85 86 |
# File 'lib/html_step_outputter.rb', line 84 def end_all # No-op end |
#end_directory ⇒ Object
73 74 75 |
# File 'lib/html_step_outputter.rb', line 73 def end_directory # No-op end |
#footer ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/html_step_outputter.rb', line 51 def @file.puts <<-eos </ul> <p> </p> <p><em>Documentation generated #{Time.now}</em></p> </body> </html> eos end |
#header ⇒ Object
HTML file header - customize as needed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/html_step_outputter.rb', line 16 def header @file.puts <<-eos <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Cucumber step documentation</title> <style> .stepdefs { font-size: smaller; } .stepdefs li { margin-bottom: 0.25em; list-style-type: none; } .stepdefs li:before { content: "\u00BB "; font-size: larger; padding-right: 0.3em; } .stepdef { color: #111; text-decoration: none; } .extrainfo { display: none; overflow: hidden; /* Fixes jumping issue in jQuery slideToggle() */ } </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> </head> <body> eos end |
#start_all ⇒ Object
77 78 79 80 81 82 |
# File 'lib/html_step_outputter.rb', line 77 def start_all @file.puts %(</ul>) @file.puts %(<p> </p>) @file.puts %(<h2>All definitions alphabetically</h2>) @previous_type = "" end |
#start_directory(dir) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/html_step_outputter.rb', line 66 def start_directory(dir) @file.puts %(</ul>) if @previous_type != "" @file.puts %(<p> </p>) @file.puts %(<h2>Step definitions in #{dir}/</h2>) @previous_type = "" end |
#step(step) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/html_step_outputter.rb', line 88 def step(step) if @previous_type != step[:type] @file.puts %(</ul>) if @previous_type != "" @file.puts %(<h3>#{step[:type]} definitions</h3>) @file.puts %(<ul class="stepdefs">) @previous_type = step[:type] end id = new_id @file.puts %(<li>) @file.puts %( <a href="#" onclick="$('##{id}').slideToggle(); return false;" class="stepdef">#{CGI.escapeHTML(step[:name])}</a>) @file.puts %( <div id="#{id}" class="extrainfo">) # TODO: Add link to source repo or Jenkins workspace # <p><a href=".../#{CGI.escapeHTML(step[:filename])}" style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</a></p> @file.puts %( <p style="color: #888;">#{CGI.escapeHTML(step[:filename])}:#{step[:line_number]}</p>) @file.puts %( <pre style="background-color: #ddd; padding-top: 1.2em;">) step[:code].each do |line| @file.puts %( #{CGI.escapeHTML(line)}) end @file.puts %( </pre>) @file.puts %( </div>) @file.puts %(</li>) end |