slack-ruby-block-kit 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba759b665f6bc72dfb41ad6f501de3ddd00e7047673ac805dddbae20bc6c69fb
4
- data.tar.gz: e30ecec2128b9f94f4f5f1d55b1b86b035555d49ef6b27f1abeae22e5b0e63b4
3
+ metadata.gz: 7f687b2454f80feed6080ab0fd166e64cf49a00508d9b9982a661ecd86119d0b
4
+ data.tar.gz: 2a96434b288cfd05db43a7d29dfc91d547bdca30f55a00d5a82837756a6c8fec
5
5
  SHA512:
6
- metadata.gz: e7784041e0d6e9b42bbfd8dc02dac3bbff8872ba268571c3b1f022a59b390e59fb637dedefb38894f8ee98234db5fa3fd3c1e03e99a8f4f1cd3befc9130ce368
7
- data.tar.gz: 2fd57d0ad2722e86e03e130799af76ec58828b9d701fd9726a68b5bbf6e1ce6da780ea93553d34a4f7423ade363c13463cbc28e02e4b65348ec389901c05420c
6
+ metadata.gz: 4af8e9ce974a3324d7df340fe21e85a5ec4018b67e9dd8744ea8b1d9537017ef3a21e02db60deb43e19270c7310e1a4ff27d742dba39067811a49381b5a08d77
7
+ data.tar.gz: d66f7d4e796172ea73938b589f6e26f46e78ab106c1c94d6d323498c9f483df1e26a5d98af15da6b35ef51d2ea00ba9fea64e65344898530665a839e1af0259a
@@ -15,10 +15,6 @@ jobs:
15
15
  matrix:
16
16
  ruby: [ '2.6', '2.7' ]
17
17
  experimental: [ false ]
18
- include:
19
- - ruby: 'head'
20
- experimental: true
21
-
22
18
  name: Ruby ${{ matrix.ruby }}
23
19
  steps:
24
20
  - uses: actions/checkout@v2
@@ -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
@@ -68,3 +69,6 @@ Style/RedundantRegexpEscape:
68
69
 
69
70
  RSpec/MultipleMemoizedHelpers:
70
71
  Max: 10
72
+
73
+ RSpec/NestedGroups:
74
+ Max: 4
@@ -32,6 +32,8 @@ RSpec/ExampleLength:
32
32
  - 'spec/lib/slack/block_kit/composition/option_spec.rb'
33
33
  - 'spec/lib/slack/block_kit/element/checkboxes_spec.rb'
34
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'
35
37
 
36
38
  # Offense count: 4
37
39
  Style/Documentation:
@@ -25,6 +25,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
25
  - N/A
26
26
 
27
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
+
28
45
  ## [0.11.0] - 2020-10-03
29
46
 
30
47
  ### Added
@@ -37,6 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
54
  - Ruby2.7 kwarg deprecation warnings
38
55
 
39
56
 
57
+ ---
58
+
59
+
40
60
  ## [0.10.0] - 2020-09-11
41
61
 
42
62
  ### Added
