Class: AwesomeTables::AwesomeTable
- Inherits:
-
Object
- Object
- AwesomeTables::AwesomeTable
- Defined in:
- lib/awesome_tables/awesome_table.rb
Constant Summary collapse
- @@tables =
{}
Instance Attribute Summary collapse
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#data ⇒ Object
Returns the value of attribute data.
-
#partial ⇒ Object
Returns the value of attribute partial.
Class Method Summary collapse
Instance Method Summary collapse
- #caption? ⇒ Boolean
-
#column(*args) ⇒ Object
example column colls t.column :created_at, :display_created_at t.column :body, :partial => ‘awesome_tables/posts/body’ t.column :comments, :comment_count, :with_image => ‘comments.png’ t.column :full_name.
-
#initialize(table_type, data = [], options = {}) ⇒ AwesomeTable
constructor
A new instance of AwesomeTable.
- #paginate? ⇒ Boolean
- #set_caption(caption) ⇒ Object
Constructor Details
#initialize(table_type, data = [], options = {}) ⇒ AwesomeTable
Returns a new instance of AwesomeTable.
12 13 14 15 16 17 18 19 20 |
# File 'lib/awesome_tables/awesome_table.rb', line 12 def initialize(table_type, data = [], = {}) @data = data @paginate = true if @data.is_a? WillPaginate::Collection @columns = [] @template = [:template] ||= 'awesome_tables/base' # is this the best way to do this? raise AwesomeTables::UnknownTableTypeException if @@tables[table_type].blank? @@tables[table_type].call(self) end |
Instance Attribute Details
#caption ⇒ Object
Returns the value of attribute caption.
5 6 7 |
# File 'lib/awesome_tables/awesome_table.rb', line 5 def @caption end |
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/awesome_tables/awesome_table.rb', line 5 def columns @columns end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/awesome_tables/awesome_table.rb', line 5 def data @data end |
#partial ⇒ Object
Returns the value of attribute partial.
5 6 7 |
# File 'lib/awesome_tables/awesome_table.rb', line 5 def partial @partial end |
Class Method Details
.register(table_type, &block) ⇒ Object
7 8 9 10 |
# File 'lib/awesome_tables/awesome_table.rb', line 7 def self.register(table_type, &block) raise AwesomeTables::NoBlockGivenException unless block_given? @@tables[table_type] = block end |
Instance Method Details
#caption? ⇒ Boolean
22 23 24 |
# File 'lib/awesome_tables/awesome_table.rb', line 22 def !@caption.blank? end |
#column(*args) ⇒ Object
example column colls t.column :created_at, :display_created_at t.column :body, :partial => ‘awesome_tables/posts/body’ t.column :comments, :comment_count, :with_image => ‘comments.png’ t.column :full_name
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/awesome_tables/awesome_table.rb', line 38 def column(*args) name = args[0].to_s.titleize if args[1].nil? method = args[0] elsif args[1].is_a? Symbol method = args[1] = args[2] else raise AwesomeTables::NoPartialProvidedException unless args[1].keys.include?(:partial) method = args[1].delete(:partial) = args[1] end @columns << { :header => name, :method => method, :options => ||= {} } end |
#paginate? ⇒ Boolean
26 27 28 |
# File 'lib/awesome_tables/awesome_table.rb', line 26 def paginate? @paginate end |
#set_caption(caption) ⇒ Object
30 31 32 |
# File 'lib/awesome_tables/awesome_table.rb', line 30 def () @caption = end |