Class: Fastlane::Notification::Slack::LinkConverter
- Inherits:
-
Object
- Object
- Fastlane::Notification::Slack::LinkConverter
- Defined in:
- fastlane/lib/fastlane/notification/slack.rb
Overview
This class was inspired by ‘LinkFormatter` in `slack-notifier` gem github.com/stevenosloan/slack-notifier/blob/4bf6582663dc9e5070afe3fdc42d67c14a513354/lib/slack-notifier/util/link_formatter.rb
Constant Summary collapse
- HTML_PATTERN =
%r{<a.*?href=['"](?<link>#{URI.regexp})['"].*?>(?<label>.+?)<\/a>}
- MARKDOWN_PATTERN =
/\[(?<label>[^\[\]]*?)\]\((?<link>#{URI.regexp}|mailto:#{URI::MailTo::EMAIL_REGEXP})\)/
Class Method Summary collapse
- .convert(string) ⇒ Object
- .convert_html_to_slack_link(string) ⇒ Object
- .convert_markdown_to_slack_link(string) ⇒ Object
- .slack_link(href, text) ⇒ Object
Class Method Details
.convert(string) ⇒ Object
34 35 36 |
# File 'fastlane/lib/fastlane/notification/slack.rb', line 34 def self.convert(string) convert_markdown_to_slack_link(convert_html_to_slack_link(string.scrub)) end |
.convert_html_to_slack_link(string) ⇒ Object
38 39 40 41 42 |
# File 'fastlane/lib/fastlane/notification/slack.rb', line 38 def self.convert_html_to_slack_link(string) string.gsub(HTML_PATTERN) do |match| slack_link(Regexp.last_match[:link], Regexp.last_match[:label]) end end |
.convert_markdown_to_slack_link(string) ⇒ Object
44 45 46 47 48 |
# File 'fastlane/lib/fastlane/notification/slack.rb', line 44 def self.convert_markdown_to_slack_link(string) string.gsub(MARKDOWN_PATTERN) do |match| slack_link(Regexp.last_match[:link], Regexp.last_match[:label]) end end |
.slack_link(href, text) ⇒ Object
50 51 52 53 |
# File 'fastlane/lib/fastlane/notification/slack.rb', line 50 def self.slack_link(href, text) return "<#{href}>" if text.nil? || text.empty? "<#{href}|#{text}>" end |