Skip to content

Commit

Permalink
Merge pull request #36 from shivam091/0.9.3
Browse files Browse the repository at this point in the history
0.9.3
  • Loading branch information
shivam091 committed Jun 4, 2023
2 parents aa7b301 + cb6b202 commit 9bf4770
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 194 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -44,3 +44,5 @@ jobs:
bundle exec rake db:migrate
- name: Run test cases
run: bundle exec rake
# - name: Rubocop
# run: bundle exec rubocop --autocorrect
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,16 @@ You can find recent releases with docs in GitHub:

https://github.com/shivam091/rails_bootstrap_form/releases

## [0.9.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.2...v0.9.3) - 2023-06-04

### What's changed

- Disabled floating labels for unsupported helpers

### What's fixed

- `id` of check box field when used in collection and don't has multiple select. (`collection_check_boxes` with `multiple: false`)

## [0.9.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03

### What's new
Expand Down
146 changes: 146 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,146 @@
# Contributing

Thank you so much for considering a contribution to `rails_bootstrap_form`. We love pull requests!

We want everyone to feel welcome to contribute. We encourage respectful exchanges of ideas. We govern ourselves with the Contributor Covenant [Code of Conduct](/CODE_OF_CONDUCT.md).

There are a number of ways you can contribute to `rails_bootstrap_form`:

- Fix a bug or add a new feature
- Add to the documentation
- Review pull requests

## Code Contributions

Here's a quick guide for code contributions:

### 1. Check if issue or feature is available to work on

Make sure no one else is working on the same issue or feature. Search the issues
and pull requests for anything that looks like the issue or feature you want to
address. If no one else is working on your issue or feature, carry on with the
following steps.

### 2. Create an issue, and wait a few days for someone to respond (Optional)

If you create an issue for your feature request or bug, it gives the maintainers a chance to comment on your ideas before you invest a lot of work on a contribution. It may save you some re-work compared to simply submitting a pull request. It's up to you whether you submit an issue.

### 3. Fork the repo

Fork the project. Optionally, create a branch you want to work on.

### 4. Get it running locally

- Install the required dependencies with `bundle install`
- Run tests via: `bundle exec rake`

### 5. Hack away

