Module: TwitterBootstrap::Helpers

Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/twitter_bootstrap_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



6
7
8
# File 'lib/twitter_bootstrap_helpers.rb', line 6

def output_buffer
  @output_buffer
end

Instance Method Details

#generate_menu_item(item) ⇒ Object

generate_menu_item :divider

<li class='divider' />

generate_menu_item :link => ‘#’,

:title => 'Menu item',
:active => true,
:items => [
  {
    *some_options*
  }


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/twitter_bootstrap_helpers.rb', line 23

def generate_menu_item(item)

  return tag :li, :class => 'divider-vertical' if item == :divider

  html_options = {}

  li_class = item[:li_class] ? [item[:li_class]] : []
  li_class << :active if item[:active]
  li_class << :dropdown if item[:items]

  link_options = {}

  link_options[:class] = item[:link_class] ? [item[:link_class]] : []

  if item[:items]
    link_options[:class] << 'dropdown-toggle'
    link_options[:data] = { :toggle => :dropdown } 
  end

  li_class = li_class.blank? ? nil : { :class => li_class.join(' ') }

   :li, li_class, false do
    inner = link_to item[:title], item[:link], link_options

    inner << generate_menu_items( item[:items], 'dropdown-menu' ) if item[:items]
    inner
  end
end

#generate_menu_items(items, ul_class = :nav) ⇒ Object

generate_menu_items [

 {
   :link => '#',
   :title => 'Menu item'
 }
]


60
61
62
63
64
65
66
# File 'lib/twitter_bootstrap_helpers.rb', line 60

def generate_menu_items(items, ul_class=:nav)
  return '' unless items
  (:ul, :class => ul_class) do
    items = items.values if items.is_a? Hash
    items.map { |i| generate_menu_item(i) }.join.html_safe
  end
end