Sha256: 2c0d1168f6fd33c5b9337854683cb910d95227f04aaa3c8ea60900b12ff595de

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class BootstrapBuilders::Box
  def initialize(args)
    @title = args.fetch(:title)
    @width = args.fetch(:width)
    @right = args[:right]
    @table = args[:table]
    @block = args.fetch(:block)

    @width = "#{@width}px" if @width.is_a?(Fixnum) || @width.is_a?(Integer)
  end

  def html
    @panel = HtmlGen::Element.new(:div, classes: ["panel", "panel-default"], css: {width: @width})

    add_heading if @title || @right

    if @table
      add_table
    else
      add_body
    end

    html = @panel.html

    if html.respond_to?(:html_safe)
      html.html_safe
    else
      html
    end
  end

private

  def add_heading
    heading = @panel.add_ele(:div, classes: ["panel-heading", "clearfix"])
    title = heading.add_ele(:div, classes: ["panel-title", "pull-left"], str: @title)
    title.add_ele(:div, classes: ["pull-right"], str_html: @right)
  end

  def add_table
    @panel.add_ele(:table, classes: ["table", "table-striped", "table-hover"], str_html: @block.call)
  end

  def add_body
    @panel.add_ele(:div, classes: ["panel-body"], str_html: @block.call)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bootstrap_builders-0.0.1 lib/bootstrap_helpers/box.rb