block-kit 1.0.4 → 1.0.6

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: 5946d09896645506f0cab7a25f94081426cb76aff710daba32f7435c39a85eef
4
- data.tar.gz: 29c70c2b4165a6b91751b25ad8b8492a97dc76b4e9bfd36b3c21c41a41ec112b
3
+ metadata.gz: a142c83644eae7923a991bffd10fab97d37a473a9b1cd0f272ffe095bec84e76
4
+ data.tar.gz: b85f5fd6a7bc53e2c10ea911aa12c6a1eb04ff5534ba9b204c65636ac429ef29
5
5
  SHA512:
6
- metadata.gz: 92fde835090a61e50d948414f7cc6cf470fa60d46fa7ac7043e24e868949a69d04a93e4fdc25c7e8a916ffa0f43ab4fc36c741b674156ff8b062a5db509f23fb
7
- data.tar.gz: 2fccbc33a2b9cf5475829a7fd8f75b96131f734a87ef19003761587809c5c82892833d3bf876403cccb70e6bf0d5ad743b089e72ab0dd3911dc22773819c1224
6
+ metadata.gz: b7c2e1713de7c0136bf9fc7a6180876214c345a16d51d0f9a1391128f58bd6d9b5ec0c2f3c820b0b425b25db81e524e6a3c185890c199cd17454f5efed050c30
7
+ data.tar.gz: 7b7537a078c37df48f3ff1a468c4f495cdd6e21777a6267f3c4595889e4be9858903f2859843f1489068e8491da4fab441c13bb7e9566560d9d3d9f5e14a294f
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 4.0.1
@@ -4,7 +4,7 @@ require "active_support/core_ext/module/delegation"
4
4
 
5
5
  module BlockKit
6
6
  class Blocks < Base
7
- attribute :blocks, Types::Array.of(Types::Blocks.new(*Layout.all))
7
+ attribute :blocks, Types::Array.of(Types::Blocks.new(*Layout.all)), default: []
8
8
  validates :blocks, "block_kit/validators/associated": true
9
9
  fixes :blocks, associated: true
10
10
 
@@ -22,8 +22,7 @@ module BlockKit
22
22
  delegate_missing_to :blocks
23
23
 
24
24
  def initialize(attributes = {})
25
- attributes = attributes.with_indifferent_access
26
- attributes[:blocks] ||= []
25
+ attributes = {blocks: attributes} if attributes.is_a?(Array)
27
26
 
28
27
  super
29
28
  end
@@ -10,7 +10,7 @@ module BlockKit
10
10
  ON_CHARACTER_ENTERED = "on_character_entered"
11
11
  ].freeze
12
12
 
13
- attribute :trigger_actions_on, Types::Set.of(:string)
13
+ attribute :trigger_actions_on, Types::Set.of(:string), default: []
14
14
  validates :trigger_actions_on, presence: true, "block_kit/validators/array_inclusion": {in: VALID_TRIGGERS}
15
15
  fixes :trigger_actions_on, null_value: {error_types: [:inclusion]}
16
16
 
@@ -22,8 +22,7 @@ module BlockKit
22
22
  end
23
23
 
24
24
  define_method(:"trigger_actions_on_#{value}!") do
25
- self.trigger_actions_on ||= []
26
- self.trigger_actions_on.add(value)
25
+ trigger_actions_on.add(value)
27
26
  end
28
27
  end
29
28
 
@@ -4,7 +4,7 @@ module BlockKit
4
4
  module Concerns
5
5
  module HasInitialOption
6
6
  def initial_option
7
- all_options&.reverse&.find(&:initial?)
7
+ all_options&.rfind(&:initial?)
8
8
  end
9
9
 
10
10
  def as_json(*)
@@ -6,7 +6,7 @@ module BlockKit
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- attribute :elements, Types::Array.of(Types::Blocks.new(*Layout::RichText::Elements.all))
9
+ attribute :elements, Types::Array.of(Types::Blocks.new(*Layout::RichText::Elements.all)), default: []
10
10
  validates :elements, presence: true, "block_kit/validators/associated": true
