bootstrap_form 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Dangerfile CHANGED
@@ -22,7 +22,7 @@ if has_lib_changes && !has_test_changes
22
22
  warn("There are code changes, but no corresponding tests. "\
23
23
  "Please include tests if this PR introduces any modifications in "\
24
24
  "#{project_name}'s behavior.",
25
- :sticky => false)
25
+ sticky: false)
26
26
  end
27
27
 
28
28
  # ------------------------------------------------------------------------------
@@ -35,10 +35,10 @@ Here's an example of a CHANGELOG.md entry (place it immediately under the `* You
35
35
  ```markdown
36
36
  * [##{pr_number}](#{pr_url}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
37
37
  ```
38
- MARKDOWN
38
+ MARKDOWN
39
39
  warn("Please update CHANGELOG.md with a description of your changes. "\
40
40
  "If this PR is not a user-facing change (e.g. just refactoring), "\
41
- "you can disregard this.", :sticky => false)
41
+ "you can disregard this.", sticky: false)
42
42
  end
43
43
 
44
44
  # ------------------------------------------------------------------------------
@@ -46,9 +46,9 @@ end
46
46
  # ------------------------------------------------------------------------------
47
47
  if has_changelog_changes
48
48
  if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3
49
- fail(
49
+ raise(
50
50
  "Please put the `- Your contribution here!` line back into CHANGELOG.md.",
51
- :sticky => false
51
+ sticky: false
52
52
  )
53
53
  end
54
54
  end
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gemspec
8
8
  group :development do
9
9
  gem "chandler", ">= 0.7.0"
10
10
  gem "htmlbeautifier"
11
+ gem "rubocop", require: false
11
12
  end
12
13
 
13
14
  group :test do
data/README.md CHANGED
@@ -21,7 +21,7 @@ Bootstrap v4-style forms into your Rails application.
21
21
  Add it to your Gemfile:
22
22
 
23
23
  ```ruby
24
- gem "bootstrap_form", ">= 4.0.0"
24
+ gem "bootstrap_form", ">= 4.1.0"
25
25
  ```
26
26
 
27
27
  Then:
@@ -213,10 +213,11 @@ validator with the associated model attribute. Presently this is one of:
213
213
  ActiveRecord::Validations::PresenceValidator or
214
214
  ActiveModel::Validations::PresenceValidator.
215
215
 
216
- In cases where this behavior is undesirable, use the `skip_required` option:
216
+ In cases where this behavior is undesirable, use the `required` option to force the class to be present or absent:
217
217
 
218
218
  ```erb
219
- <%= f.password_field :password, label: "New Password", skip_required: true %>
219
+ <%= f.password_field :login, label: "New Username", required: true %>
220
+ <%= f.password_field :password, label: "New Password", required: false %>
220
221
  ```
221
222
 
222
223
  ### Input Elements / Controls
@@ -302,12 +303,24 @@ Which produces the following output:
302
303
 
303
304
  You still can use `wrapper_class` option to set only a css class. This is just a short form of `wrapper: { class: 'additional-class' }`.
304
305
 
306
+ ### Suppressing the Form Group Altogether
307
+
308
+ You may have want to define your own form group div around a field. To do so, add the option `wrapper: false` to the input field. For example:
309
+
310
+ ```
311
+ f.form_group :user do
312
+ f.email_field :email, wrapper: false
313
+ end
314
+ ```
315
+
316
+ Note that Bootstrap relies on the form group div to correctly format most fields, so if you use the `wrapper: false` option, you should provide your own form group div around the input field. You can write your own HTML, or use the `form_group` helper.
317
+
305
318
  ### Selects
306
319
 
307
320
  Our select helper accepts the same arguments as the [default Rails helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select). Here's an example of how you pass both options and html_options hashes:
308
321
 
309
322
  ```erb
310
- <%= f.select :product, [["Apple", 1], ["Grape", 2]], { label: "Choose your favorite fruit:" }, { class: "selectpicker", wrapper: { class: 'has-warning', data: { foo: 'bar' } } } %>
323
+ <%= f.select :product, [["Apple", 1], ["Grape", 2]], { label: "Choose your favorite fruit:", wrapper: { class: 'has-warning', data: { foo: 'bar' } } }, { class: "selectpicker" } %>
311
324
  ```
312
325
 
313
326
  ### Checkboxes and Radios
@@ -353,6 +366,13 @@ Check boxes and radio buttons are wrapped in a `div.form-check`. You can add cla
353
366
  ```erb
354
367
  <%= f.radio_button :skill_level, 0, label: "Novice", inline: true, wrapper_class: "w-auto" %>
355
368
  ```
369
+ #### Switches
370
+
371
+ To render checkboxes as switches with Bootstrap 4.2+, add the proper wrapper class:
372
+
373
+ ```erb
374
+ <%= f.check_box :remember_me, custom: true, wrapper_class: 'custom-switch' %>
375
+ ```
356
376
 
357
377
  #### Collections
358
378
 
@@ -539,6 +559,34 @@ The `label_col` and `control_col` css classes can also be changed per control:
539
559
  <% end %>
540
560
  ```
541
561
 
562
+ or default value can be changed in initializer:
563
+
564
+ ```erb
565
+ # config/initializers/bootstrap_form.rb
566
+ module BootstrapForm
567
+ class FormBuilder
568
+ def default_label_col
569
+ 'col-sm-4'
570
+ end
571
+ def default_control_col
572
+ 'col-sm-8'
573
+ end
574
+ end
575
+ end
576
+ ```
577
+
578
+ Control col wrapper class can be modified with `add_control_col_class`. This option will preserve column definition:
579
+
580
+ ```erb
581
+ <%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
582
+ <%= f.email_field :email %>
583
+ <%= f.text_field :age, add_control_col_class: "additional-control-col-class" %>
584
+ <%= f.form_group do %>
585
+ <%= f.submit %>
586
+ <% end %>
587
+ <% end %>
588
+ ```
589
+
542
590
  ### Custom Field Layout
543
591
 
544
592
  The form-level `layout` can be overridden per field, unless the form-level layout was `inline`:
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  begin
2
2
  require 'bundler/setup'
3
+ require 'rubocop/rake_task'
3
4
  rescue LoadError
4
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
6
  end
@@ -30,4 +31,9 @@ task "release:rubygem_push" do
30
31
  Rake.application.invoke_task("chandler:push")
31
32
  end
32
33
 
33
- task default: :test
34
+ desc 'Run RuboCop checks -- see .rubocop_todo.yml for outstanding offenses'
35
+ RuboCop::RakeTask.new(:rubocop) do |task|
36
+ task.options = %w[--config .rubocop_todo.yml]
37
+ end
38
+
39
+ task default: %i[test rubocop]
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require "bootstrap_form/version"
@@ -1,9 +1,8 @@
1
1
  class BootstrapController < ApplicationController
2
-
3
2
  def form
4
3
  @collection = [
5
- Address.new(id: 1, street: 'Foo'),
6
- Address.new(id: 2, street: 'Bar')
4
+ Address.new(id: 1, street: "Foo"),
5
+ Address.new(id: 2, street: "Bar")
7
6
  ]
8
7
 
9
8
  @user = User.new
@@ -12,5 +11,4 @@ class BootstrapController < ApplicationController
12
11
  @user_with_error.errors.add(:email)
13
12
  @user_with_error.errors.add(:misc)
14
13
  end
15
-
16
14
  end
@@ -1,5 +1,4 @@
1
1
  module BootstrapHelper
2
-
3
2
  def form_with_source(&block)
4
3
  form_html = capture(&block)
5
4
 
@@ -19,5 +18,4 @@ module BootstrapHelper
19
18
  concat(codemirror)
20
19
  end
21
20
  end
22
-
23
21
  end
@@ -1,3 +1,3 @@
1
- class Address < ActiveRecord::Base
1
+ class Address < ApplicationRecord
2
2
  belongs_to :user
3
3
  end
@@ -1,7 +1,7 @@
1
1
  class FauxUser
2
2
  attr_accessor :email, :password, :comments, :misc
3
3
 
4
- def initialize(attributes = {})
4
+ def initialize(attributes={})
5
5
  attributes.each do |name, value|
6
6
  send("#{name}=", value)
7
7
  end
@@ -1,7 +1,7 @@
1
- class User < ActiveRecord::Base
1
+ class User < ApplicationRecord
2
2
  serialize :preferences
3
3
 
4
- validates :email, presence: true, :length => { minimum: 5 }
4
+ validates :email, presence: true, length: { minimum: 5 }
5
5
  validates :terms, acceptance: { accept: true }
6
6
 
7
7
  has_one :address
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
- load Gem.bin_path('bundler', 'bundle')
2
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
3
+ load Gem.bin_path("bundler", "bundle")
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../config/application', __dir__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
2
+ require_relative "../config/boot"
3
+ require "rake"
4
4
  Rake.application.run
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'fileutils'
2
+ require "fileutils"
3
3
  include FileUtils
4
4
 
5
5
  # path to your application root.
6
- APP_ROOT = File.expand_path('..', __dir__)
6
+ APP_ROOT = File.expand_path("..", __dir__)
7
7
 
8
8
  def system!(*args)
9
9
  system(*args) || abort("\n== Command #{args} failed ==")
@@ -13,9 +13,9 @@ chdir APP_ROOT do
13
13
  # This script is a starting point to setup your application.
14
14
  # Add necessary setup steps to this file.
15
15
 
16
- puts '== Installing dependencies =='
17
- system! 'gem install bundler --conservative'
18
- system('bundle check') || system!('bundle install')
16
+ puts "== Installing dependencies =="
17
+ system! "gem install bundler --conservative"
18
+ system("bundle check") || system!("bundle install")
19
19
 
20
20
  # Install JavaScript dependencies if using Yarn
21
21
  # system('bin/yarn')
@@ -26,11 +26,11 @@ chdir APP_ROOT do
26
26
  # end
27
27
 
28
28
  puts "\n== Preparing database =="
29
- system! 'bin/rails db:setup'
29
+ system! "bin/rails db:setup"
30
30
 
31
31
  puts "\n== Removing old logs and tempfiles =="
32
- system! 'bin/rails log:clear tmp:clear'
32
+ system! "bin/rails log:clear tmp:clear"
33
33
 
34
34
  puts "\n== Restarting application server =="
35
- system! 'bin/rails restart'
35
+ system! "bin/rails restart"
36
36
  end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'fileutils'
2
+ require "fileutils"
3
3
  include FileUtils
4
4
 
5
5
  # path to your application root.
6
- APP_ROOT = File.expand_path('..', __dir__)
6
+ APP_ROOT = File.expand_path("..", __dir__)
7
7
 
8
8
  def system!(*args)
9
9
  system(*args) || abort("\n== Command #{args} failed ==")
@@ -13,19 +13,19 @@ chdir APP_ROOT do
13
13
  # This script is a way to update your development environment automatically.
14
14
  # Add necessary update steps to this file.
15
15
 
16
- puts '== Installing dependencies =='
17
- system! 'gem install bundler --conservative'
18
- system('bundle check') || system!('bundle install')
16
+ puts "== Installing dependencies =="
17
+ system! "gem install bundler --conservative"
18
+ system("bundle check") || system!("bundle install")
19
19
 
20
20
  # Install JavaScript dependencies if using Yarn
21
21
  # system('bin/yarn')
22
22
 
23
23
  puts "\n== Updating database =="
24
- system! 'bin/rails db:migrate'
24
+ system! "bin/rails db:migrate"
25
25
 
26
26
  puts "\n== Removing old logs and tempfiles =="
27
- system! 'bin/rails log:clear tmp:clear'
27
+ system! "bin/rails log:clear tmp:clear"
28
28
 
29
29
  puts "\n== Restarting application server =="
30
- system! 'bin/rails restart'
30
+ system! "bin/rails restart"
31
31
  end
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path('..', __dir__)
2
+ APP_ROOT = File.expand_path("..", __dir__)
3
3
  Dir.chdir(APP_ROOT) do
4
4
  begin
5
5
  exec "yarnpkg #{ARGV.join(' ')}"
6
6
  rescue Errno::ENOENT
7
- $stderr.puts "Yarn executable was not detected in the system."
8
- $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
7
+ warn "Yarn executable was not detected in the system."
8
+ warn "Download Yarn at https://yarnpkg.com/en/docs/install"
9
9
  exit 1
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require_relative 'config/environment'
3
+ require_relative "config/environment"
4
4
 
5
5
  run Rails.application
@@ -1,6 +1,6 @@
1
- require_relative 'boot'
1
+ require_relative "boot"
2
2
 
3
- require 'rails/all'
3
+ require "rails/all"
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
6
  require "bootstrap_form"
@@ -13,9 +13,7 @@ module Dummy
13
13
  config.load_defaults [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join(".")
14
14
  end
15
15
 
16
- if config.respond_to?(:secret_key_base)
17
- config.secret_key_base = "ignore"
18
- end
16
+ config.secret_key_base = "ignore" if config.respond_to?(:secret_key_base)
19
17
 
20
18
  # Settings in config/environments/* take precedence over those specified here.
21
19
  # Application configuration should go into files in config/initializers
@@ -14,12 +14,12 @@ Rails.application.configure do
14
14
 
15
15
  # Enable/disable caching. By default caching is disabled.
16
16
  # Run rails dev:cache to toggle caching.
17
- if Rails.root.join('tmp/caching-dev.txt').exist?
17
+ if Rails.root.join("tmp/caching-dev.txt").exist?
18
18
  config.action_controller.perform_caching = true
19
19
 
20
20
  config.cache_store = :memory_store
21
21
  config.public_file_server.headers = {
22
- 'Cache-Control' => "public, max-age=#{2.days.to_i}"
22
+ "Cache-Control" => "public, max-age=#{2.days.to_i}"
23
23
  }
24
24
  else
25
25
  config.action_controller.perform_caching = false
@@ -28,9 +28,7 @@ Rails.application.configure do
28
28
  end
29
29
 
30
30
  # Store uploaded files on the local file system (see config/storage.yml for options)
31
- if config.respond_to?(:active_storage)
32
- config.active_storage.service = :local
33
- end
31
+ config.active_storage.service = :local if config.respond_to?(:active_storage)
34
32
 
35
33
  # Don't care if the mailer can't send.
36
34
  config.action_mailer.raise_delivery_errors = false
@@ -15,7 +15,7 @@ Rails.application.configure do
15
15
  # Configure public file server for tests with Cache-Control for performance.
16
16
  config.public_file_server.enabled = true
17
17
  config.public_file_server.headers = {
18
- 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
18
+ "Cache-Control" => "public, max-age=#{1.hour.to_i}"
19
19
  }
20
20
 
21
21
  # Show full error reports and disable caching.
@@ -29,9 +29,7 @@ Rails.application.configure do
29
29
  config.action_controller.allow_forgery_protection = false
30
30
 
31
31
  # Store uploaded files on the local file system in a temporary directory
32
- if config.respond_to?(:active_storage)
33
- config.active_storage.service = :test
34
- end
32
+ config.active_storage.service = :test if config.respond_to?(:active_storage)
35
33
 
36
34
  config.action_mailer.perform_caching = false
37
35
 
@@ -1,12 +1,12 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
4
+ Rails.application.config.assets.version = "1.0"
5
5
 
6
6
  # Add additional assets to the asset load path.
7
7
  # Rails.application.config.assets.paths << Emoji.images_path
8
8
  # Add Yarn node_modules folder to the asset load path.
9
- Rails.application.config.assets.paths << Rails.root.join('node_modules')
9
+ Rails.application.config.assets.paths << Rails.root.join("node_modules")
10
10
 
11
11
  # Precompile additional assets.
12
12
  # application.js, application.css, and all non-JS/CSS in the app/assets
@@ -1,5 +1,5 @@
1
- require 'bootstrap_form/form_builder'
2
- require 'bootstrap_form/helper'
1
+ require "bootstrap_form/form_builder"
2
+ require "bootstrap_form/helper"
3
3
 
4
4
  module BootstrapForm
5
5
  module Rails
@@ -13,7 +13,8 @@ module BootstrapForm
13
13
 
14
14
  # Strip out punctuation on predicates, bang or writer methods since
15
15
  # e.g. target?_without_feature is not a valid method name.
16
- aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
16
+ aliased_target = target.to_s.sub(/([?!=])$/, "")
17
+ punctuation = Regexp.last_match(1)
17
18
  yield(aliased_target, punctuation) if block_given?
18
19
 
19
20
  with_method = "#{aliased_target}_with_#{feature}#{punctuation}"
@@ -22,12 +23,11 @@ module BootstrapForm
22
23
  alias_method without_method, target
23
24
  alias_method target, with_method
24
25
 
25
- case
26
- when public_method_defined?(without_method)
26
+ if public_method_defined?(without_method)
27
27
  public target
28
- when protected_method_defined?(without_method)
28
+ elsif protected_method_defined?(without_method)
29
29
  protected target
30
- when private_method_defined?(without_method)
30
+ elsif private_method_defined?(without_method)
31
31
  private target
32
32
  end
33
33
  end