This is the stimulus_helpers Ruby gem - a utility library that provides helper methods for building Stimulus controller attributes in Ruby views. The gem makes it easier to work with Stimulus.js by providing a clean Ruby API for generating the necessary HTML attributes.
- Gem Name: stimulus_helpers
- Current Version: 0.1.0
- Ruby Version: 3.1.2
- License: MIT
- Author: Tomáš Celizna
stimulus_helpers/
├── lib/
│ ├── stimulus_helpers.rb # Main module with all helper methods
│ └── stimulus_helpers/
│ └── version.rb # Version constant
├── test/
│ ├── stimulus_helpers_test.rb # Test suite
│ └── test_helper.rb # Test configuration
├── stimulus_helpers.gemspec # Gem specification
├── Gemfile # Dependencies
├── Rakefile # Build tasks
└── README.md # Documentation
bundle exec rake test
# or simply
bundle exec rakebundle exec rubocopbundle installbundle exec rake build- Update the version number in
lib/stimulus_helpers/version.rb - Update CHANGELOG.md with the changes
- Commit the changes
- Run
bundle exec rake release
- Follow the RuboCop configuration in
.rubocop.yml - Use Ruby 3.1+ syntax features (like value omission in hash literals)
- Keep methods focused and well-documented
- Maintain test coverage for all public methods
The gem provides the following helper methods:
- Controller:
stimulus_controller(name) - Actions:
stimulus_action(controller, action, listener)andstimulus_actions(controller, actions) - Classes:
stimulus_class(controller, name, value)andstimulus_classes(controller, classes) - Values:
stimulus_value(controller, name, value)andstimulus_values(controller, values) - Target:
stimulus_target(controller, target) - Params:
stimulus_param(controller, name, value)andstimulus_params(controller, params) - Outlets:
stimulus_outlet(controller, name, value)andstimulus_outlets(controller, outlets)
- The main module uses
build_stimulus_actionandbuild_stimulus_attributeprivate methods to construct the attribute hashes - Complex values (Arrays and Hashes) are automatically converted to JSON
- Attribute names are dasherized to follow Stimulus conventions
- The gem depends on ActiveSupport for string inflections
- Tests are in
test/stimulus_helpers_test.rb - Each helper method has corresponding test coverage
- Tests verify the exact structure of returned hashes
- Run tests with
bundle exec rake test
- Add the public method to
lib/stimulus_helpers.rb - Use the existing private methods (
build_stimulus_actionorbuild_stimulus_attribute) if applicable - Add corresponding tests to
test/stimulus_helpers_test.rb - Update the README.md with usage examples
- Run tests and linter to ensure everything passes
- Use
bin/consoleto start an IRB session with the gem loaded - The test suite uses Minitest - add debugging with
putsor use a debugger gem - Check the GitHub Actions workflow results for CI failures
- Backwards Compatibility: This gem is used by other projects, so maintain backwards compatibility when making changes
- Dependencies: Keep dependencies minimal - currently only requires ActiveSupport
- Documentation: Update README.md when adding new features
- Versioning: Follow semantic versioning (MAJOR.MINOR.PATCH)
- The main branch is protected
- Create feature branches for new work
- Ensure all tests pass before merging
- The GitHub Actions workflow runs on every push
- If tests fail locally but pass in CI, check Ruby version (should be 3.1.2)
- RuboCop violations can often be auto-fixed with
bundle exec rubocop -A - Bundle install issues: try
bundle updateor deleteGemfile.lockand reinstall
Based on the current codebase, potential areas for enhancement:
- Add more comprehensive documentation/examples
- Consider adding type signatures (RBS file is currently minimal)
- Add more edge case testing
- Consider performance optimizations for large attribute sets