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', __dir__)
Constants included from PathUtil
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
rubocop:enable Lint/UselessMethodDefinition.
- #escape(string) ⇒ Object
- #highlight_source_tag(offense) ⇒ Object
- #highlighted_source_line(offense) ⇒ Object
-
#initialize(files, summary) ⇒ ERBContext
constructor
A new instance of ERBContext.
- #possible_ellipses(location) ⇒ Object
- #source_after_highlight(offense) ⇒ Object
- #source_before_highlight(offense) ⇒ Object
Methods included from TextUtil
Methods included from PathUtil
absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, smart_path
Constructor Details
#initialize(files, summary) ⇒ ERBContext
Returns a new instance of ERBContext.
77 78 79 80 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 77 def initialize(files, summary) @files = files.sort_by(&:path) @summary = summary end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
75 76 77 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 75 def files @files end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
75 76 77 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 75 def summary @summary end |
Instance Method Details
#base64_encoded_logo_image ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 124 def base64_encoded_logo_image image = File.read(LOGO_IMAGE_PATH, binmode: true) # `Base64.encode64` compatible: # https://github.com/ruby/base64/blob/v0.1.1/lib/base64.rb#L27-L40 [image].pack('m') end |
#binding ⇒ Object
Make Kernel#binding public. rubocop:disable Lint/UselessMethodDefinition
84 85 86 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 84 def binding super end |
#decorated_message(offense) ⇒ Object
rubocop:enable Lint/UselessMethodDefinition
89 90 91 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 89 def (offense) offense..gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" } end |
#escape(string) ⇒ Object
120 121 122 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 120 def escape(string) CGI.escapeHTML(string) end |
#highlight_source_tag(offense) ⇒ Object
100 101 102 103 104 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 100 def highlight_source_tag(offense) "<span class=\"highlight #{offense.severity}\">" \ "#{escape(offense.highlighted_area.source)}" \ '</span>' end |
#highlighted_source_line(offense) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 93 def highlighted_source_line(offense) source_before_highlight(offense) + highlight_source_tag(offense) + source_after_highlight(offense) + possible_ellipses(offense.location) end |
#possible_ellipses(location) ⇒ Object
116 117 118 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 116 def possible_ellipses(location) location.single_line? ? '' : " #{ELLIPSES}" end |
#source_after_highlight(offense) ⇒ Object
111 112 113 114 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 111 def source_after_highlight(offense) source_line = offense.location.source_line escape(source_line[offense.highlighted_area.end_pos..]) end |
#source_before_highlight(offense) ⇒ Object
106 107 108 109 |
# File 'lib/rubocop/formatter/html_formatter.rb', line 106 def source_before_highlight(offense) source_line = offense.location.source_line escape(source_line[0...offense.highlighted_area.begin_pos]) end |