Class: RuboCop::Formatter::HTMLFormatter::ERBContext
- Inherits:
-
Object
- Object
- RuboCop::Formatter::HTMLFormatter::ERBContext
- Defined in:
- lib/rubocop/formatter/html_formatter.rb
Overview
This class provides helper methods used in the ERB template.
Constant Summary collapse
- SEVERITY_COLORS =
{ refactor: Color.new(0xED, 0x9C, 0x28, 1.0), convention: Color.new(0xED, 0x9C, 0x28, 1.0), warning: Color.new(0x96, 0x28, 0xEF, 1.0), error: Color.new(0xD2, 0x32, 0x2D, 1.0), fatal: Color.new(0xD2, 0x32, 0x2D, 1.0) }.freeze
- LOGO_IMAGE_PATH =
File.('../../../../assets/logo.png', __FILE__)
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Instance Method Summary collapse
- #base64_encoded_logo_image ⇒ Object
-
#binding ⇒ Object
Make Kernel#binding public.
- #decorated_message(offense) ⇒ Object
- #escape(s) ⇒ Object
- #highlighted_source_line(offense) ⇒ Object
-
#initialize(files, summary) ⇒ ERBContext
constructor
A new instance of ERBContext.
Methods included from PathUtil
absolute?, hidden?, issue_deprecation_warning, match_path?, relative_path
Methods included from TextUtil
Constructor Details
#initialize(files, summary) ⇒ ERBContext
Returns a new instance of ERBContext.
79 80 81 82 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 79 def initialize(files, summary) @files = files.sort_by(&:path) @summary = summary end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
77 78 79 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 77 def files @files end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
77 78 79 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 77 def summary @summary end |
Instance Method Details
#base64_encoded_logo_image ⇒ Object
118 119 120 121 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 118 def base64_encoded_logo_image image = File.read(LOGO_IMAGE_PATH, binmode: true) Base64.encode64(image) end |
#binding ⇒ Object
Make Kernel#binding public.
85 86 87 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 85 def binding super end |
#decorated_message(offense) ⇒ Object
89 90 91 92 93 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 89 def (offense) offense..gsub(/`(.+?)`/) do "<code>#{Regexp.last_match(1)}</code>" end end |
#escape(s) ⇒ Object
113 114 115 116 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 113 def escape(s) # Single quotes not escaped in Ruby 1.9, so add extra substitution. CGI.escapeHTML(s).gsub(/'/, ''') end |
#highlighted_source_line(offense) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 95 def highlighted_source_line(offense) location = offense.location column_range = if location.begin.line == location.end.line location.column_range else location.column...location.source_line.length end source_line = location.source_line escape(source_line[0...column_range.begin]) + "<span class=\"highlight #{offense.severity}\">" + escape(source_line[column_range]) + '</span>' + escape(source_line[column_range.end..-1]) end |