Sha256: bdf36ddfc9c8f077e29e2122ff337fd3a5bbb81aa75dfd7216d2acedbbfe1f83

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

module BootstrapIt
  #
  module ViewHelpers
    #
    # Table
    #
    # @author [alexiss]
    #
    class Table < WrapIt::Container
      html_class 'table'
      html_class_prefix 'table-'

      switch :striped, html_class: true
      switch :bordered, html_class: true
      switch :hover, html_class: true
      switch :condensed, html_class: true
      switch :responsive do |value|
        value && wrap(class: 'table-responsive')
      end

      child :row, 'BootstrapIt::ViewHelpers::TableRow'

      after_initialize { @tag = 'table' }

      # TODO: remove it since WrapIt 0.1.5
      def unwrap
        @wrapper = nil
      end
    end

    #
    # TableRow
    #
    # @author [alexiss]
    #
    class TableRow < WrapIt::Container
      include Contextual

      child :cell, 'BootstrapIt::ViewHelpers::TableCell'
      alias_method :td, :cell

      child :head, 'BootstrapIt::ViewHelpers::TableCell', [tag: 'th']
      alias_method :th, :head
      alias_method :header, :head

      after_initialize { @tag = 'tr' }
    end

    #
    # TableCell
    #
    # @author [alexiss]
    #
    class TableCell < WrapIt::Base
      include WrapIt::TextContainer
      include SizableColumn
      include Contextual

      after_initialize do
        header = !@arguments.extract_first!([:header, :head, :th]).nil?
        header ||= @options[:header] == true || @options[:head] == true ||
          @options[:th] == true
        @options.delete(:header)
        @options.delete(:head)
        @options.delete(:th)
        @tag = header || @tag == 'th' ? 'th' : 'td'
      end
    end

    WrapIt.register :table, 'BootstrapIt::ViewHelpers::Table'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstrap_it-0.1.1 lib/bootstrap_it/view_helpers/table.rb
bootstrap_it-0.1.0 lib/bootstrap_it/view_helpers/table.rb