- Try to keep your changes small. Consider making several smaller pull requests if your changes are extensive.
- Don't forget to add necessary tests and make sure that all tests run successfully.
- Update the README if necessary.
- Add a line to the CHANGELOG for your bug fix or feature.
- Read the [Coding Guidelines](#coding-guidelines) section and make sure that `bundle exec rubocop --autocorrect` doesn't find any offences.

You may find the [demo application](#the-demo-application) useful for development and debugging.

### 6. Make a pull request

- If you've never made a pull request (PR) before, read [this](https://help.github.com/articles/about-pull-requests/).
- If your PR fixes an issues, be sure to put "Fixes #nnn" in the description of the PR (where `nnn` is the issue number). Github will automatically close the issue when the PR is merged.
- When the PR is submitted, check if Travis CI ran all the tests successfully, and didn't raise any issues.

### 7. Done

Somebody will shortly review your pull request and if everything is good, it will be
merged into the main branch. Eventually the gem will be published with your changes.

### Coding guidelines

This project uses [RuboCop](https://github.com/bbatsov/rubocop) to enforce standard Ruby coding guidelines.

- Test that your contribution passes with `bundle exec rubocop`.
- RuboCop is also run as part of the full test suite with `bundle exec rake`.
- Note the Travis build will fail and your PR cannot be merged if RuboCop finds offences.

Note that most editors have plugins to run RuboCop as you type, or when you save a file. You may find it well worth your time to install and configure the RuboCop plugin for your editor. Read the [RuboCop documentation](https://rubocop.readthedocs.io/en/latest/integration_with_other_tools/).

### Supported Versions of Ruby and Rails

The goal of `rails_bootstrap_form` is to support all versions of Rails (higher than 7.0) for bug fixes and security issues. We do not test against versions supported for severe security issues. We test against the minimum [version of Ruby required](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions) for those versions of Rails.

The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html).

### The Demo Application

There is a demo app in this repository. It shows some of the features of `rails_bootstrap_form`, and provides a base on which to build ad-hoc testing, if you need it.

Currently, the demo app is only set up to run for Rails 7, due to the variety of ways to include CSS and JavaScript in a modern Rails application.
To run the demo app, set up the database and run the server:

```bash
cd demo
bundle
rails db:create
rails db:migrate
```

You'll see errors in the browser console about duplicate ids. This is expected, since the demo app has many forms with the same fields in them. Something we can fix in the future, perhaps.

To use other supported versions of Rails, you will need to create a `Gemfile` for the Rails version. Then, change the `export BUNDLE_GEMFILE...` line to your gem file. Finally, figure out how to include the assets.

If you need to run the Rails server separately, for example, to debug the server, you _must_ run it like this:

```sh
bundle exec rails s -b 0.0.0.0
```

If you run just `rails` or even `bin/rails`, the `sprockets-rails` gem won't load and you'll either get error messages, or the assets won't be available to the demo app. At the moment it's a mystery why. PRs to fix this are welcome.

Please try to keep the checked-in `.ruby-version` set to the oldest supported version of Ruby. You're welcome and encouraged to try the demo app with other Ruby versions. Just don't check in the `.ruby-version` to GitHub.

## Documentation Contributions

Contributions to documentation are always welcome. Even fixing one typo improves the quality of `rails_bootstrap_form`. To make a documentation contribution, follow steps 1-3 of Code Contributions, then make the documentation changes, then make the pull request (step 6 of Code Contributions).

If you put `[ci skip]` in the commit message of the most recent commit of the PR, you'll be a good citizen by not causing our CI pipeline to run all the tests when it's not necessary.

## Reviewing Pull Requests

We are an entirely volunteer project. Sometimes it's hard for people to find the time to review pull requests. You can help! If you see a pull request that's waiting to be merged, it could be because no one has reviewed it yet. Your review could help move the pull request forward to be merged.

---

Thanks to all the [great contributors](https://github.com/shivam091/rails_bootstrap_form/graphs/contributors).

## Troubleshooting

### Models and Database Tables

`rails_bootstrap_form` needs few models and tables to support testing. It appears that the necessary tables were created via the `demo/db/schema.rb` file. To support `rich_text_area`, Rails 7 creates some migrations. These migrations had to be run in the existing database (not an empty one) to create a new `schema.rb` that creates the `rails_bootstrap_form` test tables, and the tables needed by Rails 7. The `schema.rb` file was checked in to GitHub.

In the future, any new Rails functionality that creates tables would likely have to be prepared the same way:

```bash
cd demo
rails db:create
rails db:migrate
```

### RuboCop

When you push a branch, RuboCop checks may fail, but locally you can't reproduce the failure. This may be because you're using a different version of RuboCop locally. When you push, the RuboCop tests use the currently available version of RuboCop. If you've been working on the branch for a while, it's likely you have a `Gemfile.lock` that specifies an older version of RuboCop.

The first thing to try is to update your `Gemfile.lock` locally:

```bash
bundle update
```

Or, if you really want to minimize your work:

```bash
bundle update --conservative rubocop
```

This should enable you to reproduce the RuboCop failures locally, and then you can fix them.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rails_bootstrap_form (0.9.2)
rails_bootstrap_form (0.9.3)
actionpack (~> 7.0)
activemodel (~> 7.0)

Expand Down
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -688,7 +688,7 @@ Here's an example of how you pass the arguments for each form helper:
### check_box

Our `check_box` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box).
This helper will render check box and label for you.
except it don't accept a `block` as an argument and renders check box and label for you.

![check_box](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/5836650c-d536-4f4e-b768-75bca9dd7901)

Expand Down Expand Up @@ -1435,7 +1435,7 @@ This generates the following HTML:

### collection_check_boxes

This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a block as
This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a `block` as
an argument and takes care of rendering labels, check boxes, and wrapper for you.

![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
Expand Down Expand Up @@ -1500,7 +1500,7 @@ This generates the following HTML:

### collection_radio_buttons

This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a block as
This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a `block` as
an argument and takes care of rendering labels, radio button, and wrapper for you.

![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
Expand Down Expand Up @@ -1850,6 +1850,8 @@ This generates the following HTML:
</form>
```

_Floating labels gets disabled by `rails_bootstrap_form` automatically for unsupported helpers._

## Validation and Errors

By default, `rails_bootstrap_form` generations in-line errors which appear below the field.
Expand Down
17 changes: 8 additions & 9 deletions lib/rails_bootstrap_form/helpers.rb
Expand Up @@ -11,22 +11,21 @@ module Helpers
autoload :Labels
autoload :RequiredField
autoload :Errors
autoload :CheckBox
autoload :RadioButton
autoload :Buttons
autoload :Choice

include HelpText
include Labels
include RequiredField
include Errors
include CheckBox
include RadioButton
include Buttons
include Choice

def self.included(base_class)
def collection_input_checked?(checked, obj, input_value)
checked == input_value || Array(checked).try(:include?, input_value) ||
checked == obj || Array(checked).try(:include?, obj)
def sanitized_tag_name(attribute, value)
# label's `for` attribute needs to match checkbox/radio button tag's id, IE sanitized value, IE
# https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125
"#{@object_name}_#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}"
end

def control_specific_class(field_tag_name)
Expand All @@ -52,8 +51,8 @@ def remove_css_class!(options, css_class)
options.delete(:class) if options[:class].blank?
end

private :collection_input_checked?, :control_specific_class, :is_size_valid?,
:add_css_class!, :remove_css_class!
private :control_specific_class, :is_size_valid?, :add_css_class!,
:remove_css_class!
end
end
end
82 changes: 0 additions & 82 deletions lib/rails_bootstrap_form/helpers/check_box.rb

This file was deleted.

0 comments on commit 9bf4770

Please sign in to comment.