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.
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
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
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