Class: Autotable::Builder
- Inherits:
-
Object
- Object
- Autotable::Builder
- Defined in:
- lib/autotable/builder.rb
Instance Method Summary collapse
- #action(title, options = {}) ⇒ Object
- #column(method, title = nil, &formatter) ⇒ Object
-
#initialize(collection, template, options) ⇒ Builder
constructor
A new instance of Builder.
- #to_html ⇒ Object
Constructor Details
#initialize(collection, template, options) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 |
# File 'lib/autotable/builder.rb', line 5 def initialize(collection, template, ) @collection, @template = collection, template = DEFAULT_OPTIONS.merge() @columns, @actions = [], [] end |
Instance Method Details
#action(title, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/autotable/builder.rb', line 26 def action(title, = {}) [:title] = title @actions << end |
#column(method, title = nil, &formatter) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/autotable/builder.rb', line 11 def column(method, title = nil, &formatter) if method.is_a?(String) title = method method = nil end @columns << { :method => method, :title => title || method.to_s.humanize, :formatter => formatter } nil end |
#to_html ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/autotable/builder.rb', line 31 def to_html html = "<table class='#{table_class}'>\n" html << header_html html << "<tbody>\n" if @collection.empty? html << "<tr class='warning'>\n" html << "<td colspan='#{@columns.size + 1}'>No items found</td>\n" html << "</tr>\n" else @collection.each { |c| html << row_html(c) } end html << "</tbody>\n" html << "</table>\n" html.html_safe end |