Permalink
Browse files

fixed logic of css classes generation in ActiveAdmin::Views::TableFor

  • Loading branch information...
1 parent 6f66b0c commit 1f401fd76dcbea9681f70a3222633fe316bfea83 @Fivell Fivell committed Nov 4, 2012
Showing with 40 additions and 14 deletions.
  1. +13 −14 lib/active_admin/views/components/table_for.rb
  2. +27 −0 spec/unit/views/components/table_for_spec.rb
@@ -65,15 +65,14 @@ def build_table_header(col)
classes << 'sortable' if sort_key
classes << "sorted-#{current_sort[1]}" if sort_key && current_sort[0] == sort_key
- classes << col.data.to_s.downcase.underscore if col.data.is_a?(Symbol)
- classes << col.title.to_s.downcase.underscore if [Symbol, String].include?(col.title.class)
+ classes << col.html_class
if sort_key
th :class => classes do
- link_to(col.title, params.merge(:order => "#{sort_key}_#{order_for_sort_key(sort_key)}").except(:page))
+ link_to(col.pretty_title, params.merge(:order => "#{sort_key}_#{order_for_sort_key(sort_key)}").except(:page))
end
else
- th(col.title, :class => classes)
+ th(col.pretty_title, :class => classes)
end
end
@@ -85,7 +84,7 @@ def build_table_body
end
def build_table_cell(col, item)
- td(:class => (col.data.to_s.downcase if col.data.is_a?(Symbol))) do
+ td(:class => col.html_class) do
rvalue = call_method_or_proc_on(item, col.data, :exec => false)
if col.data.is_a?(Symbol)
rvalue = pretty_format(rvalue)
@@ -123,12 +122,13 @@ def default_options
class Column
- attr_accessor :title, :data
+ attr_accessor :title, :data , :html_class
def initialize(*args, &block)
@options = args.extract_options!
- @title = pretty_title args[0]
+ @title = args[0]
+ @html_class = @options.delete(:class) || @title.to_s.downcase.underscore.gsub(/ +/,'_')
@data = args[1] || args[0]
@data = block if block
@resource_class = args[2]
@@ -173,17 +173,16 @@ def sort_key
end
end
- private
-
- def pretty_title(raw)
- if raw.is_a?(Symbol)
+ def pretty_title
+ if @title.is_a?(Symbol)
+ default_title = @title.to_s.titleize
if @options[:i18n] && @options[:i18n].respond_to?(:human_attribute_name)
- raw = @options[:i18n].human_attribute_name(raw, :default => raw.to_s.titleize)
+ @title = @options[:i18n].human_attribute_name(@title, :default => default_title)
else
- raw.to_s.titleize
+ default_title
end
else
- raw
+ @title
end
end
end
@@ -110,6 +110,33 @@
end
end
end
+
+
+ context "when creating many columns with symbols, blocks and strings" do
+ let(:table) do
+ render_arbre_component assigns, helpers do
+ table_for(collection) do
+ column "My Custom Title", :title
+ column :created_at , :class=>"datetime"
+ end
+ end
+ end
+
+
+ it "should add a class to each table header based on class option or the col name" do
+ table.find_by_tag("th").first.class_list.should include("my_custom_title")
+ table.find_by_tag("th").lasr.class_list.should include("datetime")
+ end
+
+ it "should add a class to each cell based on class option or the col name" do
+ table.find_by_tag("td").first.class_list.should include("my_custom_title")
+ table.find_by_tag("td").lasr.class_list.should include("datetime")
+ end
+
+
+ end
+
+
end
describe "column sorting" do

0 comments on commit 1f401fd

Please sign in to comment.