Class: HtmlStepOutputter

Inherits:
Object
  • Object
show all
Defined in:
lib/html_step_outputter.rb

Instance Method Summary collapse

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

#closeObject



61
62
63
# File 'lib/html_step_outputter.rb', line 61

def close
  @file.close
end

#end_allObject



83
84
85
# File 'lib/html_step_outputter.rb', line 83

def end_all
  # No-op
end

#end_directoryObject



72
73
74
# File 'lib/html_step_outputter.rb', line 72

def end_directory
  # No-op
end


51
52
53
54
55
56
57
58
59
# File 'lib/html_step_outputter.rb', line 51

def footer
  @file.puts <<-eos
    </ul>
    <p>&nbsp;</p>
    <p><em>Documentation generated #{Time.now}</em></p>
    </body>
    </html>
  eos
end

#headerObject

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_allObject



76
77
78
79
80
81
# File 'lib/html_step_outputter.rb', line 76

def start_all
  @file.puts %(</ul>)
  @file.puts %(<p>&nbsp;</p>)
  @file.puts %(<h2>All definitions alphabetically</h2>)
  @previous_type = ""
end

#start_directory(dir) ⇒ Object



65
66
67
68
69
70
# File 'lib/html_step_outputter.rb', line 65

def start_directory(dir)
  @file.puts %(</ul>) if @previous_type != ""
  @file.puts %(<p>&nbsp;</p>)
  @file.puts %(<h2>Step definitions in #{dir}/</h2>)
  @previous_type = ""
end

#step(step) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/html_step_outputter.rb', line 87

def step(step)
  if @previous_type != step[:filename]
    @file.puts %(</ul>) if @previous_type != ""
    @file.puts %(<h3>#{step[:filename]}</h3>)
    @file.puts %(<ul class="stepdefs">)
    @previous_type = step[:filename]
  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