diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 000000000..7cc801f7c --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,46 @@ +name: Ruby + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + Lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.2 + bundler-cache: true + - name: Danger + if: ${{ github.event_name == 'pull_request' }} + run: | + gem install danger + export DANGER_GITHUB_API_TOKEN=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 + danger + - name: Rubocop + run: bundle exec rubocop --auto-correct + Test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: [ '3.0', '2.7', '2.6' ] + gemfile: [ '6.1', '6.0', '5.2', 'edge' ] + exclude: + - { ruby-version: '3.0', gemfile: "5.2" } + - { ruby-version: '2.6', gemfile: "edge" } + env: + BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Run tests + run: bundle exec rake test diff --git a/.gitignore b/.gitignore index e7bb8f752..7c02cff54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .bundle/ +.idea log/*.log pkg/ demo/db/*.sqlite3 @@ -13,7 +14,7 @@ test/gemfiles/*.lock Vagrantfile .vagrant -// For the demo app. +# For the demo app. # Ignore uploaded files in development. demo/storage/* @@ -30,3 +31,17 @@ demo/node_modules demo/yarn-error.log demo/yarn-debug.log* demo/.yarn-integrity + +# For stuff that gets created if using the Dockerfile image +.bundle/ +.cache/ +vendor/bundle + +# or .local/share/pry/pry_history if you need to be more exact +.local/ +.irb_history +.byebug_history +# For Debian images with Bash +.bash_history +# For Alpine images +.ash_history diff --git a/.rubocop.yml b/.rubocop.yml index 88cc286dc..213e69d98 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,3 @@ -# Taken from: https://github.com/mattbrictson/rails-template/blob/master/rubocop.yml.tt -# Modified for demo app in `demo/` directory. require: - rubocop-performance - rubocop-rails @@ -8,23 +6,32 @@ AllCops: DisplayCopNames: true DisplayStyleGuide: true TargetRubyVersion: 2.5 + NewCops: enable Exclude: - - "bin/*" + - bin/* - Capfile - demo/bin/* - - "demo/bower_components/**/*" + - demo/bower_components/**/* - demo/config/boot.rb - demo/config/environment.rb - demo/config/initializers/version.rb - demo/db/schema.rb - - "demo/node_modules/**/*" + - demo/node_modules/**/* - demo/Rakefile - - "demo/tmp/**/*" - - "demo/vendor/**/*" + - demo/tmp/**/* + - demo/vendor/**/* - Gemfile - gemfiles/vendor/bundle/**/* + - vendor/bundle/**/* - Guardfile - Rakefile + - vendor/**/* + +Layout/LineLength: + Max: 132 + Exclude: + - "demo/config/**/*" + - "demo/db/**/*" Layout/SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space @@ -45,12 +52,6 @@ Metrics/ClassLength: - "demo/test/**/*" - "test/**/*" -Metrics/LineLength: - Max: 132 - Exclude: - - "demo/config/**/*" - - "demo/db/**/*" - Metrics/MethodLength: Max: 12 Exclude: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6a9867a25..000000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: ruby -rvm: - - 2.7.1 - - 2.6.5 - - 2.5.7 -gemfile: - - gemfiles/6.0.gemfile - - gemfiles/5.2.gemfile -cache: - bundler: true -script: - - bundle exec rake test - -matrix: - include: - # Bleeding edge Ruby and Rails - - rvm: ruby-head - gemfile: gemfiles/edge.gemfile - - # Next version of Rails - - rvm: 2.7.1 - gemfile: gemfiles/edge.gemfile - - # Running one job to execute DANGER bot and linting - - rvm: 2.7.1 - gemfile: gemfiles/6.0.gemfile - script: - - gem install danger - - danger - - bundle exec rake rubocop - - allow_failures: - - rvm: ruby-head - - rvm: 2.7.1 - gemfile: gemfiles/edge.gemfile diff --git a/CHANGELOG.md b/CHANGELOG.md index fe0dff508..faf90194f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,28 @@ ### New features -* Your contribution here! +* [#572](https://github.com/bootstrap-ruby/bootstrap_form/issues/572): Simplify the formatting of the file upload control to follow the new Bootstrap 5 styles +* [#573](https://github.com/bootstrap-ruby/bootstrap_form/issues/573): Add support for Bootstrap 5's floating labels ### Bugfixes +* [#582](https://github.com/bootstrap-ruby/bootstrap_form/issues/582): Fix tests in bootstrap-5 branch, removes Rubocop offenses, and adds testing with Rails 6.1. + +## [5.0.0.alpha1][] + +### Breaking changes + +* [#569] Remove `role="form"` from the default generated form HTML so forms pass W3C validation. (Only a breaking change if you depended on the `form` attribute. `bootstrap_form` doesn't depend on it.) + +### New features + * Your contribution here! +### Bugfixes + +* [#586](https://github.com/bootstrap-ruby/bootstrap_form/pull/586): Fix Rails 6.1 tests on master - [@thimo](https://github.com/thimo). +* [#587](https://github.com/bootstrap-ruby/bootstrap_form/pull/587): Replace `strip_heredoc` with `<<~` - [@thimo](https://github.com/thimo). + ## [4.5.0][] (2020-04-29) ### New features diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4610a54de..46a4b29c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ There are a number of ways you can contribute to `bootstrap_form`: *Note:* If you want to work on preparing `bootstrap_form` for Bootstrap 5, please start from the `bootstrap-5` branch. If you're submitting a pull request with code or documentation, -say that you want to merge your branch to the `bootstrap-5` branch. +target the pull request to the `bootstrap-5` branch. ## Code Contributions @@ -63,7 +63,7 @@ You may find the demo application useful for development and debugging. ### 7. Done! Somebody will shortly review your pull request and if everything is good, it will be -merged into the master branch. Eventually the gem will be published with your changes. +merged into the main branch. Eventually the gem will be published with your changes. ### Coding guidelines @@ -82,6 +82,58 @@ The goal of `bootstrap_form` is to support all versions of Rails currently suppo The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html). +### Developing with Docker + +This repository includes a `Dockerfile` to build an image with the minimum `bootstrap_form`-supported Ruby environment. To build the image: + +```bash +docker build --tag bootstrap_form . +``` + +This builds an image called `bootstrap_form`. You can change that to any tag you wish. Just make sure you use the same tag name in the `docker run` command. + +If you want to use a different Ruby version, or a smaller Linux distribution (although the distro may be missing tools you need): + +```bash +docker build --build-arg "RUBY_VERSION=2.7" --build-arg "DISTRO=slim-buster" --tag bootstrap_form . +``` + +Then run the container you built with the shell, and create the bundle: + +```bash +docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -it bootstrap_form /bin/bash +bundle install +``` + +You can run tests in the container as normal, with `rake test`. + +(Some of that command line is need for Linux hosts, to run the container as the current user.) + +### The Demo App + +There is a demo app in this repository. It shows some of the features of `bootstrap_form`, and provides a base on which to build ad-hoc testing, if you need it. + +To run the demo app, set up the database and run the server: + +```bash +cd demo +export BUNDLER_GEMFILE=../gemfiles/6.1.gemfile +rails db:setup +rails s -b 0.0.0.0 +``` + +To run the demo app in the Docker container: + +```bash +docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -p 3000:3000 -it bootstrap_form /bin/bash +cd demo +export BUNDLER_GEMFILE=../gemfiles/6.1.gemfile +rails db:setup +rails s -b 0.0.0.0 +``` + +To use other supported versions of Rails, change the `export BUNDLER_GEMFILE...` line to another gem file. + ## Documentation Contributions Contributions to documentation are always welcome. Even fixing one typo improves the quality of `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). diff --git a/Dangerfile b/Dangerfile index 121167be4..bd985496c 100644 --- a/Dangerfile +++ b/Dangerfile @@ -44,11 +44,9 @@ end # ------------------------------------------------------------------------------ # Did you remove the CHANGELOG's "Your contribution here!" line? # ------------------------------------------------------------------------------ -if has_changelog_changes - if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3 - raise( - "Please put the `- Your contribution here!` line back into CHANGELOG.md.", - sticky: false - ) - end +if has_changelog_changes && IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3 + raise( + "Please put the `- Your contribution here!` line back into CHANGELOG.md.", + sticky: false + ) end diff --git a/Dockerfile b/Dockerfile index 617ed8496..ba0915ec6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,26 @@ -# From: https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development -ARG RUBY_VERSION -# See explanation below -FROM ruby:$RUBY_VERSION-slim-buster +ARG DISTRO=buster +ARG RUBY_VERSION=2.6 -ARG NODE_MAJOR -ARG BUNDLER_VERSION -ARG YARN_VERSION +FROM ruby:$RUBY_VERSION-$DISTRO -# Common dependencies -RUN apt-get update -qq \ - && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ - build-essential \ - gnupg2 \ - curl \ - less \ - git \ - sqlite3 \ - libsqlite3-dev \ - && apt-get clean \ - && rm -rf /var/cache/apt/archives/* \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - && truncate -s 0 /var/log/*log - -# Add NodeJS to sources list -RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - - -# Add Yarn to the sources list -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ - && echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list - -# Application dependencies -RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \ - DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ - nodejs \ - yarn=$YARN_VERSION-1 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ - truncate -s 0 /var/log/*log - -# Configure bundler -ENV LANG=C.UTF-8 \ - BUNDLE_JOBS=4 \ - BUNDLE_RETRY=3 - -# Uncomment this line if you store Bundler settings in the project's root -# ENV BUNDLE_APP_CONFIG=.bundle - -# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec` -# ENV PATH /app/bin:$PATH - -# Upgrade RubyGems and install required Bundler version -RUN gem update --system && \ - gem install bundler:$BUNDLER_VERSION - -# Create a directory for the app code RUN mkdir -p /app - -WORKDIR /app \ No newline at end of file +ENV HOME /app +WORKDIR /app + +ENV GEM_HOME $HOME/vendor/bundle +ENV BUNDLE_APP_CONFIG="$GEM_HOME" +ENV PATH ./bin:$GEM_HOME/bin:$PATH +RUN (echo 'docker'; echo 'docker') | passwd root + +# Yarn installs nodejs. +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt update -y -q && \ + apt install -y -q yarn sqlite3 + +# Ruby now comes with bundler, but we're not using the default version yet, because we were using +# a newer version of bundler already. Ruby 3 comes with Bundler 2.2.3. Ruby 2.7 has Bundler 2.1.2, +# which is still behind what we were using. +RUN gem install bundler -v 2.1.4 + +EXPOSE 3000 diff --git a/Gemfile b/Gemfile index 625bb099f..793f35dfb 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec path: __dir__ # Uncomment and change rails version for testing purposes # gem "rails", "~> 5.2.0" # gem "rails", "~> 6.0.0" +# gem "rails", "~> 6.1.0" # gem "rails", git: "https://github.com/rails/rails.git" group :development do @@ -17,7 +18,6 @@ group :development do end group :test do - # can relax version requirement for Rails 5.2.beta3+ gem "diffy" gem "equivalent-xml" gem "mocha" diff --git a/README.md b/README.md index dec13828d..4faa0a781 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,9 @@ -If you are using Bootstrap v3, refer to the legacy [legacy-2.7](https://github.com/bootstrap-ruby/bootstrap_form/tree/legacy-2.7) branch. - -This is a new take on the `bootstrap_form` README. Please leave comments at: #520. You can go back to the traditional [README](/OLD-README.md). - ---- - # bootstrap_form -[](https://travis-ci.org/bootstrap-ruby/bootstrap_form) +[](https://github.com/bootstrap-ruby/bootstrap_form/actions/workflows/ruby.yml) [](https://rubygems.org/gems/bootstrap_form) -`bootstrap_form` is a Rails form builder that makes it super easy to integrate Bootstrap v4-style forms into your Rails application. It provides form helpers that augment the Rails form helpers. `bootstrap_forms`'s form helpers generate the form field and its label and all the Bootstrap mark-up required for proper Bootstrap display. `bootstrap_form` also provides: +`bootstrap_form` is a Rails form builder that makes it super easy to integrate Bootstrap v5-style forms into your Rails application. It provides form helpers that augment the Rails form helpers. `bootstrap_forms`'s form helpers generate the form field and its label and all the Bootstrap mark-up required for proper Bootstrap display. `bootstrap_form` also provides: * [Validation error messages](#validation-and-errors) below the field they correspond to, by default. You can also put the error messages after the label, or turn off `bootstrap_form`'s validation error handling and do it yourself. _Note that this applies to Rails-generated validation messages._ HTML 5 client-side validation and Rails validation out of the box don't really work well together. One discussion of the challenges and some solutions is [here](https://www.jorgemanrubia.com/2019/02/16/form-validations-with-html5-and-modern-rails/) * Automatic [mark-up for the `required` attribute](#required-fields) on required fields. @@ -33,14 +27,14 @@ Some other nice things that `bootstrap_form` does for you are: * Ruby 2.5+ * Rails 5.2+ -* Bootstrap 4.0+ +* Bootstrap 5.0+ ## Installation Add it to your Gemfile: ```ruby -gem "bootstrap_form", "~> 4.0" +gem "bootstrap_form", "~> 5.0" ``` Then: @@ -79,12 +73,12 @@ This generates the following HTML: ```html