lib/table_helper/row.rb in table_helper-0.1.0 vs lib/table_helper/row.rb in table_helper-0.2.0

- old
+ new

@@ -3,20 +3,18 @@ module TableHelper # Provides a blank class that can be used to build the cells for a row class RowBuilder < BlankSlate #:nodoc: reveal :respond_to? - attr_reader :row - # Creates a builder for the given row def initialize(row) @row = row end # Proxies all missed methods to the row def method_missing(*args) - row.send(*args) + @row.send(*args) end # Defines the builder method for the given cell name. For example, if # a cell with the name :title was defined, then the cell would be able # to be read and written like so: @@ -28,13 +26,13 @@ klass = class << self; self; end klass.class_eval do define_method(method_name) do |*args| if args.empty? - row.cells[name] + @row.cells[name] else - row.cell(name, *args) + @row.cell(name, *args) end end end unless klass.method_defined?(method_name) end @@ -56,20 +54,31 @@ attr_reader :builder # The current cells in this row, in the order in which they will be built attr_reader :cells - def initialize #:nodoc: - super + # The parent element for this row + attr_reader :parent + + delegate :empty?, :to => :cells + delegate :table, :to => :parent + + def initialize(parent) #:nodoc: + super() + @parent = parent @cells = ActiveSupport::OrderedHash.new @builder = RowBuilder.new(self) end # Creates a new cell with the given name and generates shortcut # accessors for the method. def cell(name, *args) name = name.to_s if name + + options = args.last.is_a?(Hash) ? args.pop : {} + options[:namespace] = table.object_name + args << options cell = Cell.new(name, *args) cells[name] = cell builder.define_cell(name) if name