{"id":19474556,"url":"https://github.com/tomasc/has_stimulus_attrs","last_synced_at":"2026-03-09T12:38:17.221Z","repository":{"id":142764629,"uuid":"610650065","full_name":"tomasc/has_stimulus_attrs","owner":"tomasc","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-13T17:21:09.000Z","size":49,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-14T00:46:53.633Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tomasc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-07T07:49:15.000Z","updated_at":"2026-02-13T17:21:03.000Z","dependencies_parsed_at":"2026-02-13T19:04:12.542Z","dependency_job_id":null,"html_url":"https://github.com/tomasc/has_stimulus_attrs","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/tomasc/has_stimulus_attrs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fhas_stimulus_attrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fhas_stimulus_attrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fhas_stimulus_attrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fhas_stimulus_attrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasc","download_url":"https://codeload.github.com/tomasc/has_stimulus_attrs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fhas_stimulus_attrs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30295576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T11:12:22.024Z","status":"ssl_error","status_checked_at":"2026-03-09T11:10:54.577Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-10T19:25:37.615Z","updated_at":"2026-03-09T12:38:17.182Z","avatar_url":"https://github.com/tomasc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HasStimulusAttrs\n\n[![HasStimulusAttrs](https://github.com/tomasc/has_stimulus_attrs/actions/workflows/ruby.yml/badge.svg)](https://github.com/tomasc/has_stimulus_attrs/actions/workflows/ruby.yml)\n\nHelper methods for dealing with [stimulus](https://stimulus.hotwired.dev/) data attributes.\n\nRelies on [`has_dom_attrs`](https://github.com/tomasc/has_dom_attrs) and [`stimulus_helpers`](https://github.com/tomasc/stimulus_helpers).\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add has_stimulus_attrs\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install has_stimulus_attrs\n\n## Usage\n\nInclude `HasStimulusAttrs` in your class and define a `controller_name` class method:\n\n```ruby\nclass ModalComponent\n  include HasStimulusAttrs\n\n  def self.controller_name\n    \"modal-component\"\n  end\nend\n```\n\n`controller_name` can also be defined in a base class and dynamically resolved:\n\n```ruby\nclass ApplicationComponent\n  include HasStimulusAttrs\n\n  def self.controller_name\n    self.name.underscore.dasherize\n  end\nend\n\nclass DetailsComponent \u003c ApplicationComponent\nend\n\nDetailsComponent.controller_name\n# =\u003e \"details-component\"\n```\n\nYou can then use the included class methods to easily set stimulus attributes on\nyour class:\n\n```ruby\nclass ModalComponent \u003c ApplicationComponent\n  # Controller\n  has_stimulus_controller # sets the \"controller\" data attribute using :controller_name by default\n  has_stimulus_controller \"click-outside\"\n  has_stimulus_controller \"scroll-lock\", if: :open? # conditionally add the controller\n  has_stimulus_controller \"scroll-lock\", unless: :closed? # conditionally add the controller\n\n  # Action\n  has_stimulus_action \"click\", \"onClick\"\n  has_stimulus_action \"click\", \"onClick\", if: :open?\n\n  # Class\n  has_stimulus_class \"open\", \"modal--open\"\n  has_stimulus_class \"width\", -\u003e { \"modal--#{width}\" } # resolve the class name dynamically\n\n  # Outlet\n  has_stimulus_outlet \"outlet\", \".selector\"\n\n  # Param\n  has_stimulus_param :id, 123\n  has_stimulus_param :id, -\u003e { id }\n\n  # Target\n  has_stimulus_target \"target\"\n  has_stimulus_target \"target\", controller: \"other-controller\"\n\n  # Value\n  has_stimulus_value \"id\", 123\n  has_stimulus_value \"id\", -\u003e { id }\n  has_stimulus_value \"id\", -\u003e { id }, controller: \"other-controller\"\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. 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/tomasc/has_stimulus_attrs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fhas_stimulus_attrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasc%2Fhas_stimulus_attrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fhas_stimulus_attrs/lists"}