Module: Slack::BlockKit::Formatting
Overview
Formatting contains some utility functions to help formatting text
Constant Summary collapse
- DATE_FORMAT_TOKENS =
- [ # 2014-02-18 DATE_NUM = '{date_num}', # February 18th, 2014 DATE = '{date}', # Feb 18, 2014 DATE_SHORT = '{date_short}', # Tuesday, February 18th, 2014 DATE_LONG = '{date_long}', # February 18th, 2014 but uses "yesterday", "today", or "tomorrow" # where # appropriate DATE_PRETTY = '{date_pretty}', # Feb 18, 2014 but uses "yesterday", "today", or "tomorrow" where # appropriate DATE_SHORT_PRETTY = '{date_short_pretty}', # Tuesday, February 18th, 2014 but uses "yesterday", "today", or # "tomorrow" where appropriate DATE_LONG_PRETTY = '{date_long_pretty}', # 6:39 AM or 6:39 PM / 06:39 or 18:39 (depending on user preferences) TIME = '{time}', # 6:39:45 AM 6:39:42 PM / 06:39:45 or 18:39:42 (depending on user # preferences) TIME_SECS = '{time_secs}' ].freeze 
Instance Method Summary collapse
- 
  
    
      #at_channel  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mention @channel (all users in the current channel). 
- 
  
    
      #at_everyone  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mention @everyone (all users in #general). 
- 
  
    
      #at_here  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mention @here (all active users in the current channel). 
- 
  
    
      #channel(identifier)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Link a public channel. 
- 
  
    
      #date(timestamp, token_string:, link: nil, fallback_text: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Localise a UNIX timestamp to the user’s local timezone. 
- 
  
    
      #escape(text)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Escape special characters (<,>,&) with their HTML entity code so Slack’s text parsers knows to interpret them as literals. 
- 
  
    
      #group(identifier)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mention a group. 
- 
  
    
      #link(url, link_text: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Format a URL. 
- 
  
    
      #mailto(address, link_text: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Format a mailto link. 
- 
  
    
      #user(identifier)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Mention a user. 
Instance Method Details
#at_channel ⇒ Object
Mention @channel (all users in the current channel)
See: api.slack.com/reference/surfaces/formatting#special-mentions
| 91 92 93 | # File 'lib/slack/block_kit/formatting.rb', line 91 def at_channel '<!channel>' end | 
#at_everyone ⇒ Object
Mention @everyone (all users in #general)
See: api.slack.com/reference/surfaces/formatting#special-mentions
| 98 99 100 | # File 'lib/slack/block_kit/formatting.rb', line 98 def at_everyone '<!everyone>' end | 
#at_here ⇒ Object
Mention @here (all active users in the current channel)
See: api.slack.com/reference/surfaces/formatting#special-mentions
| 83 84 85 86 | # File 'lib/slack/block_kit/formatting.rb', line 83 def at_here # additional "|here" is for supporting very old mobile clients apparently! '<!here|here>' end | 
#channel(identifier) ⇒ Object
Link a public channel
See: api.slack.com/reference/surfaces/formatting#linking-channels
| 62 63 64 | # File 'lib/slack/block_kit/formatting.rb', line 62 def channel(identifier) "<##{identifier}>" end | 
#date(timestamp, token_string:, link: nil, fallback_text: nil) ⇒ Object
Localise a UNIX timestamp to the user’s local timezone
See: api.slack.com/reference/surfaces/formatting#date-formatting
| 105 106 107 108 109 110 | # File 'lib/slack/block_kit/formatting.rb', line 105 def date(, token_string:, link: nil, fallback_text: nil) datetime_str = [, token_string, link].compact.join('^') str = [datetime_str, fallback_text].compact.join('|') "<!date^#{str}>" end | 
#escape(text) ⇒ Object
Escape special characters (<,>,&) with their HTML entity code so Slack’s text parsers knows to interpret them as literals.
| 116 117 118 119 120 121 | # File 'lib/slack/block_kit/formatting.rb', line 116 def escape(text) text .gsub('&', '&') .gsub('>', '>') .gsub('<', '<') end | 
#group(identifier) ⇒ Object
Mention a group
See: api.slack.com/reference/surfaces/formatting#mentioning-groups
| 76 77 78 | # File 'lib/slack/block_kit/formatting.rb', line 76 def group(identifier) "<!subteam^#{identifier}>" end | 
#link(url, link_text: nil) ⇒ Object
Format a URL
| 48 49 50 | # File 'lib/slack/block_kit/formatting.rb', line 48 def link(url, link_text: nil) "<#{[url, link_text].compact.join('|')}>" end | 
#mailto(address, link_text: nil) ⇒ Object
Format a mailto link
| 55 56 57 | # File 'lib/slack/block_kit/formatting.rb', line 55 def mailto(address, link_text: nil) "<mailto:#{[address, link_text].compact.join('|')}>" end | 
#user(identifier) ⇒ Object
Mention a user
See: api.slack.com/reference/surfaces/formatting#mentioning-users
| 69 70 71 | # File 'lib/slack/block_kit/formatting.rb', line 69 def user(identifier) "<@#{identifier}>" end |