slack_layout 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94f52b39278f2b8041c9eb59e825762eda643641079d0edf9fd6e4fbc85ab8a0
4
+ data.tar.gz: dc645ceda8745a0646b7991a85ce819d8ad4f4f7a17534c38fe752654ffd29d8
5
+ SHA512:
6
+ metadata.gz: c0b6428a6a0933561f404cf0daae32f9b19261e7f5a0898aaeef7046a4275035c97428458087c177123b3c196054e4c960c0800abe41703dbd310cc6b5ef43cd
7
+ data.tar.gz: 4efb710581809828e9d2e832b419b20d285ad73bd19cb3dc6bd8e0c064a29617c234545f9c6723174e05164c11db69eb514b2ace091e0ad552754217d7fa2e18
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in slack_layout.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "slack-ruby-client"
13
+ gem "slack-ruby-block-kit"
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slack_layout (0.1.0)
5
+ slack-ruby-block-kit
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.5.0)
11
+ faraday (2.7.10)
12
+ faraday-net_http (>= 2.0, < 3.1)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-mashify (0.1.1)
15
+ faraday (~> 2.0)
16
+ hashie
17
+ faraday-multipart (1.0.4)
18
+ multipart-post (~> 2)
19
+ faraday-net_http (3.0.2)
20
+ gli (2.21.1)
21
+ hashie (5.0.0)
22
+ multipart-post (2.3.0)
23
+ rake (13.0.6)
24
+ rspec (3.12.0)
25
+ rspec-core (~> 3.12.0)
26
+ rspec-expectations (~> 3.12.0)
27
+ rspec-mocks (~> 3.12.0)
28
+ rspec-core (3.12.2)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-expectations (3.12.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-mocks (3.12.6)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.12.0)
36
+ rspec-support (3.12.1)
37
+ ruby2_keywords (0.0.5)
38
+ slack-ruby-block-kit (0.21.0)
39
+ zeitwerk (~> 2.6)
40
+ slack-ruby-client (2.1.0)
41
+ faraday (>= 2.0)
42
+ faraday-mashify
43
+ faraday-multipart
44
+ gli
45
+ hashie
46
+ zeitwerk (2.6.9)
47
+
48
+ PLATFORMS
49
+ x86_64-darwin-19
50
+
51
+ DEPENDENCIES
52
+ rake (~> 13.0)
53
+ rspec (~> 3.0)
54
+ slack-ruby-block-kit
55
+ slack-ruby-client
56
+ slack_layout!
57
+
58
+ BUNDLED WITH
59
+ 2.2.22
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Borja Garcia de Vinuesa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Borja GVO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # SlackLayout
2
+
3
+ A ruby gem that makes building Slack's BlockKit layouts easy while keeping everything organized.
4
+
5
+ It leverages [Slack::BlockKit](https://github.com/CGA1123/slack-ruby-block-kit) by providing an inheritance pattern that makes building new layouts convenient and fast.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'slack_layout'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install slack_layout
22
+
23
+ ## Usage
24
+ To create a new layout create a new class that inherits from `SlackLayout`. For example:
25
+
26
+ ```ruby
27
+ class MyCustomSlackLayout < SlackLayout
28
+ attr_reader :param1, :param2
29
+
30
+ def initialize(param1, param2)
31
+ @param1 = param1
32
+ @param2 = param2
33
+ super()
34
+ end
35
+
36
+ def blocks
37
+ section do |section|
38
+ section.mrkdwn_field text: param1
39
+ end
40
+
41
+ actions do |actions|
42
+ actions.button(
43
+ text: "Archive Now!",
44
+ style: "danger",
45
+ value: param2,
46
+ action_id: "archive_now",
47
+ emoji: true,
48
+ )
49
+
50
+ actions.button(
51
+ text: "Snooze 14 days",
52
+ style: "primary",
53
+ value: param2,
54
+ action_id: "archive_snooze",
55
+ emoji: true,
56
+ )
57
+ end
58
+ end
59
+ end
60
+ ```
61
+ Then you can use it anywhere in your code:
62
+
63
+ ```ruby
64
+ param1 = "22"
65
+ param2 = "Anything you want to use in your layout"
66
+ layout = MyCustomSlackLayout.new(param1, param2)
67
+ ```
68
+
69
+ Now, you can access the layout json that Slack needs to be sent by calling `as_json` on the layout:
70
+
71
+ ```ruby
72
+ layout.as_json
73
+ ```
74
+
75
+ Which will produce the following json:
76
+
77
+ ```json
78
+ [
79
+ {
80
+ "type": "section",
81
+ "fields": [
82
+ {
83
+ "type": "mrkdwn",
84
+ "text": "The message for a custom layout"
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ "type": "actions",
90
+ "elements": [
91
+ {
92
+ "type": "button",
93
+ "text": {
94
+ "type": "plain_text",
95
+ "text": "Archive Now!",
96
+ "emoji": true
97
+ },
98
+ "action_id": "archive_now",
99
+ "value": "22",
100
+ "style": "danger"
101
+ },
102
+ {
103
+ "type": "button",
104
+ "text": {
105
+ "type": "plain_text",
106
+ "text": "Snooze 14 days",
107
+ "emoji": true
108
+ },
109
+ "action_id": "archive_snooze",
110
+ "value": "22",
111
+ "style": "primary"
112
+ }
113
+ ]
114
+ }
115
+ ]
116
+ ```
117
+
118
+ Then, use it anywhere in Slack. For example, you could use it to extend the functionality of a message in one of your Slack channels.
119
+
120
+ ```ruby
121
+ # Assuming $slack is an already initialized Slack ruby client
122
+ $slack.chat_postMessage(channel: channel_id, blocks: layout.as_json)
123
+ ```
124
+
125
+ For a complete guide on building with Block Kit, please visit https://api.slack.com/block-kit.
126
+
127
+ ## Development
128
+
129
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
130
+
131
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
132
+
133
+ ## Contributing
134
+
135
+ Bug reports and pull requests are welcome at https://github.com/bgvo/slack_layout.
136
+
137
+ ## License
138
+
139
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "slack_layout"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ VERSION = "0.1.2"
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "slack_layout/version"
4
+ require "slack-ruby-block-kit"
5
+
6
+ class SlackLayout
7
+ attr_accessor :layout
8
+
9
+ def initialize
10
+ Slack::BlockKit.blocks do |layout|
11
+ @layout = layout
12
+ end
13
+ build
14
+ end
15
+
16
+ def build
17
+ blocks
18
+ end
19
+
20
+ def blocks
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def as_json
25
+ layout.as_json
26
+ end
27
+
28
+ def method_missing(method, *args, &block)
29
+ layout.send(method, *args, &block)
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/slack_layout/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "slack_layout"
7
+ spec.version = VERSION
8
+ spec.authors = ["Borja Garcia de Vinuesa Ordovas"]
9
+ spec.email = ["hi@bgvo.io"]
10
+
11
+ spec.summary = "Build Slack layouts with ease using BlockKit"
12
+ spec.description = "Pretty easy to use gem to build Slack layouts using BlockKit."
13
+ spec.homepage = "https://bgvo.io"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_runtime_dependency "slack-ruby-block-kit"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack_layout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Borja Garcia de Vinuesa Ordovas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-ruby-block-kit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Pretty easy to use gem to build Slack layouts using BlockKit.
28
+ email:
29
+ - hi@bgvo.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/slack_layout.rb
45
+ - lib/slack_layout/version.rb
46
+ - slack_layout.gemspec
47
+ homepage: https://bgvo.io
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://bgvo.io
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.4.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.2.22
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Build Slack layouts with ease using BlockKit
71
+ test_files: []