Skip to content

Commit

Permalink
add custom_control (#289)
Browse files Browse the repository at this point in the history
* add custom_control

* simplify custom_control implementation

* make danger happy
  • Loading branch information
ThomasSevestre authored and mattbrictson committed Jan 14, 2017
1 parent bb7aa59 commit dccdb60
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3][] (2016-12-23)

Expand Down
7 changes: 7 additions & 0 deletions lib/bootstrap_form/helpers/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def static_control(*args, &block)
end
end

def custom_control(*args, &block)
options = args.extract_options!
name = args.first

form_group_builder(name, options, &block)
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(' ')
Expand Down
27 changes: 27 additions & 0 deletions test/bootstrap_other_components_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ def setup
assert_equivalent_xml 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 = %{<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>}
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 = %{<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>}
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 = %{<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>}
assert_equal expected, output
end

test "submit button defaults to rails action name" do
expected = %{<input class="btn btn-default" name="commit" type="submit" value="Create User" />}
assert_equivalent_xml expected, @builder.submit
Expand Down

0 comments on commit dccdb60

Please sign in to comment.