slack-ruby-block-kit 0.7.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +10 -0
- data/CHANGELOG.md +79 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +25 -14
- data/README.md +1 -1
- data/lib/slack/block_kit.rb +44 -2
- data/lib/slack/block_kit/composition/confirmation_dialog.rb +16 -0
- data/lib/slack/block_kit/composition/conversation_filter.rb +33 -0
- data/lib/slack/block_kit/composition/option.rb +6 -1
- data/lib/slack/block_kit/composition/option_group.rb +2 -2
- data/lib/slack/block_kit/element/button.rb +3 -11
- data/lib/slack/block_kit/element/channels_select.rb +3 -11
- data/lib/slack/block_kit/element/checkboxes.rb +53 -0
- data/lib/slack/block_kit/element/conversations_select.rb +13 -7
- data/lib/slack/block_kit/element/date_picker.rb +3 -9
- data/lib/slack/block_kit/element/external_select.rb +3 -12
- data/lib/slack/block_kit/element/multi_channels_select.rb +5 -14
- data/lib/slack/block_kit/element/multi_conversations_select.rb +16 -11
- data/lib/slack/block_kit/element/multi_external_select.rb +5 -14
- data/lib/slack/block_kit/element/multi_static_select.rb +18 -25
- data/lib/slack/block_kit/element/multi_users_select.rb +5 -14
- data/lib/slack/block_kit/element/overflow_menu.rb +4 -11
- data/lib/slack/block_kit/element/radio_buttons.rb +53 -0
- data/lib/slack/block_kit/element/static_select.rb +20 -25
- data/lib/slack/block_kit/element/users_select.rb +3 -11
- data/lib/slack/block_kit/layout/header.rb +29 -0
- data/lib/slack/block_kit/layout/image.rb +1 -4
- data/lib/slack/block_kit/layout/section.rb +21 -1
- data/lib/slack/block_kit/version.rb +7 -0
- data/lib/slack/surfaces/home.rb +35 -0
- data/lib/slack/surfaces/message.rb +34 -0
- data/lib/slack/surfaces/modal.rb +76 -0
- data/slack-ruby-block-kit.gemspec +1 -8
- metadata +17 -9
- data/.circleci/config.yml +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f687b2454f80feed6080ab0fd166e64cf49a00508d9b9982a661ecd86119d0b
|
4
|
+
data.tar.gz: 2a96434b288cfd05db43a7d29dfc91d547bdca30f55a00d5a82837756a6c8fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af8e9ce974a3324d7df340fe21e85a5ec4018b67e9dd8744ea8b1d9537017ef3a21e02db60deb43e19270c7310e1a4ff27d742dba39067811a49381b5a08d77
|
7
|
+
data.tar.gz: d66f7d4e796172ea73938b589f6e26f46e78ab106c1c94d6d323498c9f483df1e26a5d98af15da6b35ef51d2ea00ba9fea64e65344898530665a839e1af0259a
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Test & Lint
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
continue-on-error: ${{ matrix.experimental }}
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby: [ '2.6', '2.7' ]
|
17
|
+
experimental: [ false ]
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
- run: gem install bundler:2.1.4
|
25
|
+
- run: bundle install
|
26
|
+
- run: bundle exec rubocop
|
27
|
+
- run: bundle exec rspec --format progress
|
data/.rubocop.yml
CHANGED
@@ -3,6 +3,7 @@ inherit_from: .rubocop_todo.yml
|
|
3
3
|
|
4
4
|
AllCops:
|
5
5
|
TargetRubyVersion: 2.5.3
|
6
|
+
NewCops: enable
|
6
7
|
|
7
8
|
Layout/LineLength:
|
8
9
|
Max: 120
|
@@ -53,3 +54,21 @@ Style/HashTransformValues:
|
|
53
54
|
|
54
55
|
Style/SlicingWithRange:
|
55
56
|
Enabled: true
|
57
|
+
|
58
|
+
Lint/MixedRegexpCaptureTypes:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
Style/RedundantFetchBlock:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
Style/RedundantRegexpCharacterClass:
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Style/RedundantRegexpEscape:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
RSpec/MultipleMemoizedHelpers:
|
71
|
+
Max: 10
|
72
|
+
|
73
|
+
RSpec/NestedGroups:
|
74
|
+
Max: 4
|
data/.rubocop_todo.yml
CHANGED
@@ -17,6 +17,12 @@ Metrics/BlockLength:
|
|
17
17
|
Metrics/ClassLength:
|
18
18
|
Max: 117
|
19
19
|
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: IgnoredMethods.
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/slack/block_kit/element/multi_static_select.rb'
|
25
|
+
|
20
26
|
# Offense count: 5
|
21
27
|
# Configuration parameters: Max.
|
22
28
|
RSpec/ExampleLength:
|
@@ -24,6 +30,10 @@ RSpec/ExampleLength:
|
|
24
30
|
- 'spec/lib/slack/block_kit/composition/confirmation_dialog_spec.rb'
|
25
31
|
- 'spec/lib/slack/block_kit/composition/option_group_spec.rb'
|
26
32
|
- 'spec/lib/slack/block_kit/composition/option_spec.rb'
|
33
|
+
- 'spec/lib/slack/block_kit/element/checkboxes_spec.rb'
|
34
|
+
- 'spec/lib/slack/block_kit/element/radio_buttons_spec.rb'
|
35
|
+
- 'spec/lib/slack/block_kit/composition/option_spec.rb'
|
36
|
+
- 'spec/lib/slack/block_kit/element/multi_static_select_spec.rb'
|
27
37
|
|
28
38
|
# Offense count: 4
|
29
39
|
Style/Documentation:
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- N/A
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- N/A
|
14
|
+
|
15
|
+
### Deprecated
|
16
|
+
- N/A
|
17
|
+
|
18
|
+
### Removed
|
19
|
+
- N/A
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
- N/A
|
23
|
+
|
24
|
+
### Security
|
25
|
+
- N/A
|
26
|
+
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
|
31
|
+
## [0.12.0] - 2020-10-06
|
32
|
+
|
33
|
+
### Added
|
34
|
+
- `Slack::BlockKit::Layout::Header` (#57)
|
35
|
+
|
36
|
+
### Removed
|
37
|
+
- `Slack::BlockKit::Element::Checkboxes#initial`, use the `initial:` keyword on `#option`
|
38
|
+
- `Slack::BlockKit::Element::MultiStaticSelect#initial`, use the `initial:` keyword on `#option`
|
39
|
+
- `Slack::BlockKit::Element::StaticSelect#initial`, use the `initial:` keyword on `#option`
|
40
|
+
|
41
|
+
|
42
|
+
---
|
43
|
+
|
44
|
+
|
45
|
+
## [0.11.0] - 2020-10-03
|
46
|
+
|
47
|
+
### Added
|
48
|
+
- Add `Slack::BlockKit::Element::RadioButtons` (#52 by @caalberts)
|
49
|
+
|
50
|
+
### Changed
|
51
|
+
- Internal refactoring of `#confirmation_dialog` methods into a shared `Confirmable` module. (#48)
|
52
|
+
|
53
|
+
### Fixed
|
54
|
+
- Ruby2.7 kwarg deprecation warnings
|
55
|
+
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
|
60
|
+
## [0.10.0] - 2020-09-11
|
61
|
+
|
62
|
+
### Added
|
63
|
+
- Add `Slack::BlockKit::Element::Checkboxes` (#44 by @caalberts)
|
64
|
+
|
65
|
+
### Fixed
|
66
|
+
- Fixed initial options in multi select blocks (#46 by @caalberts)
|
67
|
+
|
68
|
+
|
69
|
+
---
|
70
|
+
|
71
|
+
See [releases] for previous changes.
|
72
|
+
|
73
|
+
|
74
|
+
[Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.12.0...HEAD
|
75
|
+
[0.12.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.11.0...v0.12.0
|
76
|
+
[0.11.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...v0.11.0
|
77
|
+
[0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
|
78
|
+
|
79
|
+
[releases]: https://github.com/CGA1123/slack-ruby-block-kit/releases
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slack-ruby-block-kit (0.
|
4
|
+
slack-ruby-block-kit (0.12.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.1)
|
10
|
+
codecov (0.2.11)
|
11
|
+
json
|
12
|
+
simplecov
|
10
13
|
coderay (1.1.2)
|
11
14
|
diff-lcs (1.3)
|
12
|
-
|
15
|
+
docile (1.3.2)
|
16
|
+
dotenv (2.7.6)
|
13
17
|
faraday (1.0.1)
|
14
18
|
multipart-post (>= 1.2, < 3)
|
19
|
+
json (2.3.1)
|
15
20
|
method_source (1.0.0)
|
16
21
|
multipart-post (2.1.1)
|
17
|
-
parallel (1.19.
|
18
|
-
parser (2.7.
|
19
|
-
ast (~> 2.4.
|
22
|
+
parallel (1.19.2)
|
23
|
+
parser (2.7.2.0)
|
24
|
+
ast (~> 2.4.1)
|
20
25
|
pry (0.13.1)
|
21
26
|
coderay (~> 1.1)
|
22
27
|
method_source (~> 1.0)
|
23
28
|
rainbow (3.0.0)
|
24
29
|
rake (13.0.1)
|
25
|
-
regexp_parser (1.
|
30
|
+
regexp_parser (1.8.1)
|
26
31
|
rexml (3.2.4)
|
27
32
|
rspec (3.9.0)
|
28
33
|
rspec-core (~> 3.9.0)
|
@@ -39,20 +44,24 @@ GEM
|
|
39
44
|
rspec-support (3.9.3)
|
40
45
|
rspec_junit_formatter (0.4.1)
|
41
46
|
rspec-core (>= 2, < 4, != 2.12.0)
|
42
|
-
rubocop (0.
|
47
|
+
rubocop (0.93.0)
|
43
48
|
parallel (~> 1.10)
|
44
|
-
parser (>= 2.7.
|
49
|
+
parser (>= 2.7.1.5)
|
45
50
|
rainbow (>= 2.2.2, < 4.0)
|
46
|
-
regexp_parser (>= 1.
|
51
|
+
regexp_parser (>= 1.8)
|
47
52
|
rexml
|
48
|
-
rubocop-ast (>= 0.0
|
53
|
+
rubocop-ast (>= 0.6.0)
|
49
54
|
ruby-progressbar (~> 1.7)
|
50
55
|
unicode-display_width (>= 1.4.0, < 2.0)
|
51
|
-
rubocop-ast (0.
|
52
|
-
parser (>= 2.7.
|
53
|
-
rubocop-rspec (1.
|
54
|
-
rubocop (
|
56
|
+
rubocop-ast (0.7.1)
|
57
|
+
parser (>= 2.7.1.5)
|
58
|
+
rubocop-rspec (1.43.2)
|
59
|
+
rubocop (~> 0.87)
|
55
60
|
ruby-progressbar (1.10.1)
|
61
|
+
simplecov (0.19.0)
|
62
|
+
docile (~> 1.1)
|
63
|
+
simplecov-html (~> 0.11)
|
64
|
+
simplecov-html (0.12.2)
|
56
65
|
unicode-display_width (1.7.0)
|
57
66
|
|
58
67
|
PLATFORMS
|
@@ -60,6 +69,7 @@ PLATFORMS
|
|
60
69
|
|
61
70
|
DEPENDENCIES
|
62
71
|
bundler
|
72
|
+
codecov
|
63
73
|
dotenv
|
64
74
|
faraday
|
65
75
|
pry
|
@@ -68,6 +78,7 @@ DEPENDENCIES
|
|
68
78
|
rspec_junit_formatter
|
69
79
|
rubocop
|
70
80
|
rubocop-rspec
|
81
|
+
simplecov
|
71
82
|
slack-ruby-block-kit!
|
72
83
|
|
73
84
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
[![CircleCI](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master.svg?style=svg)](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master)
|
2
1
|
[![Gem Version](https://badge.fury.io/rb/slack-ruby-block-kit.svg)](https://badge.fury.io/rb/slack-ruby-block-kit)
|
2
|
+
[![codecov](https://codecov.io/gh/CGA1123/slack-ruby-block-kit/branch/master/graph/badge.svg)](https://codecov.io/gh/CGA1123/slack-ruby-block-kit)
|
3
3
|
|
4
4
|
# Slack::BlockKit
|
5
5
|
|
data/lib/slack/block_kit.rb
CHANGED
@@ -6,12 +6,11 @@ module Slack
|
|
6
6
|
module Element; end
|
7
7
|
module Layout; end
|
8
8
|
|
9
|
-
VERSION = '0.7.0'
|
10
|
-
|
11
9
|
Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].sort.each { |file| require file }
|
12
10
|
Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].sort.each { |file| require file }
|
13
11
|
Dir[File.join(__dir__, 'block_kit', 'layout', '*.rb')].sort.each { |file| require file }
|
14
12
|
Dir[File.join(__dir__, 'block_kit', '*.rb')].sort.each { |file| require file }
|
13
|
+
Dir[File.join(__dir__, 'surfaces', '*.rb')].sort.each { |file| require file }
|
15
14
|
|
16
15
|
module_function
|
17
16
|
|
@@ -22,5 +21,48 @@ module Slack
|
|
22
21
|
|
23
22
|
blocks
|
24
23
|
end
|
24
|
+
|
25
|
+
def home(blocks: nil,
|
26
|
+
private_metadata: nil, callback_id: nil, external_id: nil)
|
27
|
+
home_surface = Slack::Surfaces::Home.new(blocks: blocks,
|
28
|
+
private_metadata: private_metadata,
|
29
|
+
callback_id: callback_id,
|
30
|
+
external_id: external_id)
|
31
|
+
|
32
|
+
yield(home_surface) if block_given?
|
33
|
+
|
34
|
+
home_surface
|
35
|
+
end
|
36
|
+
|
37
|
+
def modal(title: nil,
|
38
|
+
blocks: nil,
|
39
|
+
private_metadata: nil, callback_id: nil, external_id: nil,
|
40
|
+
clear_on_close: nil, notify_on_close: nil)
|
41
|
+
modal_surface = Slack::Surfaces::Modal.new(title: title,
|
42
|
+
blocks: blocks,
|
43
|
+
private_metadata: private_metadata,
|
44
|
+
callback_id: callback_id,
|
45
|
+
external_id: external_id,
|
46
|
+
clear_on_close: clear_on_close,
|
47
|
+
notify_on_close: notify_on_close)
|
48
|
+
|
49
|
+
yield(modal_surface) if block_given?
|
50
|
+
|
51
|
+
modal_surface
|
52
|
+
end
|
53
|
+
|
54
|
+
def message(blocks: nil, channel: nil, thread_ts: nil, as_user: nil, text: nil)
|
55
|
+
message_surface = Slack::Surfaces::Message.new(
|
56
|
+
blocks: blocks,
|
57
|
+
channel: channel,
|
58
|
+
thread_ts: thread_ts,
|
59
|
+
text: text,
|
60
|
+
as_user: as_user
|
61
|
+
)
|
62
|
+
|
63
|
+
yield(message_surface) if block_given?
|
64
|
+
|
65
|
+
message_surface
|
66
|
+
end
|
25
67
|
end
|
26
68
|
end
|
@@ -9,6 +9,22 @@ module Slack
|
|
9
9
|
#
|
10
10
|
# https://api.slack.com/reference/messaging/composition-objects#confirm
|
11
11
|
class ConfirmationDialog
|
12
|
+
# {Confirmable} contains the common behaviour for configuring a
|
13
|
+
# {ConfirmationDialog}
|
14
|
+
module Confirmable
|
15
|
+
def self.included(klass)
|
16
|
+
klass.attr_accessor :confirm
|
17
|
+
end
|
18
|
+
|
19
|
+
def confirmation_dialog
|
20
|
+
self.confirm = Composition::ConfirmationDialog.new
|
21
|
+
|
22
|
+
yield(confirm) if block_given?
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
12
28
|
def initialize
|
13
29
|
@title, @confirm, @text, @style = nil
|
14
30
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slack
|
4
|
+
module BlockKit
|
5
|
+
module Composition
|
6
|
+
# Provides a way to filter the list of options in a conversations select menu
|
7
|
+
# or conversations multi-select menu.
|
8
|
+
#
|
9
|
+
# @param [Array] only - "include" field
|
10
|
+
#
|
11
|
+
# https://api.slack.com/reference/block-kit/composition-objects#filter_conversations
|
12
|
+
# https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
|
13
|
+
# https://api.slack.com/reference/block-kit/block-elements#conversation_select
|
14
|
+
class ConversationFilter
|
15
|
+
def initialize(only: nil,
|
16
|
+
exclude_external_shared_channels: nil,
|
17
|
+
exclude_bot_users: nil)
|
18
|
+
@only = only
|
19
|
+
@exclude_external_shared_channels = exclude_external_shared_channels
|
20
|
+
@exclude_bot_users = exclude_bot_users
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_json(*)
|
24
|
+
{
|
25
|
+
include: @only,
|
26
|
+
exclude_external_shared_channels: @exclude_external_shared_channels,
|
27
|
+
exclude_bot_users: @exclude_bot_users
|
28
|
+
}.compact
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -8,11 +8,16 @@ module Slack
|
|
8
8
|
# https://api.slack.com/reference/messaging/composition-objects#option
|
9
9
|
# https://api.slack.com/reference/messaging/block-elements#select
|
10
10
|
class Option
|
11
|
-
def initialize(value:, text:, emoji: nil, description: nil, url: nil)
|
11
|
+
def initialize(value:, text:, initial: false, emoji: nil, description: nil, url: nil)
|
12
12
|
@text = PlainText.new(text: text, emoji: emoji)
|
13
13
|
@value = value
|
14
14
|
@description = description && PlainText.new(text: description, emoji: emoji)
|
15
15
|
@url = url
|
16
|
+
@initial = initial
|
17
|
+
end
|
18
|
+
|
19
|
+
def initial?
|
20
|
+
!!@initial
|
16
21
|
end
|
17
22
|
|
18
23
|
def as_json(*)
|
@@ -17,8 +17,8 @@ module Slack
|
|
17
17
|
yield(self) if block_given?
|
18
18
|
end
|
19
19
|
|
20
|
-
def option(text:, value:, emoji: nil)
|
21
|
-
@options << Option.new(text: text, value: value, emoji: emoji)
|
20
|
+
def option(text:, value:, emoji: nil, initial: false)
|
21
|
+
@options << Option.new(text: text, value: value, emoji: emoji, initial: initial)
|
22
22
|
|
23
23
|
self
|
24
24
|
end
|
@@ -9,9 +9,9 @@ module Slack
|
|
9
9
|
#
|
10
10
|
# https://api.slack.com/reference/messaging/block-elements#button
|
11
11
|
class Button
|
12
|
-
|
12
|
+
include Composition::ConfirmationDialog::Confirmable
|
13
13
|
|
14
|
-
|
14
|
+
TYPE = 'button'
|
15
15
|
|
16
16
|
def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
|
17
17
|
@text = Composition::PlainText.new(text: text, emoji: emoji)
|
@@ -23,14 +23,6 @@ module Slack
|
|
23
23
|
yield(self) if block_given?
|
24
24
|
end
|
25
25
|
|
26
|
-
def confirmation_dialog
|
27
|
-
@confirm = Composition::ConfirmationDialog.new
|
28
|
-
|
29
|
-
yield(@confirm) if block_given?
|
30
|
-
|
31
|
-
@confirm
|
32
|
-
end
|
33
|
-
|
34
26
|
def as_json(*)
|
35
27
|
{
|
36
28
|
type: TYPE,
|
@@ -39,7 +31,7 @@ module Slack
|
|
39
31
|
url: @url,
|
40
32
|
value: @value,
|
41
33
|
style: @style,
|
42
|
-
confirm:
|
34
|
+
confirm: confirm&.as_json
|
43
35
|
}.compact
|
44
36
|
end
|
45
37
|
end
|