Skip to content

Commit

Permalink
Merge pull request #2632 from floriank/feature/formbuilder-label
Browse files Browse the repository at this point in the history
Add a dedicated label method to the form builder
  • Loading branch information
ulferts committed Feb 27, 2015
2 parents 0c87251 + d46b8a0 commit 5f17041
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tabular_form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def #{selector}(field, options = {}, *args)
class_eval src, __FILE__, __LINE__
end

def label(method, text = nil, options = {}, &block)
options[:class] = Array(options[:class]) + %w(form--label)
super
end

def select(field, choices, options = {}, html_options = {})
html_options[:class] = Array(html_options[:class]) + %w(form--select)

Expand Down
16 changes: 16 additions & 0 deletions spec/lib/tabular_form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,20 @@
expect(output).to eq %{<button name="button" type="submit">Create User</button>}
end
end

describe '#label' do
subject(:output) { builder.label :name }

it 'should output element' do
expect(output).to eq %{<label class="form--label" for="user_name">Name</label>}
end

describe 'with existing attributes' do
subject(:output) { builder.label :name, 'Fear', class: 'sharknado' }

it 'should keep associated classes' do
expect(output).to eq %{<label class="sharknado form--label" for="user_name">Fear</label>}
end
end
end
end

0 comments on commit 5f17041

Please sign in to comment.