Skip to content

Commit dccdb60

Browse files
ThomasSevestremattbrictson
authored andcommitted
add custom_control (#289)
* add custom_control * simplify custom_control implementation * make danger happy
1 parent bb7aa59 commit dccdb60

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bugfixes:
55

66
Features:
77
- Your contribution here!
8+
- Add a FormBuilder#custom_control helper [#289](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/289)
89

910
## [2.5.3][] (2016-12-23)
1011

lib/bootstrap_form/helpers/bootstrap.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def static_control(*args, &block)
5959
end
6060
end
6161

62+
def custom_control(*args, &block)
63+
options = args.extract_options!
64+
name = args.first
65+
66+
form_group_builder(name, options, &block)
67+
end
68+
6269
def prepend_and_append_input(options, &block)
6370
options = options.extract!(:prepend, :append, :input_group_class)
6471
input_group_class = ["input-group", options[:input_group_class]].compact.join(' ')

test/bootstrap_other_components_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@ def setup
3232
assert_equivalent_xml expected, output
3333
end
3434

35+
test "custom control does't wrap given block in a p tag" do
36+
output = @horizontal_builder.custom_control :email do
37+
"this is a test"
38+
end
39+
40+
expected = %{<div class="form-group"><label class="control-label col-sm-2 required" for="user_email">Email</label><div class="col-sm-10">this is a test</div></div>}
41+
assert_equal expected, output
42+
end
43+
44+
test "custom control doesn't require an actual attribute" do
45+
output = @horizontal_builder.custom_control nil, label: "My Label" do
46+
"this is a test"
47+
end
48+
49+
expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_">My Label</label><div class="col-sm-10">this is a test</div></div>}
50+
assert_equal expected, output
51+
end
52+
53+
test "custom control doesn't require a name" do
54+
output = @horizontal_builder.custom_control label: "Custom Label" do
55+
"Custom Control"
56+
end
57+
58+
expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_">Custom Label</label><div class="col-sm-10">Custom Control</div></div>}
59+
assert_equal expected, output
60+
end
61+
3562
test "submit button defaults to rails action name" do
3663
expected = %{<input class="btn btn-default" name="commit" type="submit" value="Create User" />}
3764
assert_equivalent_xml expected, @builder.submit

0 commit comments

Comments
 (0)