Skip to content

Commit

Permalink
Merge pull request #20 from shivam091/0.6.1
Browse files Browse the repository at this point in the history
0.6.1
  • Loading branch information
shivam091 committed May 24, 2023
2 parents 0c82545 + 7c06053 commit 9614ee8
Show file tree
Hide file tree
Showing 63 changed files with 1,599 additions and 316 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,38 @@ on:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11-alpine
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- "3.2.2"
steps:
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
sudo apt-get install -y libvips
sudo apt-get install -yqq libpq-dev
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Set up database
run: |
bundle exec rake db:create
bundle exec rake db:migrate
- name: Run test cases
run: bundle exec rake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ demo/log/**
demo/tmp/**/*
demo/*.byebug_history
demo/public/assets
demo/config/database.yml
113 changes: 111 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
## [Unreleased]
# Change Log

You can find recent releases with docs in GitHub:

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

## [0.6.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.0...v0.6.1) - 2023-05-24

### What's changed
- Changes in directory structure
- Added test cases
- Added README and CHANGELOG

## [0.6.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.3...v0.6.0) - 2023-05-22

### What's new
- Added support for **`horizontal`** form layout

## [0.5.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.2...v0.5.3) - 2023-05-21

### What's changed
- Added new option inline to render checkboxes and radio buttons inline

## [0.5.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.1...v0.5.2) - 2023-05-21

### What's new
- Added option to add custom options to the field's wrapper
- Added option to apply user defined CSS class to the field
- Added option to control size of input group and field
- Added provision to change id of the field and corresponding label

### What's changed
- Added `mb-3` css class to field wrapper if radio buttons or check boxes are not inline

## [0.5.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.0...v0.5.1) - 2023-05-20

### What's new
- Wrapped `collection_check_boxes` and `collection_radio_buttons` inside field wrapper.

## [0.5.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.2...v0.5.0) - 2023-05-20

### What's new
- Added wrapper methods for `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` to support Bootstrap 5 form styles

### What's changed
- Replaced HTML tag of help_text component from `<span>` to `<div>`

## [0.4.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.1...v0.4.2) - 2023-05-16

### What's new
- Added wrapper method for `grouped_collection_select`

## [0.4.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.0...v0.4.1) - 2023-05-16

## [0.1.0] - 2023-05-15
### What's fixed
- Replaced `reverse_merge` by `deep_merge!` in adding new option values to fix bug causing not to merge options.

## [0.4.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.1...v0.4.0) - 2023-05-15

### What's new
- Added wrapper methods for `range_field` and `color_field`
- Added wrapper methods for `time_zone_select` and `hidden_field`
- Added wrapper methods for `date_select`, `time_select`, and `datetime_select`
- Added wrapper method to render static control
- Added wrapper method for `collection_select`

## [0.3.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.0...v0.3.1) - 2023-05-15

### What's fixed
- Bug causing fields to wrap in input group even when content to append and prepend is not available.

## [0.3.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.3...v0.3.0) - 2023-05-15

### What's new
- Added support to wrap field in input group
- Added support to display error messages below the field
- Added support for floating labels for inputs.

## [0.2.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.2...v0.2.3) - 2023-05-15

### What's new
- Added component to mark labels as required

## [0.2.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.1...v0.2.2) - 2023-05-15

### What's new
- Added support to display labels along with the field.

## [0.2.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.0...v0.2.1) - 2023-05-15

### What's new
- Added FieldWrapperBuilder to create wrapper for placing fields and other related components
- Added support to display help text along with the field
- Added wrapper methods for simple form fields

## [0.2.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.1...v0.2.0) - 2023-05-15

### What's new
- Added PORO class `BootstrapFormOptions` to maintain gem specific configuration.
- Added BoostrapFormBuilder and extension methods for Rails form builder.
- Added required models, controllers, and views in demo application.

## [0.1.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.0...v0.1.1) - 2023-05-15

### What's new
- Initialized demo application for demonstrating the working.
- Added generater to copy initializer file required for maintaining global configuration.
- Added Configuration class to maintain configurable options.

## 0.1.0 - 2023-05-15

- Initial release

## [Unreleased]
12 changes: 9 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PATH
remote: .
specs:
rails_bootstrap_form (0.6.0)
rails_bootstrap_form (0.6.1)
actionpack (~> 7.0)
activemodel (~> 7.0)

GEM
remote: http://rubygems.org/
Expand Down Expand Up @@ -79,6 +81,8 @@ GEM
sassc-rails (>= 2.0.0)
builder (3.2.4)
byebug (11.1.3)
compare-xml (0.66)
nokogiri (~> 1.8)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
Expand Down Expand Up @@ -118,6 +122,7 @@ GEM
nio4r (2.5.9)
nokogiri (1.14.4-x86_64-linux)
racc (~> 1.4)
pg (1.5.3)
popper_js (2.11.7)
puma (6.2.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -190,7 +195,6 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.6.2-x86_64-linux)
thor (1.2.2)
tilt (2.1.0)
timeout (0.3.2)
Expand All @@ -207,7 +211,10 @@ PLATFORMS
DEPENDENCIES
bootstrap (~> 5.3.0.alpha3)
byebug
compare-xml
generator_spec
nokogiri
pg (~> 1.1)
puma
rails (~> 7.0)
rails_bootstrap_form!
Expand All @@ -216,7 +223,6 @@ DEPENDENCIES
sassc-rails
simplecov
sprockets-rails
sqlite3 (~> 1.4)

BUNDLED WITH
2.4.10
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# RailsBootstrapForm

**rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate
[Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.

## Minimum Requirements

* Ruby 3.2.2+ (https://www.ruby-lang.org/en/downloads/branches/)
* Rails 7.0+ (https://guides.rubyonrails.org/maintenance_policy.html)
* Bootstrap 5.0+ (https://getbootstrap.com/docs/versions/)

## Installation

Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application. One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0 application created _without_ the `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:

```ruby
gem "bootstrap", "~> 5.0"
```

And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.

Add the `rails_bootstrap_form` gem to your `Gemfile`:

```ruby
gem "rails_bootstrap_form", "~> 0.6.1"
```

Then:

`bundle install`

Depending on which CSS pre-processor you are using, adding the bootstrap form styles differs slightly.
If you use Rails in the default mode without any pre-processor, you'll have to add the following line to your `application.css` file:

```css
*= require rails_bootstrap_form
```

If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails), you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:

```scss
@import "rails_bootstrap_form";
```

## Configuration

`rails_bootstrap_form` can be used without any configuration. However, `rails_bootstrap_form` does have an optional configuration file at `config/initializers/rails_bootstrap_form.rb` for setting options that affect all generated forms in an application. This configuration file is created using the generator
by running the command on the terminal.

```
$ rails generate rails_bootstrap_form:install
```

Example:

```ruby
# config/initializers/rails_bootstrap_form.rb
RailsBootstrapForm.configure do |config|
# to make forms non-compliant with W3C.
config.default_form_attributes = {role: "form", novalidate: true}
end
```

The current configuration options are:

| Option | Default value | Description |
|---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `default_form_attributes` | | Set this option to `{role: "form"}` to make forms non-compliant with W3C, but generate the `role="form"` attribute. |
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require_relative "demo/config/application"

Rails.application.load_tasks
RSpec::Core::RakeTask.new(:spec)

task default: :spec
12 changes: 6 additions & 6 deletions demo/app/views/users/_horizontal_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
<div class="card-body">
<%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
<%= form.text_field :name, autocomplete: "new-name" %>
<%= form.text_field :email, autocomplete: "new-email" %>
<%= form.text_field :password, autocomplete: "new-password" %>
<%= form.email_field :email, autocomplete: "new-email" %>
<%= form.password_field :password, autocomplete: "new-password" %>
<%= form.phone_field :mobile_number %>
<%= form.date_field :birth_date %>
<%= form.radio_button :terms, 1, required: true %>
<%= form.range_field :excellence %>
<%= form.url_field :blog_url %>
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {}, checked: form.object.fruit_id} %>
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
<%= form.color_field :favorite_color %>
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {}} %>
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
<%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %>
<%= address_form.text_area :street %>
<%= address_form.text_field :state %>
<%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
<%= address_form.text_field :postal_code %>
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
{include_blank: "Select Country", bootstrap_form: {}} %>
{include_blank: "Select Country"} %>
<% end %>
<%= form.check_box :terms, required: true %>
<div class="mt-3">
<%= form.submit "Register", class: "btn btn-primary" %>
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
Expand Down
16 changes: 8 additions & 8 deletions demo/app/views/users/_vertical_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
Profile Form (Vertical layout)
</div>
<div class="card-body">
<%= bootstrap_form_for @user, bootstrap_form: {} do |form| %>
<%= form.text_field :name, autocomplete: "new-name", class: "dsds", bootstrap_form: {} %>
<%= form.text_field :email, autocomplete: "new-email", bootstrap_form: {} %>
<%= form.text_field :password, autocomplete: "new-password" %>
<%= bootstrap_form_for @user do |form| %>
<%= form.text_field :name, autocomplete: "new-name" %>
<%= form.email_field :email, autocomplete: "new-email" %>
<%= form.password_field :password, autocomplete: "new-password" %>
<%= form.phone_field :mobile_number %>
<%= form.date_field :birth_date %>
<%= form.check_box :terms, bootstrap_form: {switch: false}, required: true %>
<%= form.range_field :excellence %>
<%= form.url_field :blog_url %>
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {}, checked: form.object.fruit_id} %>
<%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
<%= form.color_field :favorite_color %>
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {}} %>
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
<%= form.fields_for :address, include_id: false do |address_form| %>
<%= address_form.text_area :street %>
<%= address_form.text_field :state %>
<%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
<%= address_form.text_field :postal_code %>
<%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
{include_blank: "Select Country", bootstrap_form: {}} %>
{include_blank: "Select Country"} %>
<% end %>
<%= form.check_box :terms, required: true %>
<div class="mt-3">
<%= form.submit "Register", class: "btn btn-primary" %>
<%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
Expand Down
22 changes: 7 additions & 15 deletions demo/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
adapter: postgresql
encoding: unicode
reconnect: false
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 20 } %>

development:
<<: *default
database: db/development.sqlite3
url: <%= ENV["DATABASE_URL"] %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
url: <%= ENV["DATABASE_URL"] %>

production:
<<: *default
database: db/production.sqlite3
url: <%= ENV["DATABASE_URL"] %>
Loading

0 comments on commit 9614ee8

Please sign in to comment.