[eXPlainPMT Developers] [SVN commit] [214] Reverted last commit (changes to CollectionTableHelper).

svn at explainpmt.com svn at explainpmt.com
Mon Mar 27 11:21:41 EST 2006


Revision: 214
Author:   jwilger
Date:     2006-03-27 16:21:40 +0000 (Mon, 27 Mar 2006)

Log Message:
-----------
Reverted last commit (changes to CollectionTableHelper). That module is going to go away, because it's just a big, fat code-smell. It's making it really hard to set up the dnd priority sorting, because it falls apart when you try to do anything more complex than a simple table.

Modified Paths:
--------------
    trunk/app/helpers/collection_table_helper.rb
    trunk/test/unit/collection_table_helper_test.rb
Modified: trunk/app/helpers/collection_table_helper.rb
===================================================================
--- trunk/app/helpers/collection_table_helper.rb	2006-03-27 16:04:35 UTC (rev 213)
+++ trunk/app/helpers/collection_table_helper.rb	2006-03-27 16:21:40 UTC (rev 214)
@@ -47,34 +47,30 @@
   # build_table might return the following HTML:
   #
   #   <table class="collection_table">
-  #     <thead>
-  #       <tr>
-  #         <th>ID</th>
-  #         <th>Last Name</th>
-  #         <th>First Name</th>
-  #         <th>Email</th>
-  #         <th></th>
-  #         <th></th>
-  #       </tr>
-  #     </thead>
-  #     <tbody>
-  #       <tr class="odd_row">
-  #         <td align="right">2</td>
-  #         <td>Doe</td>
-  #         <td>Jane</td>
-  #         <td><a href="mailto:janedoe at example.com">janedoe at example.com</a></td>
-  #         <td><a href="/people/edit/2">Edit</a></td>
-  #         <td><a href="/people/delete/2">Delete</a></td>
-  #       </tr>
-  #       <tr class="even_row">
-  #         <td align="right">3</td>
-  #         <td>Body</td>
-  #         <td>Some</td>
-  #         <td><a href="mailto:somebody at example.com">somebody at example.com</a></td>
-  #         <td><a href="/people/edit/3">Edit</a></td>
-  #         <td><a href="/people/delete/3">Delete</a></td>
-  #       </tr>
-  #     </tbody>
+  #     <tr>
+  #       <th>ID</th>
+  #       <th>Last Name</th>
+  #       <th>First Name</th>
+  #       <th>Email</th>
+  #       <th></th>
+  #       <th></th>
+  #     </tr>
+  #     <tr class="odd_row">
+  #       <td align="right">2</td>
+  #       <td>Doe</td>
+  #       <td>Jane</td>
+  #       <td><a href="mailto:janedoe at example.com">janedoe at example.com</a></td>
+  #       <td><a href="/people/edit/2">Edit</a></td>
+  #       <td><a href="/people/delete/2">Delete</a></td>
+  #     </tr>
+  #     <tr class="even_row">
+  #       <td align="right">3</td>
+  #       <td>Body</td>
+  #       <td>Some</td>
+  #       <td><a href="mailto:somebody at example.com">somebody at example.com</a></td>
+  #       <td><a href="/people/edit/3">Edit</a></td>
+  #       <td><a href="/people/delete/3">Delete</a></td>
+  #     </tr>
   #   </table>
   class CollectionTable
     # The attribute of each item in the collection that can be used as a unique
@@ -84,10 +80,6 @@
     # Takes an array of CSS class names. The class names will be applied in
     # sequence to the +tr+ tag of each data row.
     attr_writer :data_row_class
-    
-    attr_writer :table_id
-    
-    attr_writer :tbody_id
 
     # Returns a new CollectionTable object that will operate on the +items+ (any
     # enumerable) and will display a column for each of the specified +columns+.
@@ -124,12 +116,9 @@
     # Returns the complete HTML for the table based on the options set on the
     # object with a data row for each item in the collection.
     def build_table
-      output = "<table #{@table_id.nil? ? '' : "id=\"#{@table_id}\" "}" +
-               "class=\"collection_table\">\n"
+      output = "<table class=\"collection_table\">\n"
       output += header_row
-      output += "\n  <tbody#{@tbody_id.nil? ? '' : " id=\"#{@tbody_id}\""}>\n"
       output += @items.inject('') { |txt,item| txt + data_row(item) }
-      output += "  </tbody>\n"
       output += "</table>\n"
     end
 
@@ -189,18 +178,18 @@
         else
           td = "<td>"
         end
-        txt + "      #{td + cell_content}</td>\n"
+        txt + "    #{td + cell_content}</td>\n"
       end
-      "    <tr#{current_row_class}>\n" +
-      data_cells + "    </tr>\n"
+      "  <tr#{current_row_class}>\n" +
+      data_cells + "  </tr>\n"
     end
 
     # Returns the complete table header row
     def header_row
       header_cells = @column_order.inject('') do |txt,col|
-        txt + "      <th>#{heading_for(col)}</th>\n"
+        txt + "    <th>#{heading_for(col)}</th>\n"
       end
-      "  <thead>\n    <tr>\n" + header_cells + "    </tr>\n  </thead>"
+      "  <tr>\n" + header_cells + "  </tr>\n"
     end
 
 

