Class: RuboCop::Formatter::HTMLFormatter Private
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- RuboCop::Formatter::HTMLFormatter
- Defined in:
- lib/rubocop/formatter/html_formatter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This formatter saves the output as an html file.
Defined Under Namespace
Classes: Color, ERBContext, FileOffenses, Summary
Constant Summary collapse
- ELLIPSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'<span class="extra-code">...</span>'- TEMPLATE_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File.('../../../assets/output.html.erb', __dir__)
Instance Attribute Summary collapse
- #files ⇒ Object readonly private
- #summary ⇒ Object readonly private
Attributes inherited from BaseFormatter
Instance Method Summary collapse
- #file_finished(file, offenses) ⇒ Object private
- #finished(inspected_files) ⇒ Object private
-
#initialize(output, options = {}) ⇒ HTMLFormatter
constructor
private
A new instance of HTMLFormatter.
- #render_html ⇒ Object private
- #started(target_files) ⇒ Object private
Methods inherited from BaseFormatter
Constructor Details
#initialize(output, options = {}) ⇒ HTMLFormatter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HTMLFormatter.
30 31 32 33 34 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 30 def initialize(output, = {}) super @files = [] @summary = Summary.new(offense_count: 0) end |
Instance Attribute Details
#files ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 28 def files @files end |
#summary ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 28 def summary @summary end |
Instance Method Details
#file_finished(file, offenses) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 40 def file_finished(file, offenses) files << FileOffenses.new(path: file, offenses: offenses) summary.offense_count += offenses.count end |
#finished(inspected_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 45 def finished(inspected_files) summary.inspected_files = inspected_files render_html end |
#render_html ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 51 def render_html context = ERBContext.new(files, summary) template = File.read(TEMPLATE_PATH, encoding: Encoding::UTF_8) erb = ERB.new(template, trim_mode: '-') html = erb.result(context.binding) output.write html end |
#started(target_files) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 36 def started(target_files) summary.target_files = target_files end |