Permalink
Browse files

Separate column/row/table classes

  • Loading branch information...
1 parent fd10169 commit 75969bcb5a43d32815cfebb570393d3ff42a1963 Joe Fiorini committed Jan 16, 2010
Showing with 53 additions and 0 deletions.
  1. +14 −0 lib/totally_tabular/column.rb
  2. +19 −0 lib/totally_tabular/row.rb
  3. +20 −0 lib/totally_tabular/table.rb
@@ -0,0 +1,14 @@
+module TotallyTabular
+ class Column
+ attr_accessor :name, :template, :header_attributes
+
+ def initialize(name)
+ @name = name
+ end
+
+ def template!(&block)
+ @template = block
+ end
+
+ end
+end
View
@@ -0,0 +1,19 @@
+module TotallyTabular
+ class Row
+
+ def initialize
+ @helper = HtmlHelper.new
+ @attributes = {}
+ end
+
+ def attributes!(attributes={})
+ @attributes = attributes
+ end
+
+ def render(content)
+ if !content.empty?
+ @helper.content_tag(:tr, content, @attributes)
+ end.to_s
+ end
+ end
+end
@@ -0,0 +1,20 @@
+module TotallyTabular
+ class Table
+ attr_reader :columns
+
+ def initialize
+ @columns = []
+ end
+
+ def column(name, header_attributes={}, &block)
+ column = Column.new(name)
+ block.call(column)
+ column.header_attributes = header_attributes
+ @columns << column
+ end
+
+ def columns_count
+ @columns.length
+ end
+ end
+end

0 comments on commit 75969bc

Please sign in to comment.