11
11
  fixes :elements, associated: true
12
12
 
@@ -16,13 +16,6 @@ module BlockKit
16
16
  dsl_method :elements, as: :emoji, type: Layout::RichText::Elements::Emoji, required_fields: [:name], yields: false
17
17
  end
18
18
 
19
- def initialize(attributes = {})
20
- attributes = attributes.with_indifferent_access
21
- attributes[:elements] ||= []
22
-
23
- super
24
- end
25
-
26
19
  def channel(channel_id:, styles: [])
27
20
  style = if styles.present?
28
21
  styles = Array(styles).map { |s| [s.to_s, true] }.to_h
@@ -0,0 +1,25 @@
1
+ module BlockKit
2
+ class Configuration
3
+ # Controls whether or not calling `valid?` or `validate` on a block or surface
4
+ # will automatically apply any fixes that would make the block or surface valid.
5
+ attr_accessor :autofix_on_validation
6
+
7
+ # Controls whether or not calling `as_json` on a block or surface will automatically
8
+ # apply any fixes that would make the block or surface valid.
9
+ attr_accessor :autofix_on_render
10
+
11
+ # Controls whether or not autofixes that may change the behavior of your view should
12
+ # be called. This is useful if you would rather post messages or publish views at the
13
+ # cost of behavioral quirks or changes rather than suffer from `invalid_blocks` errors.
14
+ #
15
+ # If you'd prefer to run dangerous autofixers on demand, you can do this by
16
+ # calling `fix_validation_errors(dangerous: true)` on your blocks or surfaces.
17
+ attr_accessor :autofix_dangerously
18
+
19
+ def initialize
20
+ @autofix_on_validation = false
21
+ @autofix_on_render = false
22
+ @autofix_dangerously = false
23
+ end
24
+ end
25
+ end
@@ -9,7 +9,7 @@ module BlockKit
9
9
 
10
10
  include Concerns::Confirmable
11
11
 
12
- attribute :options, Types::Array.of(Composition::OverflowOption)
12
+ attribute :options, Types::Array.of(Composition::OverflowOption), default: []
13
13
  validates :options, presence: true, length: {maximum: MAX_OPTIONS, message: "is too long (maximum is %{count} options)"}, "block_kit/validators/associated": true
14
14
  fixes :options, truncate: {maximum: MAX_OPTIONS, dangerous: true}, associated: true
15
15
 
@@ -28,14 +28,7 @@ module BlockKit
28
28
  Elements::WorkflowButton
29
29
  ]
30
30
 
31
- def initialize(attributes = {})
32
- attributes = attributes.with_indifferent_access
33
- attributes[:elements] ||= []
34
-
35
- super
36
- end
37
-
38
- attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS))
31
+ attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS)), default: []
39
32
  validates :elements, presence: true, length: {maximum: MAX_ELEMENTS, message: "is too long (maximum is %{count} elements)"}, "block_kit/validators/associated": true
40
33
  fixes :elements, truncate: {maximum: MAX_ELEMENTS, dangerous: true}, associated: true
41
34
 
@@ -12,20 +12,13 @@ module BlockKit
12
12
  Composition::PlainText
13
13
  ].freeze
14
14
 
15
- attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS))
15
+ attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS)), default: []
16
16
  validates :elements, presence: true, length: {maximum: MAX_ELEMENTS, message: "is too long (maximum is %{count} elements)"}, "block_kit/validators/associated": true
17
17
  fixes :elements, truncate: {maximum: MAX_ELEMENTS, dangerous: true}, associated: true
18
18
 
19
19
  dsl_method :elements, as: :mrkdwn, type: Composition::Mrkdwn, required_fields: [:text], yields: false
20
20
  dsl_method :elements, as: :plain_text, type: Composition::PlainText, required_fields: [:text], yields: false