Modified: trunk/test/unit/collection_table_helper_test.rb
===================================================================
--- trunk/test/unit/collection_table_helper_test.rb	2006-03-27 16:04:35 UTC (rev 213)
+++ trunk/test/unit/collection_table_helper_test.rb	2006-03-27 16:21:40 UTC (rev 214)
@@ -63,24 +63,17 @@
   def test_header_row
     ct = CollectionTableHelper::CollectionTable.new(@items, [:id,'ID'], :name,
                                                     :phone)
-    expected = "  <thead>\n" +
-               "    <tr>\n" +
-               "      <th>ID</th>\n" +
-               "      <th>Name</th>\n" +
-               "      <th>Phone</th>\n" +
-               "    </tr>\n" +
-               "  </thead>"
+    expected = "  <tr>\n    <th>ID</th>\n    <th>Name</th>\n" +
+               "    <th>Phone</th>\n  </tr>\n"
     assert_equal expected, ct.send(:header_row)
   end
 
   def test_data_row
     ct = CollectionTableHelper::CollectionTable.new(@items, :id, :name, :phone)
     item = @items.first
-    expected = "    <tr>\n" +
-               "      <td>#{item.id}</td>\n" +
-               "      <td>#{item.name}</td>\n" +
-               "      <td>#{item.phone}</td>\n" +
-               "    </tr>\n"
+    expected = "  <tr>\n    <td>#{item.id}</td>\n" +
+               "    <td>#{item.name}</td>\n    <td>#{item.phone}</td>\n" +
+               "  </tr>\n"
     assert_equal expected, ct.send(:data_row, item)
   end
 
@@ -94,12 +87,11 @@
       "<a href=\"/item/edit/#{item.id}\">Edit</a>"
     }
     item = @items.first
-    expected = "    <tr>\n" +
-               "      <td>#{item.id}</td>\n" +
-               "      <td>#{item.name}</td>\n" +
-               "      <td>#{item.phone.gsub('-','#')}</td>\n" +
-               "      <td><a href=\"/item/edit/#{item.id}\">Edit</a></td>\n" +
-               "    </tr>\n"
+    expected = "  <tr>\n    <td>#{item.id}</td>\n" +
+               "    <td>#{item.name}</td>\n" +
+               "    <td>#{item.phone.gsub('-','#')}</td>\n" +
+               "    <td><a href=\"/item/edit/#{item.id}\">Edit</a></td>\n" +
+               "  </tr>\n"
     assert_equal expected, ct.send(:data_row, item)
   end
 
@@ -119,9 +111,7 @@
     ct = CollectionTableHelper::CollectionTable.new(@items, :id)
     ct.column_align(:id, 'right')
     item = @items.shift
-    expected = "    <tr>\n" +
-               "      <td align=\"right\">#{item.id}</td>\n" +
-               "    </tr>\n"
+    expected = "  <tr>\n    <td align=\"right\">#{item.id}</td>\n  </tr>\n"
     assert_equal expected, ct.send(:data_row, item)
   end
 
@@ -131,59 +121,23 @@
     ct.data_row_class = [ 'odd_row', 'even_row' ]
     expected = <<EOF
 <table class="collection_table">
-  <thead>
-    <tr>
-      <th>ID</th>
-      <th>Name</th>
-      <th>Phone</th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr class="odd_row">
-      <td>1</td>
-      <td>John Doe</td>
-      <td>555-5555</td>
-    </tr>
-    <tr class="even_row">
-      <td>2</td>
-      <td>Jane Doe</td>
-      <td>666-6666</td>
-    </tr>
-  </tbody>
+  <tr>
+    <th>ID</th>
+    <th>Name</th>
+    <th>Phone</th>
+  </tr>
+  <tr class="odd_row">
+    <td>1</td>
+    <td>John Doe</td>
+    <td>555-5555</td>
+  </tr>
+  <tr class="even_row">
+    <td>2</td>
+    <td>Jane Doe</td>
+    <td>666-6666</td>
+  </tr>
 </table>
 EOF
     assert_equal expected, ct.build_table
   end
-  
-  def test_table_and_tbody_id
-    ct = CollectionTableHelper::CollectionTable.new(@items, [:id,'ID'], :name,
-                                                    :phone)
-    ct.data_row_class = [ 'odd_row', 'even_row' ]
-    ct.table_id = 'MyTable'
-    ct.tbody_id = 'MyTBody'
-    expected = <<EOF
-<table id="MyTable" class="collection_table">
-  <thead>
-    <tr>
-      <th>ID</th>
-      <th>Name</th>
-      <th>Phone</th>
-    </tr>
-  </thead>
-  <tbody id="MyTBody">
-    <tr class="odd_row">
-      <td>1</td>
-      <td>John Doe</td>
-      <td>555-5555</td>
-    </tr>
-    <tr class="even_row">
-      <td>2</td>
-      <td>Jane Doe</td>
-      <td>666-6666</td>
-    </tr>
-  </tbody>
-</table>
-EOF
-    assert_equal expected, ct.build_table
-  end
 end





More information about the Explainpmt-developers mailing list