class Fastlane::Helper::SlackBotLinkFormatterHelper
Fastlane
is moving away 'slack-notifier' gem, github.com/fastlane/fastlane/pull/18512 Duplicate of: github.com/stevenosloan/slack-notifier/blob/master/lib/slack-notifier/util/link_formatter.rb
Constants
- HTML_PATTERN
- MARKDOWN_PATTERN
Attempt at only matching pairs of parens per the markdown spec spec.commonmark.org/0.27/#links
- VALID_PATH_CHARS
the path portion of a url can contain these characters
Attributes
formats[R]
Public Class Methods
format(string, opts={})
click to toggle source
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 34 def format string, opts={} SlackBotLinkFormatterHelper.new(string, **opts).formatted end
new(string, opts = {})
click to toggle source
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 41 def initialize string, opts = {} @formats = opts[:formats] || %i[html markdown] @orig = string.respond_to?(:scrub) ? string.scrub : string end
Public Instance Methods
formatted()
click to toggle source
rubocop:disable Lint/RescueWithoutErrorClass
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 47 def formatted return @orig unless @orig.respond_to?(:gsub) sub_markdown_links(sub_html_links(@orig)) rescue => e raise e unless RUBY_VERSION < "2.1" && e.message.include?("invalid byte sequence") raise e, "#{e.message}. Consider including the 'string-scrub' gem to strip invalid characters" end
Private Instance Methods
slack_link(link, text=nil)
click to toggle source
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 75 def slack_link link, text=nil "<#{link}" \ "#{text && !text.empty? ? "|#{text}" : ''}" \ ">" end
sub_html_links(string)
click to toggle source
rubocop:enable Lint/RescueWithoutErrorClass
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 59 def sub_html_links string return string unless formats.include?(:html) string.gsub(HTML_PATTERN) do slack_link Regexp.last_match[1], Regexp.last_match[2] end end
sub_markdown_links(string)
click to toggle source
# File lib/fastlane/plugin/slack_bot/helper/slack_bot_link_formatter_helper.rb, line 67 def sub_markdown_links string return string unless formats.include?(:markdown) string.gsub(MARKDOWN_PATTERN) do slack_link Regexp.last_match[2], Regexp.last_match[1] end end