Class: TwitterBootstrap::ButtonGroupBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_bootstrap_helpers/button_group_builder.rb

Direct Known Subclasses

ButtonGroupWithTabsBuilder

Instance Method Summary collapse

Constructor Details

#initialize(id, view_context) ⇒ ButtonGroupBuilder

Returns a new instance of ButtonGroupBuilder.



8
9
10
11
12
# File 'lib/twitter_bootstrap_helpers/button_group_builder.rb', line 8

def initialize(id,view_context)
  @id = id
  @view_context = view_context
  @buttons = ""
end

Instance Method Details

#build(block) ⇒ Object



14
15
16
17
# File 'lib/twitter_bootstrap_helpers/button_group_builder.rb', line 14

def build(block)
  block.call(self)
  @view_context.(:div, @buttons.html_safe, class: 'btn-group',id: @id);
end

#button(label, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twitter_bootstrap_helpers/button_group_builder.rb', line 19

def button(label, options = {})
  button_class = ['btn']

  button_class << options[:class] if options[:class]
  button_class << 'active' if options[:active]

  button_class = button_class.join(' ')

  data = {toggle: 'button'}
  data[:target] = "##{options[:target]}" if options[:target]

  @buttons << @view_context.(:button, label, class: button_class, data: data)

  ""
end


35
36
37
38
39
40
# File 'lib/twitter_bootstrap_helpers/button_group_builder.rb', line 35

def dropdown_button(item_title,dropdown_menu)
  title = (item_title << ' ' << (:span, nil, class: 'caret')).html_safe
  link  = (:a, title, :href => '#', :class => 'btn btn-mini dropdown-toggle', 'data-toggle' => 'dropdown')

  @buttons << (link << dropdown_menu) 
end