Class: RuboCop::Formatter::HTMLFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- RuboCop::Formatter::HTMLFormatter
- Defined in:
- lib/rubocop/formatter/html_formatter.rb
Overview
This formatter saves the output as a html file.
Defined Under Namespace
Classes: Color, ERBContext
Constant Summary collapse
- TEMPLATE_PATH =
File.('../../../../assets/output.html.erb', __FILE__)
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #file_finished(file, offenses) ⇒ Object
- #finished(inspected_files) ⇒ Object
-
#initialize(output) ⇒ HTMLFormatter
constructor
A new instance of HTMLFormatter.
- #render_html ⇒ Object
- #started(target_files) ⇒ Object
Methods inherited from BaseFormatter
Constructor Details
#initialize(output) ⇒ HTMLFormatter
Returns a new instance of HTMLFormatter.
17 18 19 20 21 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 17 def initialize(output) super @files = [] @summary = OpenStruct.new(offense_count: 0) end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
15 16 17 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 15 def files @files end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
15 16 17 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 15 def summary @summary end |
Instance Method Details
#file_finished(file, offenses) ⇒ Object
27 28 29 30 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 27 def file_finished(file, offenses) files << OpenStruct.new(path: file, offenses: offenses) summary.offense_count += offenses.count end |
#finished(inspected_files) ⇒ Object
32 33 34 35 36 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 32 def finished(inspected_files) summary.inspected_files = inspected_files render_html end |
#render_html ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 38 def render_html context = ERBContext.new(files, summary) template = File.read(TEMPLATE_PATH) erb = ERB.new(template, nil, '-') html = erb.result(context.binding) output.write html end |
#started(target_files) ⇒ Object
23 24 25 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 23 def started(target_files) summary.target_files = target_files end |