class Card::Bootstrap::Component::Layout

generate bootstrap column layout @example

layout container: true, fluid: true, class: "hidden" do
  row 6, 6, class: "unicorn" do
    column "horn",
    column "rainbow", class: "colorful"
  end
end

@example

layout do
  row 3, 3, 4, 2, class: "unicorn" do
    [ "horn", "body", "tail", "rainbow"]
  end
  add_html "<span> some extra html</span>"
  row 6, 6, ["unicorn", "rainbow"], class: "horn"
end

Public Instance Methods

render() click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 21
def render
  @rendered = begin
    render_content
    @content[-1]
  end
end
render_content() click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 28
def render_content
  content = instance_exec(*@args, &@build_block)
  add_content content
  opts = @args.first
  return unless opts&.delete(:container)

  content = @content.pop
  @content = ["".html_safe]
  container content, opts
end

Private Instance Methods

col_widths(args, opts) click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 82
def col_widths args, opts
  opts = args.pop if args.one? && args.last.is_a?(Hash)
  if args.present?
    col_widths_from_args args
  else
    col_widths_from_opts opts
  end
end
col_widths_from_args(args) click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 91
def col_widths_from_args args
  raise Error, "bad argument" unless args.all? { |a| a.is_a? Integer }

  { md: Array.wrap(args) }
end
col_widths_from_opts(opts) click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 97
def col_widths_from_opts opts
  %i[lg xs sm md].each_with_object({}) do |k, cols_w|
    next unless (widths = opts.delete(k))

    cols_w[k] = Array.wrap widths
  end
end
standardize_row_args(args) click to toggle source
# File lib/card/bootstrap/component/layout.rb, line 75
def standardize_row_args args
  opts = args.last.is_a?(Hash) ? args.pop : {}
  cols = (args.last.is_a?(Array) || args.last.is_a?(String)) &&
         Array.wrap(args.pop)
  [cols, opts, col_widths(args, opts)]
end