Class: TableHelp::TableFor
- Inherits:
-
Object
- Object
- TableHelp::TableFor
- Defined in:
- lib/table_help/table_for.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Instance Method Summary collapse
- #column(name = nil, method_name = nil, &block) ⇒ Object
-
#initialize(collection, context, options = {}) ⇒ TableFor
constructor
A new instance of TableFor.
- #to_html ⇒ Object
Constructor Details
#initialize(collection, context, options = {}) ⇒ TableFor
Returns a new instance of TableFor.
8 9 10 11 12 13 14 15 |
# File 'lib/table_help/table_for.rb', line 8 def initialize(collection, context, = {}) @collection = collection @context = context @options = .merge() @columns = [] @strategies = [] @q = @options.delete(:q) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def collection @collection end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def columns @columns end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def context @context end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def @options end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def q @q end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
5 6 7 |
# File 'lib/table_help/table_for.rb', line 5 def strategies @strategies end |
Instance Method Details
#column(name = nil, method_name = nil, &block) ⇒ Object
17 18 19 20 |
# File 'lib/table_help/table_for.rb', line 17 def column(name = nil, method_name = nil, &block) columns << Column.new(name, Formatter.format_attribute_name(name, collection)) strategies << Strategy.new(name, block_given? ? block : method_name) end |
#to_html ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/table_help/table_for.rb', line 22 def to_html return if collection.empty? tag.table() do concat thead concat tbody end end |