21
21
 
22
- def initialize(attributes = {})
23
- attributes = attributes.with_indifferent_access
24
- attributes[:elements] ||= []
25
-
26
- super
27
- end
28
-
29
22
  def image(alt_text:, image_url: nil, slack_file: nil)
30
23
  if (image_url.nil? && slack_file.nil?) || (image_url && slack_file)
31
24
  raise ArgumentError, "Must provide either image_url or slack_file, but not both."
@@ -11,7 +11,7 @@ module BlockKit
11
11
  ].freeze
12
12
 
13
13
  attribute :style, :string
14
- attribute :elements, Types::Array.of(RichText::Section)
14
+ attribute :elements, Types::Array.of(RichText::Section), default: []
15
15
  attribute :indent, :integer
16
16
  attribute :offset, :integer
17
17
  attribute :border, :integer
@@ -18,7 +18,7 @@ module BlockKit
18
18
  RichText::Section
19
19
  ].freeze
20
20
 
21
- attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS))
21
+ attribute :elements, Types::Array.of(Types::Blocks.new(*SUPPORTED_ELEMENTS)), default: []
22
22
  validates :elements, presence: true, "block_kit/validators/associated": true
23
23
  fixes :elements, associated: true
24
24
 
@@ -32,13 +32,6 @@ module BlockKit
32
32
  alias_method :quote, :rich_text_quote
33
33
  alias_method :section, :rich_text_section
34
34
 
35
- def initialize(attributes = {})
36
- attributes = attributes.with_indifferent_access
37
- attributes[:elements] ||= []
38
-
39
- super
40
- end
41
-
42
35
  def append(element)
43
36
  elements << element
44
37
 
@@ -20,7 +20,7 @@ module BlockKit
20
20
  Layout::Video
21
21
  ]
22
22
 
23
- attribute :blocks, Types::Array.of(Types::Blocks.new(*SUPPORTED_BLOCKS))
23
+ attribute :blocks, Types::Array.of(Types::Blocks.new(*SUPPORTED_BLOCKS)), default: []
24
24
  attribute :private_metadata, :string
25
25
  attribute :callback_id, :string
26
26
  attribute :external_id, :string
@@ -28,13 +28,6 @@ module BlockKit
28
28
  Elements::TimePicker,
29
29
  Elements::UsersSelect
30
30
  ].freeze
31
-
32
- def initialize(attributes = {})
33
- attributes = attributes.with_indifferent_access
34
- attributes[:blocks] ||= []
35
-
36
- super
37
- end
38
31
  end
39
32
  end
40
33
  end
@@ -32,7 +32,7 @@ module BlockKit
32
32
  ].freeze
33
33
 
34
34
  attribute :text, :string
35
- attribute :blocks, Types::Array.of(Types::Blocks.new(*Layout.all))
35
+ attribute :blocks, Types::Array.of(Types::Blocks.new(*Layout.all)), default: []
36
36
  attribute :thread_ts, :string
37
37
  attribute :mrkdwn, :boolean
38
38
 
@@ -53,13 +53,6 @@ module BlockKit
53
53
  dsl_method :blocks, as: :section, type: Layout::Section
54
54
  dsl_method :blocks, as: :video, type: Layout::Video, required_fields: [:alt_text, :title, :thumbnail_url, :video_url], yields: false
55
55
 
56
- def initialize(attributes = {})
57
- attributes = attributes.with_indifferent_access
58
- attributes[:blocks] ||= []
59
-
60
- super
61
- end
62
-
63
56
  def image(alt_text:, image_url: nil, slack_file: nil, title: nil, emoji: nil, block_id: nil)
64
57
  if (image_url.nil? && slack_file.nil?) || (image_url && slack_file)
65
58
  raise ArgumentError, "Must provide either image_url or slack_file, but not both."
