class Spyro::ActionViewExtension::CollectionForHelper::Output::Table

Public Instance Methods

custom_value_formatted(value, elem) click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 70
def custom_value_formatted value, elem
  value
end
format_value(value, elem) click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 57
def format_value value, elem
  return self.send("format_#{elem.as}".to_sym, value, {}) if elem.as


  @@fields.each do |keys, values|
    klass, pattern = *keys
    if (Symbol === klass and klass == elem.db_type) or (Class === klass and value.is_a? klass)
      return self.send("format_#{values[:method]}".to_sym, value, {}) if elem.name.to_s.match pattern
    end
  end
  value
end
header() click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 14
def header
  @header ||= (@unicollection.meta[:header] || []) + (@unicollection.meta[:actions] ? ['Actions'] : [])
end
render() click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 112
def render
  return "" if @unicollection.rows.empty?
  table_html_opts = {:class => ['table', self.class.to_s.demodulize.underscore]}.deep_merge(@unicollection.meta[:html] || {}) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
  content_tag :table, table_html_opts do
    html = render_header.html_safe
    html << render_body
    html << render_footer
    html
  end
end
render_body() click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 74
def render_body
  content = @unicollection.rows.map do |row|
    html = row[:data].map do |elem|
      value_formatted = elem.value
      value_formatted = t(value_formatted) if elem.translate
      value_formatted = format_value value_formatted, elem
      value_formatted = link_to value_formatted, elem.link if elem.link
      value_formatted = custom_value_formatted value_formatted, elem
      elem.html ? content_tag(:td, value_formatted, elem.html) : "<td>#{value_formatted}</td>"
    end.join('')
    html += render_cell_buttons row if @unicollection.meta[:actions]
    (row[:meta][:opts] and row[:meta][:opts][:html]) ? content_tag(:tr, html.html_safe, row[:meta][:opts][:html]) : "<tr>#{html}</tr>"
  end.join('').html_safe

  if @unicollection.meta[:header]
    content_tag :tbody, @unicollection.meta[:html_body] do
      content
    end
  else
    content
  end
end
render_cell_buttons(row) click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 34
def render_cell_buttons row
  row[:meta][:actions] = {} if row[:meta][:actions].nil?

  html = if row[:meta][:actions].is_a? Hash
           (row[:meta][:actions] || []).map do |name, link|
             case name
               when :show
                 mini_button_success name, link
               when :edit
                 mini_button_info name, link
               when :destroy
                 mini_button_danger name, link, default_destroy_link_attributes
               else
                 mini_button name, link
             end
           end.join ''
         else
           row[:meta][:actions]
         end

  "<td><span class='btn-group'>#{html}</span></td>"
end
render_header() click to toggle source
# File lib/spyro/collections/outputs/table.rb, line 18
def render_header
  return "" unless @unicollection.meta[:header]
  content_tag :thead, @unicollection.meta[:html_header] do
    html = header.map do |header_sym|
      header = t(header_sym)
      header = @unicollection.meta[:block_header].call header_sym, header if @unicollection.meta[:block_header]
      "<th>#{header}</th>"
    end.join('')
    "<tr>#{html}</tr>".html_safe
  end
end