Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag option for sets the attribute when value is a string or symbol #49

Merged
merged 1 commit into from
Feb 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## unreleased [☰](https://github.com/activeadmin/arbre/compare/v1.0.3...master)

* Tag option `for` sets the attribute when value is a string or symbol [#18]

## 1.0.3 [☰](https://github.com/activeadmin/arbre/compare/v1.0.2...v1.0.3)

* Performance improvements [#40][] by [@alexesDev][]
Expand Down
5 changes: 4 additions & 1 deletion lib/arbre/html/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def build(*args)
attributes = extract_arguments(args)
self.content = args.first if args.first

set_for_attribute(attributes.delete(:for))
for_value = attributes[:for]
unless for_value.is_a?(String) || for_value.is_a?(Symbol)
set_for_attribute(attributes.delete(:for))
end

attributes.each do |key, value|
set_attribute(key, value)
Expand Down
12 changes: 12 additions & 0 deletions spec/arbre/unit/html/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def default_id_for_prefix
end
end

describe "creating a tag with a for attribute" do
it "sets the `for` attribute when a string is given" do
tag.build for: "email"
expect(tag.attributes[:for]).to eq "email"
end

it "sets the `for` attribute when a symbol is given" do
tag.build for: :email
expect(tag.attributes[:for]).to eq :email
end
end

describe "css class names" do

it "should add a class" do
Expand Down