class RuboCop::Formatter::HTMLFormatter::ERBContext

This class provides helper methods used in the ERB template.

Constants

LOGO_IMAGE_PATH
SEVERITY_COLORS

Attributes

files[R]
summary[R]

Public Class Methods

new(files, summary) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 79
def initialize(files, summary)
  @files = files.sort_by(&:path)
  @summary = summary
end

Public Instance Methods

base64_encoded_logo_image() click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 116
def base64_encoded_logo_image
  image = File.read(LOGO_IMAGE_PATH, binmode: true)
  Base64.encode64(image)
end
binding() click to toggle source

Make Kernel#binding public.

Calls superclass method
# File lib/rubocop/formatter/html_formatter.rb, line 85
def binding
  super
end
decorated_message(offense) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 89
def decorated_message(offense)
  offense.message.gsub(/`(.+?)`/) do
    "<code>#{Regexp.last_match(1)}</code>"
  end
end
escape(s) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 111
def escape(s)
  # Single quotes not escaped in Ruby 1.9, so add extra substitution.
  CGI.escapeHTML(s).gsub(/'/, '&#39;')
end
highlighted_source_line(offense) click to toggle source
# File lib/rubocop/formatter/html_formatter.rb, line 95
def highlighted_source_line(offense)
  location = offense.location

  source_line = if location.first_line == location.last_line
                  location.source_line
                else
                  "#{location.source_line} #{ELLIPSES}"
                end

  escape(source_line[0...offense.highlighted_area.begin_pos]) +
    "<span class=\"highlight #{offense.severity}\">" +
    escape(offense.highlighted_area.source) +
    '</span>' +
    escape(source_line[offense.highlighted_area.end_pos..-1])
end