HTML
end
def dropdown_list items, extra_css_class=nil, active=nil
wrap_with :ul, class: "dropdown-menu #{extra_css_class}", role: "menu" do
case items
when Array
items.map.with_index { |item, i| dropdown_list_item item, i, active }
when Hash
items.map { |key, item| dropdown_list_item item, key, active }
else
[items]
end.compact.join "\n"
end
end
def dropdown_list_item item, active_test, active
return unless item
"
#{item}
"
end
def separator
''
end
def split_button main_button, active_item
wrap_with :div, class: "btn-group btn-group-sm" do
[
main_button,
split_button_toggle,
dropdown_list(yield, nil, active_item)
]
end
end
def split_button_toggle
button_tag(situation: "primary",
class: "dropdown-toggle",
"data-toggle" => "dropdown",
"aria-haspopup" => "true",
"aria-expanded" => "false") do
'Toggle Dropdown'
end
end
def list_group content_or_options=nil, options={}
options = content_or_options if block_given?
content = block_given? ? yield : content_or_options
content = Array(content).map(&:to_s)
add_class options, "list-group"
options[:items] ||= {}
add_class options[:items], "list-group-item"
list_tag content, options
end
def list_tag content_or_options=nil, options={}
options = content_or_options if block_given?
content = block_given? ? yield : content_or_options
content = Array(content)
default_item_options = options.delete(:items) || {}
tag = options[:ordered] ? :ol : :ul
wrap_with tag, options do
content.map do |item|
i_content, i_opts = item
i_opts ||= default_item_options
wrap_with :li, i_content, i_opts
end
end
end
end