Class: RuboCop::Formatter::HTMLFormatter::ERBContext
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/rubocop/formatter/html_formatter.rb |
Overview
This class provides helper methods used in the ERB template.
Constant Summary
-
LOGO_IMAGE_PATH =
# File 'lib/rubocop/formatter/html_formatter.rb', line 67File. ('../../../assets/logo.png', __dir__)
::RuboCop::PathUtil
- Included
Class Method Summary
- .new(files, summary) ⇒ ERBContext constructor
Instance Attribute Summary
Instance Method Summary
- #base64_encoded_logo_image
-
#binding
Make Kernel#binding public.
- #decorated_message(offense)
- #escape(string)
- #highlight_source_tag(offense)
- #highlighted_source_line(offense)
- #possible_ellipses(location)
- #render_css
- #source_after_highlight(offense)
- #source_before_highlight(offense)
::RuboCop::Formatter::TextUtil
- Included
::RuboCop::PathUtil
- Included
#absolute? | Returns true for an absolute Unix or Windows path. |
#glob? | Returns true for a glob. |
#hidden_dir?, #hidden_file?, #hidden_file_in_not_hidden_dir?, | |
#match_path? | Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity. |
#maybe_hidden_file? | Loose check to reduce memory allocations. |
#relative_path, #smart_path |
Constructor Details
.new(files, summary) ⇒ ERBContext
Instance Attribute Details
#files (readonly)
[ GitHub ]# File 'lib/rubocop/formatter/html_formatter.rb', line 69
attr_reader :files, :summary
#summary (readonly)
[ GitHub ]# File 'lib/rubocop/formatter/html_formatter.rb', line 69
attr_reader :files, :summary
Instance Method Details
#base64_encoded_logo_image
[ GitHub ]# 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
#binding
Make Kernel#binding public.
# File 'lib/rubocop/formatter/html_formatter.rb', line 78
def binding super end
#decorated_message(offense)
[ GitHub ]# File 'lib/rubocop/formatter/html_formatter.rb', line 83
def (offense) offense. .gsub(/`(.+?)`/) { "<code>#{escape(Regexp.last_match(1))}</code>" } end
#escape(string)
[ GitHub ]# File 'lib/rubocop/formatter/html_formatter.rb', line 114
def escape(string) CGI.escapeHTML(string) end
#highlight_source_tag(offense)
[ GitHub ]# 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
#highlighted_source_line(offense)
[ GitHub ]# 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
#possible_ellipses(location)
[ GitHub ]# File 'lib/rubocop/formatter/html_formatter.rb', line 110
def possible_ellipses(location) location.single_line? ? '' : " #{ELLIPSES}" end
#render_css
[ GitHub ]# 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_after_highlight(offense)
[ GitHub ]# 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_before_highlight(offense)
[ GitHub ]# 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