From f815ee9af718a2328cbee9220dcde4907c952ff1 Mon Sep 17 00:00:00 2001 From: Thomas Sevestre Date: Fri, 26 Aug 2016 13:56:15 +0200 Subject: [PATCH 1/3] add custom_control --- lib/bootstrap_form/helpers/bootstrap.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 45578d67b..1bf25d2b9 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -59,6 +59,15 @@ def static_control(*args, &block) end end + def custom_control(*args, &block) + options = args.extract_options! + name = args.first + + form_group_builder(name, options) do + capture(&block) + end + end + def prepend_and_append_input(options, &block) options = options.extract!(:prepend, :append, :input_group_class) input_group_class = ["input-group", options[:input_group_class]].compact.join(' ') From cf683ceb17002bdb57528be9bffeca2b787968b3 Mon Sep 17 00:00:00 2001 From: Thomas Sevestre Date: Thu, 12 Jan 2017 11:02:44 +0100 Subject: [PATCH 2/3] simplify custom_control implementation --- lib/bootstrap_form/helpers/bootstrap.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 1bf25d2b9..540d632b2 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -63,9 +63,7 @@ def custom_control(*args, &block) options = args.extract_options! name = args.first - form_group_builder(name, options) do - capture(&block) - end + form_group_builder(name, options, &block) end def prepend_and_append_input(options, &block) From c726429c6298160ba1886a9ed980371d3af40108 Mon Sep 17 00:00:00 2001 From: Thomas Sevestre Date: Thu, 12 Jan 2017 11:27:11 +0100 Subject: [PATCH 3/3] make danger happy --- CHANGELOG.md | 1 + test/bootstrap_other_components_test.rb | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c0ae03d8..d2c220502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Bugfixes: Features: - Your contribution here! + - Add a FormBuilder#custom_control helper [#289](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/289) ## [2.5.0][] (2016-08-12) diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index b86fb9d63..7a994c5e9 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -32,6 +32,33 @@ def setup assert_equal expected, output end + test "custom control does't wrap given block in a p tag" do + output = @horizontal_builder.custom_control :email do + "this is a test" + end + + expected = %{
this is a test
} + assert_equal expected, output + end + + test "custom control doesn't require an actual attribute" do + output = @horizontal_builder.custom_control nil, label: "My Label" do + "this is a test" + end + + expected = %{
this is a test
} + assert_equal expected, output + end + + test "custom control doesn't require a name" do + output = @horizontal_builder.custom_control label: "Custom Label" do + "Custom Control" + end + + expected = %{
Custom Control
} + assert_equal expected, output + end + test "submit button defaults to rails action name" do expected = %{} assert_equal expected, @builder.submit