@@ -54,13 +54,6 @@ module BlockKit
54
54
  fixes :submit, truncate: {maximum: MAX_BUTTON_LENGTH}, null_value: {error_types: [:blank]}
55
55
  fix :add_default_submit_button
56
56
 
57
- def initialize(attributes = {})
58
- attributes = attributes.with_indifferent_access
59
- attributes[:blocks] ||= []
60
-
61
- super
62
- end
63
-
64
57
  def as_json(*)
65
58
  super.merge(
66
59
  title: title&.as_json,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlockKit
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.6"
5
5
  end
data/lib/block_kit.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/configurable"
3
+ require "active_support/core_ext/module/attribute_accessors"
4
4
 
5
5
  module BlockKit
6
- include ActiveSupport::Configurable
7
-
8
6
  autoload :Base, "block_kit/base"
9
7
  autoload :Blocks, "block_kit/blocks"
10
8
  autoload :Composition, "block_kit/composition"
@@ -18,21 +16,34 @@ module BlockKit
18
16
  autoload :Types, "block_kit/types"
19
17
  autoload :Validators, "block_kit/validators"
20
18
 
19
+ autoload :Configuration, "block_kit/configuration"
21
20
  autoload :VERSION, "block_kit/version"
22
21
 
23
- def self.blocks(&block)
24
- Blocks.new(&block)
22
+ mattr_reader :configuration, default: Configuration.new, instance_reader: false, instance_accessor: false
23
+
24
+ class << self
25
+ alias_method :config, :configuration
26
+ end
27
+
28
+ def self.configure(&block)
29
+ raise ArgumentError, "BlockKit.configure requires a block" unless block_given?
30
+
31
+ yield(configuration)
32
+ end
33
+
34
+ def self.blocks(attributes = {}, &block)
35
+ Blocks.new(attributes, &block)
25
36
  end
26
37
 
27
- def self.home(&block)
28
- Surfaces::Home.new(&block)
38
+ def self.home(attributes = {}, &block)
39
+ Surfaces::Home.new(attributes, &block)
29
40
  end
30
41
 
31
- def self.modal(&block)
32
- Surfaces::Modal.new(&block)
42
+ def self.modal(attributes = {}, &block)
43
+ Surfaces::Modal.new(attributes, &block)
33
44
  end
34
45
 
35
- def self.message(&block)
36
- Surfaces::Message.new(&block)
46
+ def self.message(attributes = {}, &block)
47
+ Surfaces::Message.new(attributes, &block)
37
48
  end
38
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: block-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Celis
@@ -23,20 +23,6 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 7.0.0
26
- - !ruby/object:Gem::Dependency
27
- name: activesupport
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 7.0.0
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 7.0.0
40
26
  description: A powerful and flexible DSL-based library for Slack's Block Kit framework,
41
27
  built on ActiveModel.
42
28
  email:
@@ -46,6 +32,7 @@ extensions: []
46
32
  extra_rdoc_files: []
47
33
  files:
48
34
  - ".rspec"
35
+ - ".tool-versions"
49
36
  - CODE_OF_CONDUCT.md
50
37
  - LICENSE.txt
51
38
  - README.md
@@ -81,6 +68,7 @@ files:
81
68
  - lib/block_kit/concerns/has_placeholder.rb
82
69
  - lib/block_kit/concerns/has_rich_text_elements.rb
83
70
  - lib/block_kit/concerns/plain_text_emoji_assignment.rb
71
+ - lib/block_kit/configuration.rb
84
72
  - lib/block_kit/elements.rb
85
73
  - lib/block_kit/elements/base.rb
86
74
  - lib/block_kit/elements/base_button.rb
@@ -184,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
172
  - !ruby/object:Gem::Version
185
173
  version: '0'
186
174
  requirements: []
187
- rubygems_version: 3.6.8
175
+ rubygems_version: 4.0.3
188
176
  specification_version: 4
189
177
  summary: A powerful DSL-based library for Slack's Block Kit framework.
190
178
  test_files: []