Class: Hirb::Helpers::AutoTable

Inherits:
Table
  • Object
show all
Extended by:
DynamicView
Defined in:
lib/hirb/helpers/auto_table.rb

Overview

This helper wraps around the other table helpers i.e. Hirb::Helpers::Table while providing default helper options via Hirb::DynamicView. Using these default options, this helper supports views for the following modules/classes: ActiveRecord::Base, CouchFoo::Base, CouchPotato::Persistence, CouchRest::ExtendedDocument, DBI::Row, DataMapper::Resource, Friendly::Document, MongoMapper::Document, MongoMapper::EmbeddedDocument, Mongoid::Document, Ripple::Document, Sequel::Model.

Constant Summary

Constants inherited from Table

Table::BORDER_LENGTH, Table::CHARS, Table::MIN_FIELD_LENGTH

Instance Attribute Summary

Attributes inherited from Table

#field_lengths, #fields, #max_fields, #width

Class Method Summary collapse

Methods included from DynamicView

add, add_module, class_to_method, dynamic_options, generate_single_view_module, method_to_class, update_config, view_method_classes, view_methods

Methods inherited from Table

#actual_width, #array_to_indices_hash, #call_filter, #chars, choose_style, #default_field_lengths, #enforce_field_constraints, #filter_values, #format_cell, #format_values, #initialize, #render, #render_border, #render_footer, #render_header, #render_rows, #render_table_description, #render_table_header, #set_fields, #set_filter_defaults, #set_headers, #set_rows, #setup_field_lengths, #validate_values

Constructor Details

This class inherits a constructor from Hirb::Helpers::Table

Class Method Details

.render(output, options = {}) ⇒ Object

Takes same options as Hirb::Helpers::Table.render except as noted below.

Options:

:table_class

Explicit table class to use for rendering. Defaults to Hirb::Helpers::ObjectTable if output is not an Array or Hash. Otherwise defaults to Hirb::Helpers::Table.



16
17
18
19
20
21
22
23
# File 'lib/hirb/helpers/auto_table.rb', line 16

def self.render(output, options={})
  output = Array(output)
  (defaults = dynamic_options(output[0])) && (options = defaults.merge(options))
  klass = options.delete(:table_class) || (
    !(output[0].is_a?(Hash) || output[0].is_a?(Array)) ?
    Hirb::Helpers::ObjectTable : Hirb::Helpers::Table)
  klass.render(output, options)
end