Module: Btgen::Helper

Defined in:
lib/btgen/helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_description(instance, attributes) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/btgen/helper.rb', line 43

def bootstrap_description(instance, attributes)
   :dl, class: 'dl-horizontal' do
    attributes.to_a.map do |(k, v)|
      ( :dt, instance.class.human_attribute_name(k)) + ( :dd, v)
    end.inject(:+)
  end
end

#bootstrap_table(args = {}) {|table| ... } ⇒ Object

Yields:

  • (table)


5
6
7
8
9
# File 'lib/btgen/helper.rb', line 5

def bootstrap_table(args = {})
  table = BootstrapTable.new args
  yield table
  table.to_html
end

#expand_collapsible_label(target_id) ⇒ Object



11
12
13
# File 'lib/btgen/helper.rb', line 11

def expand_collapsible_label(target_id)
  icon :plus, href: "##{target_id}", data: {toggle: 'collapse'}
end

#panel_with_body(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/btgen/helper.rb', line 15

def panel_with_body(*args)

  body_classes = ['panel-body']

  random_string = (0...8).map { (65 + rand(26)).chr }.join
  body_options = {id: "collapsible_#{random_string.downcase}"}
  title_fragments = []

  if args.last[:icon]
    title_fragments << icon(args.last[:icon][:type].to_sym, class: args.last[:icon][:class])
  end

  if args.last[:collapsible]
    body_classes << 'collapse'
    title_fragments << expand_collapsible_label(body_options[:id])
  end

  title_fragments << sanitize(args.last[:title])
  args.last[:title] = title_fragments.compact.inject(:+).html_safe

  panel(*args) do
    body_options[:class] = body_classes.join(' ')
     :div, body_options do
      yield
    end
  end
end