module StandardTableBuilder::Sorting

Provides headers with sort links. Expects a method :sortable?(attr) in the template/controller to tell if an attribute is sortable or not. Extracted into an own module for convenience.

Public Instance Methods

sort_header(attr, label = nil) click to toggle source

Create a header with sort links and a mark for the current sort direction.

# File lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb, line 126
def sort_header(attr, label = nil)
  label ||= attr_header(attr)
  template.link_to(label, sort_params(attr)) + current_mark(attr)
end
sortable_attr(a, header = nil) click to toggle source

Renders a sort link header, otherwise similar to :attr.

# File lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb, line 140
def sortable_attr(a, header = nil)
  attr(a, sort_header(a, header))
end
sortable_attrs(*attrs) click to toggle source

Same as :attrs, except that it renders a sort link in the header if an attr is sortable.

# File lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb, line 133
def sortable_attrs(*attrs)
  attrs.each do |a|
    template.sortable?(a) ? sortable_attr(a) : attr(a)
  end
end