@@ -46,10 +66,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
46
66
  - Fixed initial options in multi select blocks (#46 by @caalberts)
47
67
 
48
68
 
69
+ ---
70
+
49
71
  See [releases] for previous changes.
50
72
 
51
73
 
52
- [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.11.0...HEAD
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
53
76
  [0.11.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...v0.11.0
54
77
  [0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
55
78
 
data/Gemfile CHANGED
@@ -3,3 +3,6 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ gem 'codecov', require: false
8
+ gem 'simplecov', require: false
@@ -1,28 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack-ruby-block-kit (0.11.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)
15
+ docile (1.3.2)
12
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
22
  parallel (1.19.2)
18
- parser (2.7.1.5)
23
+ parser (2.7.2.0)
19
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.8.0)
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,22 +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.92.0)
47
+ rubocop (0.93.0)
43
48
  parallel (~> 1.10)
44
49
  parser (>= 2.7.1.5)
45
50
  rainbow (>= 2.2.2, < 4.0)
46
- regexp_parser (>= 1.7)
51
+ regexp_parser (>= 1.8)
47
52
  rexml
48
- rubocop-ast (>= 0.5.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.7.0)
56
+ rubocop-ast (0.7.1)
52
57
  parser (>= 2.7.1.5)
53
- strscan (>= 1.0.0)
54
58
  rubocop-rspec (1.43.2)
55
59
  rubocop (~> 0.87)
56
60
  ruby-progressbar (1.10.1)
57
- strscan (1.0.3)
61
+ simplecov (0.19.0)
62
+ docile (~> 1.1)
63
+ simplecov-html (~> 0.11)
64
+ simplecov-html (0.12.2)
58
65
  unicode-display_width (1.7.0)
59
66
 
60
67
  PLATFORMS
@@ -62,6 +69,7 @@ PLATFORMS
62
69
 
63
70
  DEPENDENCIES
64
71
  bundler
72
+ codecov
65
73
  dotenv
66
74
  faraday
67
75
  pry
@@ -70,6 +78,7 @@ DEPENDENCIES
70
78
  rspec_junit_formatter
71
79
  rubocop
72
80
  rubocop-rspec
81
+ simplecov
73
82
  slack-ruby-block-kit!
74
83
 
75
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
 
@@ -6,8 +6,6 @@ module Slack
6
6
  module Element; end
7
7
  module Layout; end
8
8
 
9
- VERSION = '0.11.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 }
@@ -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
@@ -15,26 +15,16 @@ module Slack
15
15
  def initialize(action_id:)
16
16
  @action_id = action_id
17
17
  @options = []
18
- @initial_options = []
19
18
 
20
19
  yield(self) if block_given?
21
20
  end
22
21
 
23
- def option(value:, text:, description: nil)
22
+ def option(value:, text:, initial: false, description: nil)
24
23
  @options << Composition::Option.new(
25
24
  value: value,
26
25
  text: text,
27
- description: description
28
- )
29
-
30
- self
31
- end
32
-
33
- def initial(value:, text:, description: nil)
34
- @initial_options << Composition::Option.new(
35
- value: value,
36
- text: text,
37
- description: description
26
+ description: description,
27
+ initial: initial
38
28
  )
39
29
 
40
30
  self
@@ -45,10 +35,18 @@ module Slack
45
35
  type: TYPE,
46
36
  action_id: @action_id,
47
37
  options: @options.map(&:as_json),
48
- initial_options: @initial_options.any? ? @initial_options.map(&:as_json) : nil,
38
+ initial_options: initial_options&.map(&:as_json),
49
39
  confirm: confirm&.as_json
50
40
  }.compact
51
41
  end
42
+
43
+ private
44
+
45
+ def initial_options
46
+ initial = @options.select(&:initial?)
47
+
48
+ initial.empty? ? nil : initial
49
+ end
52
50
  end
53
51
  end
54
52
  end
@@ -17,7 +17,7 @@ module Slack
17
17
 
18
18
  TYPE = 'multi_static_select'
19
19
 
20
- attr_accessor :options, :option_groups, :initial_options
20
+ attr_accessor :options, :option_groups
21
21
 
22
22
  def initialize(placeholder:, action_id:, emoji: nil, max_selected_items: nil)
23
23
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -26,17 +26,17 @@ module Slack
26
26
 
27
27
  @options = nil
28
28
  @option_groups = nil
29
- @initial_options = nil
30
29
 
31
30
  yield(self) if block_given?
32
31
  end
33
32
 
34
- def option(value:, text:, emoji: nil)
33
+ def option(value:, text:, initial: false, emoji: nil)
35
34
  @options ||= []
36
35
  @options << Composition::Option.new(
37
36
  value: value,
38
37
  text: text,
39
- emoji: emoji
38
+ emoji: emoji,
39
+ initial: initial
40
40
  )
41
41
 
42
42
  self
@@ -53,17 +53,6 @@ module Slack
53
53
  self
54
54
  end
55
55
 
56
- def initial(value:, text:, emoji: nil)
57
- @initial_options ||= []
58
- @initial_options << Composition::Option.new(
59
- value: value,
60
- text: text,
61
- emoji: emoji
62
- )
63
-
64
- self
65
- end
66
-
67
56
  def as_json(*)
68
57
  {
69
58
  type: TYPE,
@@ -71,11 +60,21 @@ module Slack
71
60
  action_id: @action_id,
72
61
  options: @options&.map(&:as_json),
73
62
  option_groups: @option_groups&.map(&:as_json),
74
- initial_options: @initial_options&.map(&:as_json),
63
+ initial_options: initial_options&.map(&:as_json),
75
64
  confirm: confirm&.as_json,
76
65
  max_selected_items: @max_selected_items
77
66
  }.compact
78
67
  end
68
+
69
+ private
70
+
71
+ def initial_options
72
+ all_options = options || option_groups&.flat_map(&:options)
73
+
74
+ initial = all_options&.select(&:initial?)
75
+
76
+ initial&.empty? ? nil : initial
77
+ end
79
78
  end
80
79
  end
81
80
  end
@@ -11,10 +11,11 @@ module Slack
11
11
 
12
12
  TYPE = 'radio_buttons'
13
13
 
14
- attr_accessor :options, :initial_option
14
+ attr_accessor :options
15
15
 
16
16
  def initialize(action_id:)
17
17
  @action_id = action_id
18
+ @options = []
18
19
 
19
20
  yield(self) if block_given?
20
21
  end
@@ -22,14 +23,12 @@ module Slack
22
23
  def option(value:, text:, initial: false)
23
24
  option = Composition::Option.new(
24
25
  value: value,
25
- text: text
26
+ text: text,
27
+ initial: initial
26
28
  )
27
29
 
28
- @options ||= []
29
30
  @options << option
30
31
 
31
- @initial_option = option if initial
32
-
33
32
  self
34
33
  end
35
34
 
@@ -37,11 +36,17 @@ module Slack
37
36
  {
38
37
  type: TYPE,
39
38
  action_id: @action_id,
40
- options: @options&.map(&:as_json),
41
- initial_option: @initial_option&.as_json,
39
+ options: @options.map(&:as_json),
40
+ initial_option: initial_option&.as_json,
42
41
  confirm: confirm&.as_json
43
42
  }.compact
44
43
  end
44
+
45
+ private
46
+
47
+ def initial_option
48
+ @options&.find(&:initial?)
49
+ end
45
50
  end
46
51
  end
47
52
  end
@@ -17,7 +17,7 @@ module Slack
17
17
 
18
18
  TYPE = 'static_select'
19
19
 
20
- attr_accessor :options, :option_groups, :initial_option
20
+ attr_accessor :options, :option_groups
21
21
 
22
22
  def initialize(placeholder:, action_id:, emoji: nil)
23
23
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
@@ -26,12 +26,13 @@ module Slack
26
26
  yield(self) if block_given?
27
27
  end
28
28
 
29
- def option(value:, text:, emoji: nil)
29
+ def option(value:, text:, initial: false, emoji: nil)
30
30
  @options ||= []
31
31
  @options << Composition::Option.new(
32
32
  value: value,
33
33
  text: text,
34
- emoji: emoji
34
+ emoji: emoji,
35
+ initial: initial
35
36
  )
36
37
 
37
38
  self
@@ -48,27 +49,27 @@ module Slack
48
49
  self
49
50
  end
50
51
 
51
- def initial(value:, text:, emoji: nil)
52
- @initial_option = Composition::Option.new(
53
- value: value,
54
- text: text,
55
- emoji: emoji
56
- )
57
-
58
- self
59
- end
60
-
61
52
  def as_json(*)
62
53
  {
63
54
  type: TYPE,
64
55
  placeholder: @placeholder.as_json,
65
56
  action_id: @action_id,
66
- options: @options&.map(&:as_json),
67
- option_groups: @option_groups&.map(&:as_json),
68
- initial_option: @initial_option&.as_json,
57
+ options: options&.map(&:as_json),
58
+ option_groups: option_groups&.map(&:as_json),
59
+ initial_option: initial_option&.as_json,
69
60
  confirm: confirm&.as_json
70
61
  }.compact
71
62
  end
63
+
64
+ private
65
+
66
+ def initial_option
67
+ opts = options || option_groups&.flat_map(&:options)
68
+
69
+ return unless opts
70
+
71
+ opts.find(&:initial?)
72
+ end
72
73
  end
73
74
  end
74
75
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Layout
6
+ # A header is a plain-text block that displays in a larger, bold font.
7
+ # Use it to delineate between different groups of content in your app's
8
+ # surfaces.
9
+ #
10
+ # https://api.slack.com/reference/block-kit/blocks#header
11
+ class Header
12
+ TYPE = 'header'
13
+
14
+ def initialize(text:, block_id: nil, emoji: nil)
15
+ @text = Composition::PlainText.new(text: text, emoji: emoji)
16
+ @block_id = block_id
17
+ end
18
+
19
+ def as_json(*)
20
+ {
21
+ type: TYPE,
22
+ text: @text.as_json,
23
+ block_id: @block_id
24
+ }.compact
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ VERSION = '0.12.0'
6
+ end
7
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'slack-ruby-block-kit'
5
+ require 'slack/block_kit/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'slack-ruby-block-kit'
@@ -13,13 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/CGA1123/slack-ruby-block-kit'
14
14
  spec.license = 'MIT'
15
15
 
16
- if spec.respond_to?(:metadata)
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
- else
19
- raise 'RubyGems 2.0 or newer is required to protect against ' \
20
- 'public gem pushes.'
21
- end
22
-
23
16
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
17
  `git ls-files -z`
25
18
  .split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-block-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Gregg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-03 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -185,10 +185,12 @@ files:
185
185
  - lib/slack/block_kit/layout/actions.rb
186
186
  - lib/slack/block_kit/layout/context.rb
187
187
  - lib/slack/block_kit/layout/divider.rb
188
+ - lib/slack/block_kit/layout/header.rb
188
189
  - lib/slack/block_kit/layout/image.rb
189
190
  - lib/slack/block_kit/layout/input.rb
190
191
  - lib/slack/block_kit/layout/section.rb
191
192
  - lib/slack/block_kit/layout/section/multi_select_elements.rb
193
+ - lib/slack/block_kit/version.rb
192
194
  - lib/slack/surfaces/home.rb
193
195
  - lib/slack/surfaces/message.rb
194
196
  - lib/slack/surfaces/modal.rb
@@ -196,8 +198,7 @@ files:
196
198
  homepage: https://github.com/CGA1123/slack-ruby-block-kit
197
199
  licenses:
198
200
  - MIT
199
- metadata:
200
- allowed_push_host: https://rubygems.org
201
+ metadata: {}
201
202
  post_install_message:
202
203
  rdoc_options: []
203
204
  require_paths: