Skip to content

Commit

Permalink
Get rid of heredoc on bootstrap-5 branch (#591)
Browse files Browse the repository at this point in the history
* Ignore RubyMine config directory

* Initial setup of GitHb Actions

* Run tests for rails 5 and rails 6

* Run tests for rails 5 and rails 6 + run lint job

* GH Actions: Correct gemfile names

* GH Actions: Only run the test task in the matrix.  rubocop is run in the separate Lint job.

* GH Actions: Separate the Danger run for better output

* GH Actions: Run rubocop directly instead of as a Rake task.  Allow autocorrectable offences.

* GH Actions: Only run Danger for pull requests

* GH Actions: Try to calm RuboCop

* Use the default Gemfile to pick up rubocop.yml

* GH Actions: Ignore the vendor directory for rubocop

* Forward the options as keyword arguments

* Test Rails 6.1 and skip Rails 5.2 + Ruby 3.0

* Fix Rails 6.1 tests on master (#586)

* Fix tests for Rails 6.1

* Fix Rubocop offenses

bootstrap_form.gemspec:27:29: C: Gemspec/RequiredRubyVersion: required_ruby_version (2.5, declared in bootstrap_form.gemspec) and TargetRubyVersion (2.7, which may be specified in .rubocop.yml) should be equal.
  s.required_ruby_version = ">= 2.5"
                            ^^^^^^^^
lib/bootstrap_form/form_group.rb:14:30: C: [Correctable] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line. (https://rubystyle.guide#no-double-indent)
                             :input_group_class, :label_col, :control_col,
                             ^^^^^^^^^^^^^^^^^^
lib/bootstrap_form/form_group.rb:15:30: C: [Correctable] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line. (https://rubystyle.guide#no-double-indent)
                             :add_control_col_class, :layout, :prepend)) do
                             ^^^^^^^^^^^^^^^^^^^^^^
test/bootstrap_form_test.rb:123:103: C: [Correctable] Style/IfUnlessModifier: Modifier form of if makes the line too long. (https://rubystyle.guide#if-as-a-modifier)
        <form accept-charset="UTF-8" action="/users" method="post" role="form" #{'data-remote="true"' if ::Rails::VERSION::STRING < "6.1"}>
                                                                                                      ^^
test/bootstrap_form_test.rb:123:133: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
        <form accept-charset="UTF-8" action="/users" method="post" role="form" #{'data-remote="true"' if ::Rails::VERSION::STRING < "6.1"}>
                                                                                                                                    ^^^^^
test/bootstrap_rich_text_area_test.rb:23:54: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
      "http://test.host/rails/active_storage/blobs/#{"redirect/" if ::Rails::VERSION::STRING >= "6.1"}:signed_id/:filename"
                                                     ^^^^^^^^^^^
test/bootstrap_rich_text_area_test.rb:23:97: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
      "http://test.host/rails/active_storage/blobs/#{"redirect/" if ::Rails::VERSION::STRING >= "6.1"}:signed_id/:filename"
                                                                                                ^^^^^

* Include Rails 6.1 in Travis tests + update Ruby versions

* Update CHANGELOG

* Rails Edge requires Ruby 2.7+

* Remove rubocop_todo and fix Rubocop offenses

* Replace strip_heredoc with <<~ (#587)

* Replace strip_heredoc with <<~

Also fix newly detected Rubocop offenses on indentation

* Update CHANGELOG

* Simplify Dockerfile and add documentation (#588)

* Simplify Dockerfile and add documentation

* A few more additions to .gitignore

* Ignore gems placed when using Dockerfile (#590)

* Fix formatting and heredoc

* Fix bad merge

Co-authored-by: Uwe Kubosch <uwe@kubosch.no>
Co-authored-by: Uwe Kubosch <donv@users.noreply.github.com>
Co-authored-by: Thimo Jansen <thimo@defrog.nl>
  • Loading branch information
4 people committed Apr 16, 2021
1 parent b0e53cd commit 46d9b5b
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 482 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Ruby

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

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
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
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.bundle/
.idea
log/*.log
pkg/
demo/db/*.sqlite3
Expand All @@ -13,7 +14,7 @@ test/gemfiles/*.lock
Vagrantfile
.vagrant

// For the demo app.
# For the demo app.

# Ignore uploaded files in development.
demo/storage/*
Expand All @@ -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
27 changes: 14 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -45,12 +52,6 @@ Metrics/ClassLength:
- "demo/test/**/*"
- "test/**/*"

Metrics/LineLength:
Max: 132
Exclude:
- "demo/config/**/*"
- "demo/db/**/*"

Metrics/MethodLength:
Max: 12
Exclude:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

### Bugfixes

* Your contribution here!
* [#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)

Expand Down
29 changes: 28 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -82,6 +82,33 @@ 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 whichever container you built with the shell to 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.)

## 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).
Expand Down
79 changes: 23 additions & 56 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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

# 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
2 changes: 1 addition & 1 deletion lib/bootstrap_form/helpers/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def submit(name=nil, options={})
def primary(name=nil, options={}, &block)
setup_css_class "btn btn-primary", options

if options[:render_as_button] || block_given?
if options[:render_as_button] || block
options.except! :render_as_button
button(name, options, &block)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/inputs/check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def check_box_label(name, options, checked_value, &block)
end

def check_box_description(name, options, &block)
content = block_given? ? capture(&block) : options[:label]
content = block ? capture(&block) : options[:label]
content || object&.class&.human_attribute_name(name) || name.to_s.humanize
end

Expand Down
Loading

0 comments on commit 46d9b5b

Please sign in to comment.