Class: Banzai::Filter::CommitTrailersFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- Banzai::Filter::CommitTrailersFilter
- Includes:
- ActionView::Helpers::TagHelper, AvatarsHelper
- Defined in:
- lib/banzai/filter/commit_trailers_filter.rb
Overview
HTML filter that replaces users' names and emails in commit trailers with links to their GitLab accounts or mailto links to their mentioned emails.
Commit trailers are special labels in the form of `*-by:` and fall on a single line, ex:
Reported-By: John S. Doe <[email protected]>
More info about this can be found here:
Constant Summary collapse
- TRAILER_REGEXP =
/(?<label>[[:alpha:]-]+-by:)/i.freeze
- AUTHOR_REGEXP =
/(?<author_name>.+)/.freeze
- MAIL_REGEXP =
Devise.email_regexp wouldn't work here since its designed to match against strings that only contains email addresses; the A and z around the expression will only match if the string being matched contains just the email nothing else.
/<(?<author_email>[^@\s][email protected][^@\s]+)>/.freeze
- FILTER_REGEXP =
/(?<trailer>^\s*#{TRAILER_REGEXP}\s*#{AUTHOR_REGEXP}\s+#{MAIL_REGEXP}$)/mi.freeze
Instance Method Summary collapse
Methods included from AvatarsHelper
#author_avatar, #avatar_icon_for, #avatar_icon_for_email, #avatar_icon_for_user, #default_avatar, #gravatar_icon, #group_icon, #project_icon, #user_avatar, #user_avatar_without_link
Instance Method Details
#call ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/banzai/filter/commit_trailers_filter.rb', line 29 def call doc.xpath('descendant-or-self::text()').each do |node| content = node.to_html next unless content.match(FILTER_REGEXP) html = trailer_filter(content) next if html == content node.replace(html) end doc end |