Class: Slack::BlockKit::Layout::Context
- Inherits:
-
Object
- Object
- Slack::BlockKit::Layout::Context
- Defined in:
- lib/slack/block_kit/layout/context.rb
Overview
Displays message context, which can include both images and text.
Constant Summary collapse
- TYPE =
'context'
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
Instance Method Summary collapse
- #append(element) ⇒ Object
- #as_json ⇒ Object
- #image(url:, alt_text:) ⇒ Object
-
#initialize(block_id: nil) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
- #mrkdwn(text:, verbatim: nil) ⇒ Object
- #plain_text(text:, emoji: nil) ⇒ Object
Constructor Details
#initialize(block_id: nil) {|_self| ... } ⇒ Context
Returns a new instance of Context.
14 15 16 17 18 19 |
# File 'lib/slack/block_kit/layout/context.rb', line 14 def initialize(block_id: nil) @block_id = block_id @elements = [] yield(self) if block_given? end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
12 13 14 |
# File 'lib/slack/block_kit/layout/context.rb', line 12 def elements @elements end |
Instance Method Details
#append(element) ⇒ Object
33 34 35 36 37 |
# File 'lib/slack/block_kit/layout/context.rb', line 33 def append(element) @elements << element self end |
#as_json ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/slack/block_kit/layout/context.rb', line 39 def as_json(*) { type: TYPE, elements: @elements.map(&:as_json), block_id: @block_id }.compact end |
#image(url:, alt_text:) ⇒ Object
21 22 23 |
# File 'lib/slack/block_kit/layout/context.rb', line 21 def image(url:, alt_text:) append(Element::Image.new(image_url: url, alt_text: alt_text)) end |
#mrkdwn(text:, verbatim: nil) ⇒ Object
29 30 31 |
# File 'lib/slack/block_kit/layout/context.rb', line 29 def mrkdwn(text:, verbatim: nil) append(Composition::Mrkdwn.new(text: text, verbatim: verbatim)) end |
#plain_text(text:, emoji: nil) ⇒ Object
25 26 27 |
# File 'lib/slack/block_kit/layout/context.rb', line 25 def plain_text(text:, emoji: nil) append(Composition::PlainText.new(text: text, emoji: emoji)) end |