{"id":27498314,"url":"https://github.com/davidcelis/block-kit","last_synced_at":"2025-07-27T08:35:27.933Z","repository":{"id":287444973,"uuid":"960702668","full_name":"davidcelis/block-kit","owner":"davidcelis","description":"💬 A Ruby gem to build UI with Slack's BlockKit framework","archived":false,"fork":false,"pushed_at":"2025-06-02T16:02:20.000Z","size":439,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-18T03:50:28.976Z","etag":null,"topics":["block-kit","rails","ruby","ruby-gem","ruby-on-rails","slack"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidcelis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-04T22:41:48.000Z","updated_at":"2025-06-02T15:59:38.000Z","dependencies_parsed_at":"2025-04-11T19:45:16.248Z","dependency_job_id":"71d471da-ba73-4e3f-a2aa-d5982f54f408","html_url":"https://github.com/davidcelis/block-kit","commit_stats":null,"previous_names":["davidcelis/block-kit"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/davidcelis/block-kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcelis%2Fblock-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcelis%2Fblock-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcelis%2Fblock-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcelis%2Fblock-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidcelis","download_url":"https://codeload.github.com/davidcelis/block-kit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcelis%2Fblock-kit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267330015,"owners_count":24069961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["block-kit","rails","ruby","ruby-gem","ruby-on-rails","slack"],"created_at":"2025-04-17T08:31:35.140Z","updated_at":"2025-07-27T08:35:27.927Z","avatar_url":"https://github.com/davidcelis.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Block Kit\n\n`block-kit` is a Ruby library for Slack's [Block Kit](https://api.slack.com/block-kit) framework built on ActiveModel, providing a powerful DSL for building surfaces like modals, home tabs, messages, or even just blocks themselves.\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n```bash\nbundle add block-kit\n```\n\nOr just install it globally:\n\n```bash\ngem install block-kit\n```\n\n## Usage\n\nBlocks can be built individually or as a surface or collection of blocks, which each block able to initialize with a simple Hash of attributes or via a block-based DSL. For example, each of the following declarations would result in the same `section` block:\n\n```ruby\nrequire \"block-kit\"\n\nsection = BlockKit::Layout::Section.new(text: BlockKit::Composition::Mrkdwn.new(text: \"Hello, world!\"))\nsection = BlockKit::Layout::Section.new(text: \"Hello, world!\")\nsection = BlockKit::Layout::Section.new do |s|\n  # With one of any of the following:\n  s.mrkdwn(text: \"Hello, world!\")\n  s.text(\"Hello, world!\")\n  s.text = BlockKit::Composition::Mrkdwn.new(text: \"Hello, world!\")\n  s.text = {type: \"mrkdwn\", text: \"Hello, world!\"}\n  s.text = \"Hello, world!\" # Defaults to `mrkdwn` for section blocks\nend\n```\n\nBecause each block is built using ActiveModel, attributes are cast to their appropriate types from a variety of inputs. If a block contains another block, you can even assign that nested block as a Hash, which means you should be able to completely reconstruct views or messages from the JSON they serialize to. Additionally, like other ActiveModel classes, values that cannot be cast simply result in `nil`, including when you attempt to do something like add an element to a block that doesn't support it.\n\nActiveModel and the extensive DSL provides a powerful and flexible way to build UI in Slack. Here's an end-to-end example of building a message and a modal and sending them to Slack:\n\n```ruby\nrequire \"slack-ruby-client\"\nrequire \"block-kit\"\n\nfooter = BlockKit::Layout::Context.new do |c|\n  c.mrkdwn(text: \"_Made with :heart: in Portland, OR_\")\nend\n\n# Or `BlockKit::Blocks.new do |b|`\nblocks = BlockKit.blocks do |b|\n  b.header(text: \"Hello, :earth_americas:!\", emoji: true)\n\n  b.divider\n\n  b.section(block_id: \"content\") do |s|\n    s.mrkdwn(text: \"Welcome to Block Kit!\")\n    s.button(text: \"Learn more\", style: \"primary\", url: \"https://api.slack.com/block-kit\")\n  end\n\n  b.append(footer)\nend\n\nclient = Slack::Web::Client.new\nclient.chat_postMessage(\n  channel: \"#general\",\n  blocks: blocks.to_json,\n  text: \"Hello, world!\"\n)\n\nmodal = BlockKit.modal(blocks: blocks) do |m|\n  m.title(text: \"Hello, :earth_americas:!\", emoji: true)\n  m.close(text: \"Close\", emoji: true)\nend\n\nclient.views_open(\n  trigger_id: \"trigger_id\",\n  view: modal.to_json\n)\n```\n\nMost DSL methods you call while building blocks will accept optional keyword arguments for the block's attributes and will yield the block itself, allowing you to choose how you want to build your blocks.\n\nAnother benefit of being built on ActiveModel is that all documented limitations of BlockKit are enforced as model validations, with surfaces and collections validating all blocks within them. For example:\n\n```ruby\nmodal = BlockKit.modal do |m|\n  m.title(text: \"Hello, world! Welcome to Block Kit!\")\n\n  m.section(block_id: \"content\") do |s|\n    s.mrkdwn(text: \"Welcome to Block Kit!\")\n    s.button(text: \"Learn more\", style: \"primary\", url: \"invalid.url\")\n  end\n\n  m.append(footer)\nend\n\nmodal.valid?\n# =\u003e false\n\nmodal.errors.full_messages\n[\"Blocks is invalid\", \"Blocks[0] is invalid: accessory.url is not a valid URI\", \"Title is too long (maximum is 24 characters)\"]\n```\n\nThis allows you to catch most issues that would result in an `invalid_blocks` error from Slack before you even send the request. Better yet, `block-kit` provides a way to fix any validation error that wouldn't result in changing the behavior of your view. For instance:\n\n```ruby\nmodal = BlockKit.modal do |m|\n  m.title(text: \"Hello, world! Welcome to Block Kit!\")\n\n  m.section(block_id: \"content\") do |s|\n    s.mrkdwn(text: \"Welcome to Block Kit!\")\n    s.button(text: \"Learn more\", style: \"\", url: \"https://api.slack.com/block-kit\")\n  end\n\n  m.append(footer)\nend\n\nmodal.valid?\n# =\u003e false\n\nmodal.errors.full_messages\n# =\u003e [\"Blocks is invalid\", \"Blocks[0] is invalid: accessory.style can't be blank\", \"Title is too long (maximum is 24 characters)\"]\n\nmodal.fix_validation_errors\n# =\u003e true # or false if any errors couldn't be fixed\n\nmodal.title\n# =\u003e #\u003cBlockKit::Composition::PlainText text: \"Hello, world! Welcome...\", emoji: nil\u003e\n\nmodal.blocks.first.accessory\n# =\u003e #\u003cBlockKit::Elements::Button text: #\u003cBlockKit::Composition::PlainText text: \"Learn more\", emoji: nil\u003e, style: nil, ...\u003e\n```\n\nThe gem can also be configured to fix validation errors automatically on validation or when rendering as JSON if you don't want to have to remember to call `fix_validation_errors` yourself:\n\n```ruby\nBlockKit.configure do |config|\n  # You can set both of these, but `autofix_on_render` is likely enough if you\n  # prefer not to have to call `valid?` at all. Note that `autofix_on_render`\n  # does _not_ mean that only the resulting JSON is fixed; it still fixes the\n  # underlying model's attributes, meaning the model will be mutated.\n  config.autofix_on_validation = true\n  config.autofix_on_render = true\n\n  # Set this to perform autofixes that may change the behavior of your view. This\n  # is useful if you would rather post messages or publish views at the cost of\n  # behavioral quirks or changes rather than suffer from `invalid_blocks` errors.\n  #\n  # If you'd prefer to run dangerous autofixers on demand, you can do this by\n  # calling `fix_validation_errors(dangerous: true)` on your blocks or surfaces.\n  config.autofix_dangerously = true\nend\n```\n\nAutofixers currently include:\n\n* Truncating long text fields to their maximum length\n* Setting optional attributes to `nil` if they are blank\n\nDangerous autofixers (which can be run by calling `fix_validation_errors(dangerous: true)`) that may change the behavior of your view include:\n\n* Truncating long _lists_ of blocks or elements to their maximum length (such as surface blocks, options, option groups, actions elements, etc.)\n* Truncating URLs to their maximum length\n* Removing section accessories or actions/input elements from surfaces that don't support them\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/davidcelis/block-kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/davidcelis/block-kit/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the project's codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/davidcelis/block-kit/blob/main/CODE_OF_CONDUCT.md).\n\n## Acknowledgements\n\nSpecial thanks to [FireHydrant](https://firehydrant.com) for allowing me to build the initial version on the job (and therefore sponsoring the project)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcelis%2Fblock-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidcelis%2Fblock-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcelis%2Fblock-kit/lists"}