Module: BoxCutter::BoxHelpers

Defined in:
lib/box-cutter/helpers/box_helpers.rb

Defined Under Namespace

Classes: BoxOptions

Instance Method Summary collapse

Instance Method Details

#box(options = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/box-cutter/helpers/box_helpers.rb', line 23

def box(options={}, &block)
  opts = BoxOptions.new(options)

  buffer = []
  if opts.if
    buffer << "<div class='#{opts.span}#{opts.offset}'><div>"
    buffer << "<div class='box #{opts.color}#{opts.klass}'>"
    if !opts.title.empty? || opts.links.any?
      buffer << "<div class='tab-header'>#{opts.title}<div class='pull-right tab-header-right'><div class='space-right actions'>"
      buffer << opts.links.map { |l| link_to(l[0], l[1], {class: 'ml5'}.merge(l[2] || {})) }
      buffer << '</div></div></div>'
    end
    if block_given?
      buffer << "<div class='box-content padded#{opts.padding}'>"
      buffer << capture(&block)
      buffer << '</div>'
    end
    buffer << '</div></div></div>'
  end
  buffer.flatten.join('').html_safe
end