Module: TbHelpers::Components

Defined in:
lib/tb-helpers/components.rb

Instance Method Summary collapse

Instance Method Details

#tb_alert_flash(key, options = nil, tag = :div, escape = true) ⇒ Object

alerts



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tb-helpers/components.rb', line 6

def tb_alert_flash(key, options = nil, tag = :div, escape = true)
  return nil if flash[key].blank?

  options ||= {}
  context = delete_option_if_exists!(options, :context, key)
  closeable = delete_option_if_exists!(options, :closeable, false)
  heading = delete_option_if_exists!(options, :heading, nil)

  classes = ["alert alert-#{context}"]
  block = delete_option_if_exists!(options, :block, false)
  classes << 'alert-block' if block
  set_or_prepend_option!(options, :class, classes.join(' '))

  (tag, options, nil, escape) do
    concat tb_icon_close_button(:data => {:dismiss => 'alert'}) if closeable
    concat (:h4, heading, {:class => 'alert-heading'}, true) if heading
    concat flash[key]
  end
end

#tb_clearfix(options = nil) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/tb-helpers/components.rb', line 104

def tb_clearfix(options = nil)
  options ||= {}
  tag = delete_option_if_exists!(options, :tag, :div)
  escape = delete_option_if_exists!(options, :escape, true)

  set_or_prepend_option!(options, :class, 'clearfix')
  (tag, '', options, escape)
end

#tb_icon_close(style, options = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/tb-helpers/components.rb', line 80

def tb_icon_close(style, options = nil)
  tag = case style
    when :link then :a
    when :button then :button
    else raise ArgumentError.new('invalid style value')
  end
  escape = delete_option_if_exists!(options, :escape, true)

  options[:class] ||= 'close'
  if tag == :link
    options[:href] ||= '#'
  end

  (tag, '&times;'.html_safe, options, escape)
end

#tb_icon_close_button(options = nil) ⇒ Object



100
101
102
# File 'lib/tb-helpers/components.rb', line 100

def tb_icon_close_button(options = nil)
  tb_icon_close(:button, options)
end


96
97
98
# File 'lib/tb-helpers/components.rb', line 96

def tb_icon_close_link(options = nil)
  tb_icon_close(:link, options)
end

#tb_progress_bar(progress, options = nil) ⇒ Object

progess bars



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tb-helpers/components.rb', line 30

def tb_progress_bar(progress, options = nil)
  options ||= {}
  context = delete_option_if_exists!(options, :context, nil)
  tag = delete_option_if_exists!(options, :tag, :div)
  escape = delete_option_if_exists!(options, :escape, true)

  progresses = progress.is_a?(Array) ? progress : [progress]
  contexts = context.is_a?(Array) ? context : [context]

  classes = ['progress']
  striped = delete_option_if_exists!(options, :striped, false)
  classes << 'progress-striped' if striped
  active = delete_option_if_exists!(options, :active, false)
  classes << 'active' if active
  set_or_prepend_option!(options, :class, classes.join(' '))

  (tag, options, nil, escape) do
    progresses.each_with_index do |progress, progress_idx|
      classes = ['bar']
      context = contexts[progress_idx]
      classes << "bar-#{context}" if context

      concat (tag, '', {:class => classes.join(' '), :style => "width: #{progress}%;"}, true)
    end
  end
end

#tb_well(content = nil, options = nil, &block) ⇒ Object

misc



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tb-helpers/components.rb', line 67

def tb_well(content = nil, options = nil, &block)
  content, options = content_or_options_with_block?(content, options, &block)
  tag = delete_option_if_exists!(options, :tag, :div)
  escape = delete_option_if_exists!(options, :escape, true)

  classes = ['well']
  size = delete_option_if_exists!(options, :size, false)
  classes << "well-#{size}" if size
  set_or_prepend_option!(options, :class, classes.join(' '))

  (tag, content, options, escape)
end