Permalink
Browse files

classes and ids are better now

  • Loading branch information...
1 parent 3e6e478 commit e4afa0bf3af0846af7d7830150c3fa5be0beb041 Iain Hecker committed Nov 6, 2008
Showing with 14 additions and 13 deletions.
  1. +4 −2 lib/model_based_html/base.rb
  2. +10 −11 lib/model_based_html/table.rb
@@ -8,11 +8,12 @@ def initialize(type, object, template, &block)
end
# Sets all the defaults and stuff
- def default(type, object, template, &block)
+ def default(type, object, template, options = {}, &block)
object = object.to_s.camelize.constantize.new if object.is_a?(Symbol)
@object = object
@template = template
- open_tag(start_tag(type, :object_html => @object))
+ options = { :object_html => @object }.merge(options)
+ open_tag(start_tag(type, options))
yield self
close_tag("</#{type}>")
end
@@ -96,6 +97,7 @@ def name(method_or_value)
# echo it in your views.
# <% dl.dd :name %> will be the same as <%= dl.dd :name %>
def concat(*args)
+ args[0] = args.at(0).to_s
@tags_opened ||= 0
@template.concat("\n")
@template.concat(" " * (@tags_opened))
@@ -15,7 +15,8 @@ def initialize(type, collection, template, options = {}, &block)
object = collection.first
end
@collection = collection
- default(:table, object, template, &block)
+ @columns = []
+ default(:table, object, template, { :object_html => collection }, &block)
end
def head(options = {}, &block)
@@ -36,20 +37,18 @@ def body(options = {}, &block)
sanitize = options.delete(:sanitize) or false
open_tag(start_tag(:tbody, options))
- if block_given?
- @collection.each do |object|
+ @collection.each do |object|
+ if block_given?
@object = object
yield object
- end
- else
- raise ArgumentError, "No columns defined. Make a head with at least 1 th." if @columns.nil? or @columns.empty?
- @collection.each do |o|
- tr(o) do
+ else
+ raise ArgumentError, "No columns defined. Make a head with at least 1 th." if @columns.nil? or @columns.empty?
+ tr(:object_html => object) do
@columns.each do |column|
- if columns.is_a?(Symbol)
- sanitize ? td_h(o.send(column)) : td(o.send(column))
+ if column.is_a?(Symbol)
+ sanitize ? td_h(object.send(column)) : td(object.send(column))
else
- td('')
+ td('&nbsp;', :class => 'empty_cell')
end
end
end

0 comments on commit e4afa0b

Please sign in to comment.