Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added numeric ability for text nodes. #470

Closed
wants to merge 1 commit into from

3 participants

@bobbytables

I discovered that table_for (and any tag really) created with Arbre with the content of a numeric value would just not display anything. For example:

table_for(article) do
  column("Article Comments") { |a| a.comments_count }
end

The column for comments will be blank because "comments_count" is a number.
The code in builder.rb prevents this on this line:

if tag.is_a?(String)
  current_dom_context << Arbre::HTML::TextNode.from_string(tag)
end

I added spec but wasn't sure if it was to par, sorry if isn't.

@ebeigarts

This has been already reported in #154 and it also accepts any object that has to_s method.

@gregbell gregbell was assigned
@gregbell gregbell referenced this pull request from a commit
@gregbell gregbell Add any object that repsonds to to_s to the DOM in Arbre blocks.
Before this commit:

  index do
    column("My Column"){ 1 }
  end

Would result in an empty column. Now the object is appended to the DOM
and will result in a colum of "1"s.

The return value is ignored if the user has already appended other
elements to the DOM. This might trip up some users, however it is more
likely that you are either going to build up a DOM structure or return a
simple value, not both.

Thanks for the pull requests from @bobbytables and @utkarshkukreti

References isses #470, 154
9cb2b90
@gregbell
Owner

Fixed on master in 9cb2b90

@gregbell gregbell closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 12, 2011
  1. @bobbytables
This page is out of date. Refresh to see the latest.
View
4 lib/active_admin/arbre/builder.rb
@@ -102,7 +102,9 @@ def with_current_dom_context(tag)
def insert_text_node_if_string(tag)
if tag.is_a?(String)
current_dom_context << Arbre::HTML::TextNode.from_string(tag)
- end
+ elsif tag.kind_of?(Numeric)
+ current_dom_context << Arbre::HTML::TextNode.from_string(tag.to_s)
+ end
end
end
View
8 spec/unit/arbre/html/tag_spec.rb
@@ -16,8 +16,14 @@
it "should set the hash of options to the attributes" do
tag.attributes.should == { :id => "my_id" }
end
+
+ it "should set contents to a string if passed a numeric value" do
+ numeric_tag = Arbre::HTML:Tag.new
+ numeric_tag.build 42, :id => "answer_to_life"
+ numeric_tag.content.should == 42.to_s
+ end
end
-
+
describe "creating a tag 'for' an object" do
let(:model_name){ mock(:singular => "resource_class")}
let(:resource_class){ mock(:model_name => model_name) }
Something went wrong with that request. Please try again.