class RuboCop::Formatter::HTMLFormatter::ERBContext
This class provides helper methods used in the ERB template.
Constants
- LOGO_IMAGE_PATH
Attributes
Public Class Methods
Source
# File lib/rubocop/formatter/html_formatter.rb, line 71 def initialize(files, summary) @files = files.sort_by(&:path) @summary = summary end
Public Instance Methods
Source
# File lib/rubocop/formatter/html_formatter.rb, line 118 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
Source
# File lib/rubocop/formatter/html_formatter.rb, line 78 def binding super end
Make Kernel#binding public. rubocop:disable Lint/UselessMethodDefinition
Calls superclass method
Source
# File lib/rubocop/formatter/html_formatter.rb, line 83 def decorated_message(offense) offense.message.gsub(/`(.+?)`/) { "<code>#{escape(Regexp.last_match(1))}</code>" } end
rubocop:enable Lint/UselessMethodDefinition
Source
# File lib/rubocop/formatter/html_formatter.rb, line 114 def escape(string) CGI.escapeHTML(string) end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 94 def highlight_source_tag(offense) "<span class=\"highlight #{offense.severity}\">" \ "#{escape(offense.highlighted_area.source)}" \ '</span>' end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 87 def highlighted_source_line(offense) source_before_highlight(offense) + highlight_source_tag(offense) + source_after_highlight(offense) + possible_ellipses(offense.location) end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 110 def possible_ellipses(location) location.single_line? ? '' : " #{ELLIPSES}" end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 126 def render_css context = CSSContext.new template = File.read(CSS_PATH, encoding: Encoding::UTF_8) erb = ERB.new(template, trim_mode: '-') erb.result(context.binding).lines.map do |line| line == "\n" ? line : " #{line}" end.join end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 105 def source_after_highlight(offense) source_line = offense.location.source_line escape(source_line[offense.highlighted_area.end_pos..]) end
Source
# File lib/rubocop/formatter/html_formatter.rb, line 100 def source_before_highlight(offense) source_line = offense.location.source_line escape(source_line[0...offense.highlighted_area.begin_pos]) end