slackblocks 2.5.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +7 -0
- data/LICENSE.BSD-3-Clause +29 -0
- data/README.md +44 -0
- data/lib/slackblocks/components.rb +59 -0
- data/lib/slackblocks/generated/limits.rb +9 -0
- data/lib/slackblocks/generated/models.rb +979 -0
- data/lib/slackblocks/generated/style_flags.rb +6 -0
- data/lib/slackblocks/generated/vocabulary.rb +7 -0
- data/lib/slackblocks/rich_text_style.rb +13 -0
- data/lib/slackblocks/validation_error.rb +18 -0
- data/lib/slackblocks/validator.rb +284 -0
- data/lib/slackblocks/value.rb +274 -0
- data/lib/slackblocks/version.rb +4 -0
- data/lib/slackblocks.rb +11 -0
- data/sig/slackblocks/generated.rbs +1268 -0
- data/sig/slackblocks.rbs +76 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9dcbdcf2798b0c73114cdf30db0afbf6606e3ea8a3533b29171621e5a3415f48
|
|
4
|
+
data.tar.gz: 101404a4d300ac0ea813a0b70b31fb6301348158d3ee43794c391d35b5585296
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7d8206a548bda392603f75ca6f46e979945eb16842b9541997afc6bc39b7672b77556c0636e0e72c67c057c1a3f541c82bb2d6cf5795009b5dca6706b4fcecf9
|
|
7
|
+
data.tar.gz: a9bc196c52ab8df1caefa398cfe30f818d3f4b0696a8e6bb3138e4997a3040ac3df1353f41e80f7856b63c3f59db742c1355b671a85ec70548c6120ba24cb64e
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2019 Nicholas Lambourne
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019, Nicholas Lambourne
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# slackblocks for Ruby
|
|
2
|
+
|
|
3
|
+
Build and validate Slack Block Kit payloads with Ruby 3.3 or newer. The gem implements shared spec 1.2.0 and uses only Ruby's JSON default gem at runtime.
|
|
4
|
+
|
|
5
|
+
Install from the repository while the first Ruby release is being prepared:
|
|
6
|
+
|
|
7
|
+
cd ruby
|
|
8
|
+
gem build slackblocks.gemspec
|
|
9
|
+
gem install ./slackblocks-2.5.0.gem
|
|
10
|
+
|
|
11
|
+
Use keyword arguments for every value:
|
|
12
|
+
|
|
13
|
+
require "slackblocks"
|
|
14
|
+
|
|
15
|
+
button = Slackblocks::ButtonElement.new(text: "Open", action_id: "open")
|
|
16
|
+
blocks = [
|
|
17
|
+
Slackblocks::SectionBlock.new(text: "Hello"),
|
|
18
|
+
Slackblocks::ActionsBlock.new(elements: [button])
|
|
19
|
+
]
|
|
20
|
+
message = Slackblocks::MessagePayload.new(channel: "C123", blocks: blocks)
|
|
21
|
+
puts message.to_json
|
|
22
|
+
|
|
23
|
+
Strings in text fields become the plain text or mrkdwn object specified for that field. Named enum fields take symbols such as :in_channel, :complete, or :primary. Constructors reject invalid Slack values with Slackblocks::ValidationError, whose category and path identify the rule and field.
|
|
24
|
+
|
|
25
|
+
All values are immutable. with(**changes) returns a validated value, to_h returns structural Ruby members, and as_json returns a fresh Slack wire Hash. to_json, JSON.generate(value), and ActiveSupport::JSON.encode(value) produce the same payload. ActiveSupport is optional and is never loaded by the gem.
|
|
26
|
+
|
|
27
|
+
For unmodeled Slack fields, pass additional_fields: { "future_field" => value }. Extensions cannot replace known fields or the wire type. The gem copies and freezes owned strings and collections, including extensions.
|
|
28
|
+
|
|
29
|
+
Helpers return ordinary values that can be placed in block collections:
|
|
30
|
+
|
|
31
|
+
section = Slackblocks::AccordionSection.create(
|
|
32
|
+
title: "Details",
|
|
33
|
+
blocks: [Slackblocks::SectionBlock.new(text: "More information")]
|
|
34
|
+
)
|
|
35
|
+
accordion_blocks = Slackblocks::Accordion.create(sections: [section])
|
|
36
|
+
|
|
37
|
+
page_blocks = Slackblocks::Paginator.create(
|
|
38
|
+
action_id_prefix: "items",
|
|
39
|
+
blocks: blocks,
|
|
40
|
+
page: 1,
|
|
41
|
+
page_size: 5
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
Slackblocks::VERSION is the gem version; Slackblocks::SPEC_VERSION is the shared contract version. To verify the implementation locally, run ruby/bin/check from the repository with Ruby 3.3, 3.4, and 4.0 installed.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Slackblocks
|
|
2
|
+
module AccordionSection
|
|
3
|
+
def self.create(title:, blocks:, subtitle: nil, icon: nil, expanded: false, width: ContainerWidth::STANDARD, has_header_divider: false, block_id: nil)
|
|
4
|
+
ContainerBlock.new(
|
|
5
|
+
title: title,
|
|
6
|
+
child_blocks: blocks,
|
|
7
|
+
subtitle: subtitle,
|
|
8
|
+
icon: icon,
|
|
9
|
+
width: width,
|
|
10
|
+
is_collapsible: true,
|
|
11
|
+
default_collapsed: !expanded,
|
|
12
|
+
has_header_divider: has_header_divider,
|
|
13
|
+
block_id: block_id
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module Accordion
|
|
19
|
+
def self.create(sections:)
|
|
20
|
+
Value.fail!("type-mismatch", "Accordion.sections", "expected an Array") unless sections.is_a?(Array)
|
|
21
|
+
Value.fail!("missing-required", "Accordion.sections", "expected at least one section") if sections.empty?
|
|
22
|
+
sections.each_with_index do |section, index|
|
|
23
|
+
unless section.is_a?(ContainerBlock) && section.is_collapsible
|
|
24
|
+
Value.fail!("type-mismatch", "Accordion.sections[#{index}]", "expected a collapsible container")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
sections.dup.freeze
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module Paginator
|
|
32
|
+
def self.create(action_id_prefix:, blocks:, page: 1, page_size: 5, previous_text: "Previous", next_text: "Next", show_page_indicator: true, block_id: nil)
|
|
33
|
+
Value.fail!("type-mismatch", "Paginator.blocks", "expected an array of blocks") unless blocks.is_a?(Array) && blocks.all? { |block| block.is_a?(Block) }
|
|
34
|
+
Value.fail!("missing-required", "Paginator.blocks", "expected at least one block") if blocks.empty?
|
|
35
|
+
Value.fail!("type-mismatch", "Paginator.action_id_prefix", "expected a string") unless action_id_prefix.is_a?(String)
|
|
36
|
+
Value.fail!("missing-required", "Paginator.action_id_prefix", "expected a non-empty prefix") if action_id_prefix.empty?
|
|
37
|
+
[[:page, page], [:page_size, page_size]].each do |field, value|
|
|
38
|
+
Value.fail!("type-mismatch", "Paginator.#{field}", "expected an Integer") unless value.is_a?(Integer)
|
|
39
|
+
Value.fail!("out-of-range", "Paginator.#{field}", "expected a positive integer") if value < 1
|
|
40
|
+
end
|
|
41
|
+
page_count = (blocks.length + page_size - 1) / page_size
|
|
42
|
+
Value.fail!("out-of-range", "Paginator.page", "page exceeds page count") if page > page_count
|
|
43
|
+
result = blocks.drop((page - 1) * page_size).take(page_size)
|
|
44
|
+
return result.freeze if page_count == 1
|
|
45
|
+
|
|
46
|
+
# @type var controls: Array[ButtonElement]
|
|
47
|
+
controls = []
|
|
48
|
+
if page > 1
|
|
49
|
+
controls << ButtonElement.new(text: previous_text, action_id: "#{action_id_prefix}.previous", value: (page - 1).to_s)
|
|
50
|
+
end
|
|
51
|
+
if page < page_count
|
|
52
|
+
controls << ButtonElement.new(text: next_text, action_id: "#{action_id_prefix}.next", value: (page + 1).to_s)
|
|
53
|
+
end
|
|
54
|
+
result << ContextBlock.new(elements: [MarkdownText.new(text: "Page #{page} of #{page_count}")]) if show_page_indicator
|
|
55
|
+
result << ActionsBlock.new(elements: controls, block_id: block_id)
|
|
56
|
+
result.freeze
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Generated from spec/limits.json. Do not edit by hand.
|
|
2
|
+
module Slackblocks
|
|
3
|
+
module Limits
|
|
4
|
+
VALUES = {"action_id.max_length" => 255, "actions.elements.max_items" => 25, "alert.text.max_length" => 200, "block_id.max_length" => 255, "button.accessibility_label.max_length" => 75, "button.text.max_length" => 75, "button.url.max_length" => 3000, "button.value.max_length" => 2000, "card.actions.max_items" => 3, "card.body.max_length" => 200, "card.subtext.max_length" => 200, "card.subtitle.max_length" => 150, "card.title.max_length" => 150, "carousel.elements.max_items" => 10, "carousel.elements.min_items" => 1, "checkboxes.options.max_items" => 10, "checkboxes.options.min_items" => 1, "confirmation.confirm.max_length" => 30, "confirmation.deny.max_length" => 30, "confirmation.text.max_length" => 300, "confirmation.title.max_length" => 100, "container.child_blocks.max_items" => 10, "container.child_blocks.min_items" => 1, "container.subtitle.max_length" => 150, "container.title.max_length" => 150, "context.elements.max_items" => 10, "context_actions.elements.max_items" => 5, "conversation_filter.include.min_items" => 1, "data_table.cell_text.min_length" => 1, "data_table.columns.max_items" => 20, "data_table.columns.min_items" => 1, "data_table.content.max_length" => 20000, "data_table.page_size.max" => 100, "data_table.page_size.min" => 1, "data_table.row_header_column_index.min" => 0, "data_table.rows.max_items" => 201, "data_table.rows.min_items" => 2, "data_table.total_content.max_length" => 20000, "data_visualization.axis_label.max_length" => 50, "data_visualization.categories.max_items" => 20, "data_visualization.categories.min_items" => 1, "data_visualization.category_label.max_length" => 20, "data_visualization.data.max_items" => 20, "data_visualization.data.min_items" => 1, "data_visualization.point_label.max_length" => 20, "data_visualization.segment.label.max_length" => 20, "data_visualization.segment.value.exclusive_min" => 0, "data_visualization.segments.max_items" => 12, "data_visualization.segments.min_items" => 1, "data_visualization.series.max_items" => 12, "data_visualization.series.min_items" => 1, "data_visualization.series_name.max_length" => 20, "data_visualization.title.max_length" => 50, "date_picker.placeholder.max_length" => 150, "dispatch_action_configuration.trigger_actions_on.max_items" => 2, "dispatch_action_configuration.trigger_actions_on.min_items" => 1, "email_input.placeholder.max_length" => 150, "feedback_button.accessibility_label.max_length" => 75, "feedback_button.text.max_length" => 75, "feedback_button.value.max_length" => 2000, "file_input.max_files.max" => 10, "file_input.max_files.min" => 1, "header.text.max_length" => 150, "icon_button.accessibility_label.max_length" => 75, "icon_button.value.max_length" => 2000, "icon_button.visible_to_user_ids.max_items" => 10, "image.alt_text.max_length" => 2000, "image.image_url.max_length" => 3000, "image.title.max_length" => 2000, "image_element.alt_text.max_length" => 2000, "image_element.image_url.max_length" => 3000, "input.hint.max_length" => 2000, "input.label.max_length" => 2000, "markdown.text.max_length" => 12000, "markdown.total_text.max_length" => 12000, "message.attachments.max_items" => 100, "message.blocks.max_items" => 50, "message.channel.min_length" => 1, "multi_select.max_selected_items.min" => 1, "number_input.placeholder.max_length" => 150, "option.description.max_length" => 75, "option.text.max_length" => 75, "option.url.max_length" => 3000, "option.value.max_length" => 150, "option_group.label.max_length" => 75, "option_group.options.max_items" => 100, "option_group.options.min_items" => 1, "overflow.options.max_items" => 5, "overflow.options.min_items" => 1, "plain_text_input.max_length.max" => 3000, "plain_text_input.max_length.min" => 1, "plain_text_input.min_length.max" => 3000, "plain_text_input.min_length.min" => 0, "plain_text_input.placeholder.max_length" => 150, "plan.tasks.max_items" => 50, "radio_buttons.options.max_items" => 10, "radio_buttons.options.min_items" => 1, "rich_text_input.max_lines.max" => 100, "rich_text_input.max_lines.min" => 1, "rich_text_input.min_lines.max" => 100, "rich_text_input.min_lines.min" => 1, "rich_text_input.placeholder.max_length" => 150, "rich_text_list.border.max" => 1, "rich_text_list.border.min" => 0, "rich_text_list.indent.max" => 8, "rich_text_list.indent.min" => 0, "rich_text_list.offset.min" => 0, "rich_text_preformatted.border.max" => 1, "rich_text_preformatted.border.min" => 0, "rich_text_quote.border.max" => 1, "rich_text_quote.border.min" => 0, "section.fields.item_max_length" => 2000, "section.fields.max_items" => 10, "section.text.max_length" => 3000, "select.option_groups.max_items" => 100, "select.options.max_items" => 100, "select.placeholder.max_length" => 150, "table.column_settings.max_items" => 20, "table.columns.max_items" => 20, "table.rows.max_items" => 100, "text.max_length" => 3000, "text.min_length" => 1, "time_picker.placeholder.max_length" => 150, "url_input.placeholder.max_length" => 150, "video.alt_text.max_length" => 2000, "video.author_name.max_length" => 50, "video.description.max_length" => 200, "video.provider_icon_url.max_length" => 2000, "video.provider_name.max_length" => 50, "video.thumbnail_url.max_length" => 3000, "video.title.max_length" => 200, "video.title_url.max_length" => 2000, "video.video_url.max_length" => 3000, "view.blocks.max_items" => 100, "view.callback_id.max_length" => 255, "view.close.max_length" => 24, "view.external_id.max_length" => 255, "view.private_metadata.max_length" => 3000, "view.submit.max_length" => 24, "view.title.max_length" => 24, "workflow_button.accessibility_label.max_length" => 75, "workflow_button.text.max_length" => 75}.freeze
|
|
5
|
+
def self.[](path)
|
|
6
|
+
VALUES.fetch(path)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|