slack_block_kit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,36 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Layout
6
+ # Displays message context, which can include both images and text.
7
+ #
8
+ # https://api.slack.com/reference/messaging/blocks#context
6
9
  class Context
7
10
  TYPE = 'context'
8
11
 
9
- def initialize(elements:, block_id: nil)
10
- @elements = elements
12
+ attr_accessor :elements
13
+ def initialize(block_id: nil)
11
14
  @block_id = block_id
15
+ @elements = []
16
+
17
+ yield(self) if block_given?
18
+ end
19
+
20
+ def image(url:, alt_text:)
21
+ append(Element::Image.new(image_url: url, alt_text: alt_text))
22
+ end
23
+
24
+ def plain_text(text:, emoji: nil)
25
+ append(Composition::PlainText.new(text: text, emoji: emoji))
26
+ end
27
+
28
+ def mrkdwn(text:, verbatim: nil)
29
+ append(Composition::Mrkdwn.new(text: text, verbatim: verbatim))
30
+ end
31
+
32
+ def append(element)
33
+ @elements << element
34
+
35
+ self
12
36
  end
13
37
 
14
38
  def as_json(*)
@@ -3,6 +3,10 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Layout
6
+ # A content divider, like an <hr>, to split up different blocks inside of
7
+ # a message.
8
+ #
9
+ # https://api.slack.com/reference/messaging/blocks#divider
6
10
  class Divider
7
11
  TYPE = 'divider'
8
12
 
@@ -3,14 +3,23 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Layout
6
+ # A simple image block, designed to make those cat photos really pop.
7
+ #
8
+ # https://api.slack.com/reference/messaging/blocks#context
6
9
  class Image
7
10
  TYPE = 'image'
8
11
 
9
- def initialize(image_url:, alt_text:, title: nil, block_id: nil)
10
- @image_url = image_url
12
+ def initialize(url:, alt_text:, title: nil, block_id: nil, emoji: nil)
13
+ @image_url = url
11
14
  @alt_text = alt_text
12
- @title = title
13
15
  @block_id = block_id
16
+
17
+ return unless title
18
+
19
+ @title = Composition::PlainText.new(
20
+ text: title,
21
+ emoji: emoji
22
+ )
14
23
  end
15
24
 
16
25
  def as_json(*)
@@ -3,14 +3,158 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Layout
6
+ # A section is one of the most flexible blocks available - it can be used
7
+ # as a simple text block, in combination with text fields, or side-by-side
8
+ # with any of the available block elements.
9
+ #
10
+ # https://api.slack.com/reference/messaging/blocks#section
6
11
  class Section
7
12
  TYPE = 'section'
8
13
 
9
- def initialize(text:, block_id: nil, fields: nil, accessory: nil)
10
- @text = text
14
+ attr_accessor :fields, :text, :accessory
15
+
16
+ def initialize(block_id: nil)
11
17
  @block_id = block_id
12
- @fields = fields
13
- @accessory = accessory
18
+
19
+ yield(self) if block_given?
20
+ end
21
+
22
+ def plaintext_field(text:, emoji: nil)
23
+ @fields ||= []
24
+
25
+ @fields << Composition::PlainText.new(text: text, emoji: emoji)
26
+
27
+ self
28
+ end
29
+
30
+ def mrkdwn_field(text:, verbatim: nil)
31
+ @fields ||= []
32
+
33
+ @fields << Composition::Mrkdwn.new(text: text, verbatim: verbatim)
34
+
35
+ self
36
+ end
37
+
38
+ def plain_text(text:, emoji: nil)
39
+ @text = Composition::PlainText.new(text: text, emoji: emoji)
40
+
41
+ self
42
+ end
43
+
44
+ def mrkdwn(text:, verbatim: nil)
45
+ @text = Composition::Mrkdwn.new(text: text, verbatim: verbatim)
46
+
47
+ self
48
+ end
49
+
50
+ def button(text:, action_id:, emoji: nil, url: nil, value: nil)
51
+ element = Element::Button.new(
52
+ text: text,
53
+ action_id: action_id,
54
+ emoji: emoji,
55
+ url: url,
56
+ value: value
57
+ )
58
+
59
+ yield(element) if block_given?
60
+
61
+ accessorise(element)
62
+ end
63
+
64
+ def channel_select(placeholder:, action_id:, initial: nil, emoji: nil)
65
+ element = Element::ChannelsSelect.new(
66
+ placeholder: placeholder,
67
+ action_id: action_id,
68
+ initial: initial,
69
+ emoji: emoji
70
+ )
71
+
72
+ yield(element) if block_given?
73
+
74
+ accessorise(element)
75
+ end
76
+
77
+ def converstation_select(placeholder:, action_id:, initial: nil, emoji: nil)
78
+ element = Element::ConversationsSelect.new(
79
+ placeholder: placeholder,
80
+ action_id: action_id,
81
+ initial: initial,
82
+ emoji: emoji
83
+ )
84
+
85
+ yield(element) if block_given?
86
+
87
+ accessorise(element)
88
+ end
89
+
90
+ def date_picker(action_id:, placeholder: nil, initial: nil, emoji: nil)
91
+ element = Element::DatePicker.new(
92
+ placeholder: placeholder,
93
+ action_id: action_id,
94
+ initial: initial,
95
+ emoji: emoji
96
+ )
97
+
98
+ yield(element) if block_given?
99
+
100
+ accessorise(element)
101
+ end
102
+
103
+ def external_select(placeholder:, action_id:, initial: nil, min_query_length: nil, emoji: nil)
104
+ element = Element::ExternalSelect.new(
105
+ placeholder: placeholder,
106
+ action_id: action_id,
107
+ initial: initial,
108
+ min_query_length: min_query_length,
109
+ emoji: emoji
110
+ )
111
+
112
+ yield(element) if block_given?
113
+
114
+ accessorise(element)
115
+ end
116
+
117
+ def overflow_menu(action_id:)
118
+ element = Element::OverflowMenu.new(action_id: action_id)
119
+
120
+ yield(element) if block_given?
121
+
122
+ accessorise(element)
123
+ end
124
+
125
+ def static_select(placeholder:, action_id:, emoji: nil)
126
+ element = Element::StaticSelect.new(
127
+ placeholder: placeholder,
128
+ action_id: action_id,
129
+ emoji: emoji
130
+ )
131
+
132
+ yield(element) if block_given?
133
+
134
+ accessorise(element)
135
+ end
136
+
137
+ def users_select(placeholder:, action_id:, initial: nil, emoji: nil)
138
+ element = Element::UsersSelect.new(
139
+ placeholder: placeholder,
140
+ action_id: action_id,
141
+ emoji: emoji,
142
+ initial: initial
143
+ )
144
+
145
+ yield(element) if block_given?
146
+
147
+ accessorise(element)
148
+ end
149
+
150
+ def image(url:, alt_text:)
151
+ accessorize(Element::Image.new(image_url: url, alt_text: alt_text))
152
+ end
153
+
154
+ def accessorise(element)
155
+ @accessory = element
156
+
157
+ self
14
158
  end
