Sha256: 89c4228315db0432e327b2613e2f16a30b64289f82b3cee09355b11bdc349568

Contents?: true

Size: 1.13 KB

Versions: 46

Compression:

Stored size: 1.13 KB

Contents

class BootstrapBuilders::Table
  def initialize(args)
    @args = args
    @blk = args.fetch(:blk)
    @context = args.fetch(:context)
  end

  def html
    if @blk
      buffer = @context.content_tag(:table, attributes, &@blk)
    else
      buffer = @context.content_tag(:table, @content, attributes)
    end

    return buffer unless @args[:responsive]

    @context.content_tag(:div, buffer, class: "table-responsive")
  end

private

  def attributes
    attributes = {class: classes}

    pass_through = [:data]
    pass_through.each do |pass_through_arg|
      next unless @args.key?(pass_through_arg)
      attributes[pass_through_arg] = @args[pass_through_arg]
    end

    attributes
  end

  def classes
    if @args[:bs_classes]
      classes = @args[:bs_classes]
    else
      classes = BootstrapBuilders.configuration.default_table_classes
    end

    classes = classes.map { |class_name| "table-#{class_name}" }

    if @args[:class].is_a?(String)
      classes += @args.fetch(:class).split(/\s+/)
    elsif @args[:class].is_a?(Array)
      classes += @args.fetch(:class)
    end

    classes += ["table", "bb-table"]
    classes
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
bootstrap_builders-1.0.4 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.63 lib/bootstrap_builders/table.rb
bootstrap_builders-1.0.3 lib/bootstrap_builders/table.rb
bootstrap_builders-1.0.2 lib/bootstrap_builders/table.rb
bootstrap_builders-1.0.1 lib/bootstrap_builders/table.rb
bootstrap_builders-1.0.0 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.62 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.61 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.60 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.59 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.58 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.57 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.56 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.55 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.54 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.53 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.52 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.51 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.50 lib/bootstrap_builders/table.rb
bootstrap_builders-0.0.49 lib/bootstrap_builders/table.rb