Skip to content

Commit

Permalink
Implemented Arbre::HTML::Tag#default_id_for_prefix
Browse files Browse the repository at this point in the history
This method can be overriden in subclasses of Tag to add a prefix to the
auto generated id when an object is passed in using :for
  • Loading branch information
gregbell committed Jun 13, 2012
1 parent df9b605 commit a841a19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/arbre/html/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def dom_id_for(record)
record.object_id
end

[dom_class_name_for(record), id].join("_")
[default_id_for_prefix, dom_class_name_for(record), id].compact.join("_")
end

def default_id_for_prefix
Expand Down
16 changes: 16 additions & 0 deletions spec/arbre/unit/html/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
it "should add a class name" do
tag.class_list.should include("resource_class")
end

describe "with a default_id_for_prefix" do

let(:tag) do
Class.new(Arbre::HTML::Tag) do
def default_id_for_prefix
"a_prefix"
end
end.new
end

it "should set the id to the type and id" do
tag.id.should == "a_prefix_resource_class_5"
end

end
end

describe "css class names" do
Expand Down

0 comments on commit a841a19

Please sign in to comment.