15
159
 
16
160
  def as_json(*)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './slack/block_kit'
@@ -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/block_kit'
5
+ require 'slack_block_kit'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'slack_block_kit'
@@ -31,5 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'bundler', '< 2.0'
32
32
  spec.add_development_dependency 'rake'
33
33
  spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'rspec_junit_formatter'
34
35
  spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop-rspec'
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_block_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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: 2019-03-03 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description:
70
98
  email:
71
99
  - c_arlt@hotmail.com
@@ -73,7 +101,9 @@ executables: []
73
101
  extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
104
+ - ".circleci/config.yml"
76
105
  - ".gitignore"
106
+ - ".rspec"
77
107
  - ".rubocop.yml"
78
108
  - ".rubocop_todo.yml"
79
109
  - Gemfile
@@ -82,10 +112,12 @@ files:
82
112
  - README.md
83
113
  - Rakefile
84
114
  - lib/slack/block_kit.rb
115
+ - lib/slack/block_kit/blocks.rb
85
116
  - lib/slack/block_kit/composition/confirmation_dialog.rb
117
+ - lib/slack/block_kit/composition/mrkdwn.rb
86
118
  - lib/slack/block_kit/composition/option.rb
87
119
  - lib/slack/block_kit/composition/option_group.rb
88
- - lib/slack/block_kit/composition/text.rb
120
+ - lib/slack/block_kit/composition/plain_text.rb
89
121
  - lib/slack/block_kit/element/button.rb
90
122
  - lib/slack/block_kit/element/channels_select.rb
91
123
  - lib/slack/block_kit/element/conversations_select.rb
@@ -100,6 +132,7 @@ files:
100
132
  - lib/slack/block_kit/layout/divider.rb
101
133
  - lib/slack/block_kit/layout/image.rb
102
134
  - lib/slack/block_kit/layout/section.rb
135
+ - lib/slack_block_kit.rb
103
136
  - slack_block_kit.gemspec
104
137
  homepage: https://github.com/CGA1123/slack_block_kit-ruby
105
138
  licenses:
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Slack
4
- module BlockKit
5
- module Composition
6
- class Text
7
- def initialize(type:, text:, emoji: nil, verbatim: nil)
8
- @type = type
9
- @text = text
10
- @emoji = emoji
11
- @verbatim = verbatim
12
- end
13
-
14
- def self.plaintext(text:, emoji: nil)
15
- new(
16
- type: 'plain_text',
17
- text: text,
18
- emoji: emoji
19
- )
20
- end
21
-
22
- def self.markdown(text:, verbatim: nil)
23
- new(
24
- type: 'mrkdwn',
25
- text: text,
26
- verbatim: verbatim
27
- )
28
- end
29
-
30
- def as_json(*)
31
- {
32
- type: @type,
33
- text: @text,
34
- emoji: @emoji,
35
- verbatim: @verbatim
36
- }.compact
37
- end
38
- end
39
- end
40
- end
41
- end