Module: TbHelpers::Components
- Defined in:
- lib/tb-helpers/components.rb
Instance Method Summary collapse
-
#tb_alert_flash(key, options = nil, tag = :div, escape = true) ⇒ Object
alerts.
- #tb_clearfix(options = nil) ⇒ Object
- #tb_icon_close(style, options = nil) ⇒ Object
- #tb_icon_close_button(options = nil) ⇒ Object
- #tb_icon_close_link(options = nil) ⇒ Object
-
#tb_progress_bar(progress, options = nil) ⇒ Object
progess bars.
-
#tb_well(content = nil, options = nil, &block) ⇒ Object
misc.
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, = nil, tag = :div, escape = true) return nil if flash[key].blank? ||= {} context = delete_option_if_exists!(, :context, key) closeable = delete_option_if_exists!(, :closeable, false) heading = delete_option_if_exists!(, :heading, nil) classes = ["alert alert-#{context}"] block = delete_option_if_exists!(, :block, false) classes << 'alert-block' if block set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape) do concat (:data => {:dismiss => 'alert'}) if closeable concat content_tag(: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( = nil) ||= {} tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) set_or_prepend_option!(, :class, 'clearfix') content_tag(tag, '', , 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, = 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!(, :escape, true) [:class] ||= 'close' if tag == :link [:href] ||= '#' end content_tag(tag, '×'.html_safe, , escape) end |
#tb_icon_close_button(options = nil) ⇒ Object
100 101 102 |
# File 'lib/tb-helpers/components.rb', line 100 def ( = nil) tb_icon_close(:button, ) end |
#tb_icon_close_link(options = nil) ⇒ Object
96 97 98 |
# File 'lib/tb-helpers/components.rb', line 96 def tb_icon_close_link( = nil) tb_icon_close(:link, ) 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 (progress, = nil) ||= {} context = delete_option_if_exists!(, :context, nil) tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) progresses = progress.is_a?(Array) ? progress : [progress] contexts = context.is_a?(Array) ? context : [context] classes = ['progress'] striped = delete_option_if_exists!(, :striped, false) classes << 'progress-striped' if striped active = delete_option_if_exists!(, :active, false) classes << 'active' if active set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape) do progresses.each_with_index do |progress, progress_idx| classes = ['bar'] context = contexts[progress_idx] classes << "bar-#{context}" if context concat content_tag(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, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) classes = ['well'] size = delete_option_if_exists!(, :size, false) classes << "well-#{size}" if size set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |