Class: ActionTable::BootstrapStyles

Inherits:
Object
  • Object
show all
Defined in:
lib/action_table/bootstrap_styles.rb

Constant Summary collapse

BOOTSTRAP_TABLE_WRAPERS =
Set.new(
  %w[
    responsive
    responsive-sm
    responsive-md
    responsive-lg
    responsive-xl
  ],
).freeze
BOOTSTRAP_UTILS =

All the below can be used on <table>, <thead>, <tr>, <td>

Set.new(
  %w[
    dark
    light
    primary
    success
    danger
    info
    warning
    active
    secondary
  ],
)
BOOTSTRAP_TABLE_STYLES =

.thead-light or .thead-dark

    <th scope="row">1</th>
<caption>List of users</caption> # directly under <table>
(
  Set.new(
    %w[
      striped
      sm
      bordered
      hover
      borderless
    ],
  ) + BOOTSTRAP_UTILS
).freeze

Instance Method Summary collapse

Constructor Details

#initialize(styles) ⇒ BootstrapStyles

Returns a new instance of BootstrapStyles.



45
46
47
48
49
50
51
# File 'lib/action_table/bootstrap_styles.rb', line 45

def initialize(styles)
  @styles = Array(styles).map { |style| style.to_s.tr('_', '-') }
  @responsive_wrapper_class = nil
  @table_classes = nil

  validate_styles!(@styles)
end

Instance Method Details

#responsive_wrapper_classObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/action_table/bootstrap_styles.rb', line 53

def responsive_wrapper_class
  return @responsive_wrapper_class if @responsive_wrapper_class

  wrappers = BOOTSTRAP_TABLE_WRAPERS.select { |style| @styles.include?(style) }
  return if wrappers.empty?

  @responsive_wrapper_class = wrappers.map do |style|
    "table-#{style}" if wrapper_class?(style)
  end.join(' ')
end

#table_classesObject



64
65
66
67
68
69
70
71
72
# File 'lib/action_table/bootstrap_styles.rb', line 64

def table_classes
  return @table_classes if @table_classes

  style_classes = @styles.map do |style|
    "table-#{style}" if table_class?(style)
  end.compact

  @table_classes = "table #{style_classes.join(' ')}"
end