-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsection.rb
More file actions
214 lines (162 loc) · 5.49 KB
/
section.rb
File metadata and controls
214 lines (162 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# frozen_string_literal: true
module Slack
module BlockKit
module Layout
# A section is one of the most flexible blocks available - it can be used
# as a simple text block, in combination with text fields, or side-by-side
# with any of the available block elements.
#
# https://api.slack.com/reference/messaging/blocks#section
class Section
include Section::MultiSelectElements
TYPE = 'section'
attr_accessor :fields, :text, :accessory
def initialize(block_id: nil)
@block_id = block_id
@fields = nil
@accessory = nil
@text = nil
yield(self) if block_given?
end
def plaintext_field(text:, emoji: nil)
@fields ||= []
@fields << Composition::PlainText.new(text: text, emoji: emoji)
self
end
def mrkdwn_field(text:, verbatim: nil)
@fields ||= []
@fields << Composition::Mrkdwn.new(text: text, verbatim: verbatim)
self
end
def plain_text(text:, emoji: nil)
@text = Composition::PlainText.new(text: text, emoji: emoji)
self
end
def mrkdwn(text:, verbatim: nil)
@text = Composition::Mrkdwn.new(text: text, verbatim: verbatim)
self
end
def button(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
element = Element::Button.new(
text: text,
action_id: action_id,
style: style,
emoji: emoji,
url: url,
value: value
)
yield(element) if block_given?
accessorise(element)
end
def channel_select(placeholder:, action_id:, initial: nil, emoji: nil, response_url_enabled: nil)
element = Element::ChannelsSelect.new(
placeholder: placeholder,
action_id: action_id,
initial: initial,
emoji: emoji,
response_url_enabled: response_url_enabled
)
yield(element) if block_given?
accessorise(element)
end
def conversation_select(placeholder:, action_id:, initial: nil, emoji: nil, default_to_current_conversation: nil, response_url_enabled: nil)
element = Element::ConversationsSelect.new(
placeholder: placeholder,
action_id: action_id,
initial: initial,
emoji: emoji,
default_to_current_conversation: default_to_current_conversation,
response_url_enabled: response_url_enabled
)
yield(element) if block_given?
accessorise(element)
end
def datepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
element = Element::Datepicker.new(
placeholder: placeholder,
action_id: action_id,
initial: initial,
emoji: emoji
)
yield(element) if block_given?
accessorise(element)
end
def timepicker(action_id:, placeholder: nil, initial: nil, emoji: nil)
element = Element::Timepicker.new(
placeholder: placeholder,
action_id: action_id,
initial: initial,
emoji: emoji
)
yield(element) if block_given?
accessorise(element)
end
def external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
element = Element::ExternalSelect.new(
placeholder: placeholder,
action_id: action_id,
initial: initial,
min_query_length: min_query_length,
emoji: emoji
)
yield(element) if block_given?
accessorise(element)
end
def overflow_menu(action_id:)
element = Element::OverflowMenu.new(action_id: action_id)
yield(element) if block_given?
accessorise(element)
end
def static_select(placeholder:, action_id:, emoji: nil)
element = Element::StaticSelect.new(
placeholder: placeholder,
action_id: action_id,
emoji: emoji
)
yield(element) if block_given?
accessorise(element)
end
def users_select(placeholder:, action_id:, initial: nil, emoji: nil)
element = Element::UsersSelect.new(
placeholder: placeholder,
action_id: action_id,
emoji: emoji,
initial: initial
)
yield(element) if block_given?
accessorise(element)
end
def checkboxes(action_id:)
element = Element::Checkboxes.new(
action_id: action_id
)
yield(element) if block_given?
accessorise(element)
end
def radio_buttons(action_id:)
element = Element::RadioButtons.new(
action_id: action_id
)
yield(element) if block_given?
accessorise(element)
end
def image(url:, alt_text:)
accessorise(Element::Image.new(image_url: url, alt_text: alt_text))
end
def accessorise(element)
@accessory = element
self
end
def as_json(*)
{
type: TYPE,
text: @text&.as_json,
block_id: @block_id,
fields: @fields&.map(&:as_json),
accessory: @accessory&.as_json
}.compact
end
end
end
end
end