Module: Bootstrap::TableHelper

Defined in:
app/helpers/bootstrap/table_helper.rb

Overview

Rails helper for producing consistent Bootstrap styled tables.

Examples:

# in your view

<%= bs_table_tag do %>
  ...

<%= bs_table_tag(id: 'my-id', class: 'another-class') do %>
  ...

# configure a custom set of classes:
Bootstrap::TableHelper.classes[:admin] = %w(admin table table-striped table-compact)

<%= bs_table_tag(:admin) do %>

Constant Summary collapse

InvalidClassListsKeyError =
Class.new(StandardError)
DEFAULT_CLASS_LIST =
%w(table table-bordered table-striped table-hover)

Instance Method Summary collapse

Instance Method Details

#bs_table_tag(class_list = :default, options = {}) ⇒ String

Produces a wrapper TABLE element with Bootstrap classes.

Parameters:

  • class_list (Symbol)

    a key of the Bootstrap::class_lists Hash

  • options (Hash)

    unrecognized options become attributes of the <table> element

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
# File 'app/helpers/bootstrap/table_helper.rb', line 32

def bs_table_tag(*args, &block)
  options = canonicalize_options(args.extract_options!)
  table_classes = _get_table_classes(args.shift)
  options = ensure_class(options, table_classes)
  
  (:table, options) do
    yield
  end
end