Module: BootstrapHelper
- Defined in:
- app/helpers/bootstrap_helper.rb
Defined Under Namespace
Classes: TabBuilder
Instance Method Summary collapse
-
#bootstrap_btn_group(data = nil, &block) ⇒ Object
- Render a bootstrap button group data
-
The data content in the button group.
-
#bootstrap_dropdown_button(content, opts = {}) ⇒ Object
Render a bootstrap dropdown button.
-
#bootstrap_dropdown_menu(menu, cls = nil) ⇒ Object
Render a dropdown menu <li> markup in the bootstrap nav bar It will yield to a block that will output the menu items as html <li> tag.
-
#bootstrap_fav_links ⇒ Object
Render standard fav link icons for different devices.
- #bootstrap_form_fields(form, model, &block) ⇒ Object
-
#bootstrap_modal(options) ⇒ Object
Render a bootstrap modal panel.
-
#bootstrap_navbar(opts = {}, &block) ⇒ Object
Render a standard fixed-top bootstrap navbar It will yield to a block that will output nav menus as <li> markup.
-
#bootstrap_sidebar(opts = {}) ⇒ Object
Render a standard bootstrap sidebar panel with nav-stacked, nav-pills content.
-
#bootstrap_tab_pane(opts = {}) {|tab_builder| ... } ⇒ Object
Render a bootstrap tab pane Example code: <tt> bootstrap_tabs(tab_pos: “tabs-top”) do |t| t.tab “Tab1”, :id=>“id_of_tab1” do …
Instance Method Details
#bootstrap_btn_group(data = nil, &block) ⇒ Object
Render a bootstrap button group
- data
-
The data content in the button group. If it is an emuratable object, this method
will yield the block with each item in the collection.
89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/bootstrap_helper.rb', line 89 def bootstrap_btn_group data=nil, &block content_tag(:div, :class=>"btn-group") do if data.respond_to? :each data.each(&block) else yield data end end end |
#bootstrap_dropdown_button(content, opts = {}) ⇒ Object
Render a bootstrap dropdown button. The yielded block should render each dropdown item as a <li>
- content
-
The html content on the button
- opts
-
The dropdown button class, default is “btn”
77 78 79 80 81 82 83 |
# File 'app/helpers/bootstrap_helper.rb', line 77 def content, opts={} btn_class = (opts||{}).delete(:class) || "btn" content_tag(:div, :class=>"btn-group") do concat link_to(%{#{content} #{content_tag :span, "", :class=>"caret"}}.html_safe, "#", :class=>"#{btn_class} dropdown-toggle", :"data-toggle"=>"dropdown") concat content_tag(:ul, :class=>"dropdown-menu"){yield if block_given?} end end |
#bootstrap_dropdown_menu(menu, cls = nil) ⇒ Object
Render a dropdown menu <li> markup in the bootstrap nav bar It will yield to a block that will output the menu items as html <li> tag
- menu
-
The text on the menu
64 65 66 67 68 69 70 |
# File 'app/helpers/bootstrap_helper.rb', line 64 def , cls=nil opts = {:class=>["dropdown",cls].compact.join(" ")} content_tag(:li, opts) do concat link_to(%{#{} #{content_tag :b, "", :class=>"caret"}}.html_safe, "#", :class=>"dropdow-toggle", :"data-toggle"=>"dropdown") concat content_tag(:ul, :class=>"dropdown-menu"){yield} end end |
#bootstrap_fav_links ⇒ Object
Render standard fav link icons for different devices. It normally embeded in the <header>
102 103 104 |
# File 'app/helpers/bootstrap_helper.rb', line 102 def bootstrap_fav_links render "components/bootstrap/fav_links" end |
#bootstrap_form_fields(form, model, &block) ⇒ Object
16 17 18 |
# File 'app/helpers/bootstrap_helper.rb', line 16 def bootstrap_form_fields form, model, &block BootstrapFormBuilder.render_items(form, model, self, &block) end |
#bootstrap_modal(options) ⇒ Object
Render a bootstrap modal panel. It will yield to a block that should ouput the modal-body content
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/bootstrap_helper.rb', line 113 def bootstrap_modal id = .delete(:id) remote_path = .delete(:remote_path) title=.delete(:title) || "Title" actions = .delete(:actions) || [link_to("Cancel","#", :class=>"btn ", :"data-dismiss"=>"modal", :"aria-hidden"=>"true")] cls = .delete(:class) || "" = {:class=>"modal hide fade #{cls}"} [:id] = id if id.present? [:"data-remote-path"] = remote_path if remote_path.present? content_tag(:div, ) do concat(content_tag(:div, :class=>"modal-header"){ concat content_tag(:button,"×".html_safe, :type=>"button", :class=>"close", :"data-dismiss"=>"modal", :"aria-hidden"=>"true") concat content_tag(:h3, title) }) concat(content_tag(:div, :class=>"modal-body"){yield if block_given?}) concat content_tag(:div, actions.join("\n").html_safe, :class=>"modal-footer") end end |
#bootstrap_navbar(opts = {}, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/bootstrap_helper.rb', line 41 def opts={}, &block brand = opts.delete :brand || "" right = opts.delete :right || "" content_tag(:div, :class=>"navbar navbar-fixed-top") do content_tag(:div, :class=>"navbar-inner") do content_tag(:div, :class=>"container-fluid") do concat(nav_collapse.html_safe) concat(link_to brand.html_safe, "#", :class=>"brand") nav = content_tag(:div, :class=>"container-fluid nav-collapse") do concat(content_tag(:ul, :class=>"nav", &block)) concat(content_tag(:ul, right, :class=>"nav pull-right")) end concat(nav) end end end end |
#bootstrap_sidebar(opts = {}) ⇒ Object
Render a standard bootstrap sidebar panel with nav-stacked, nav-pills content
- opts
-
Options that will be passed to the yieled block
23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/bootstrap_helper.rb', line 23 def opts={} content_tag(:div, :class=>"section sidebar-nav") do nav_class = opts.delete(:nav_class) || "nav-pills nav-stacked" content_tag(:ul, :class=>"nav #{nav_class}") do header = opts.delete(:header) concat(content_tag :li, header.html_safe, :class=>"nav-header") if header.present? yield(opts) if block_given? end end end |
#bootstrap_tab_pane(opts = {}) {|tab_builder| ... } ⇒ Object
Render a bootstrap tab pane Example code: <tt>
bootstrap_tabs(tab_pos: "tabs-top") do |t|
t.tab "Tab1", :id=>"id_of_tab1" do
...
end
t.tab "Tab2", :id=>"id_of_tab2" do
...
end
end
</tt>
Parameters for the tab panel
- opts
-
The bootstrap class name for the tab position, like “tab-top”. Default value is “tab-top”
Parameters for each tab
- name
-
The tab name
- opts
-
The tab id, default value is the tab name
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/helpers/bootstrap_helper.rb', line 156 def bootstrap_tab_pane opts={} tab_builder = TabBuilder.new yield(tab_builder) if block_given? tab_pos = opts.delete(:tab_pos) || "tabs-top" = tab_builder.tabs.collect do |item| opts = item[:opts] || {} name = item[:name] id = opts.delete(:id) || name {:id=>id, :link=>link_to(name, "##{id}", :"data-toggle"=>"tab"), :content_proc=>item[:proc], :opts=>opts} end content_tag :div, :class=>"tabbable #{tab_pos}" do concat(content_tag(:ul, :class=>"nav nav-tabs"){ .each_with_index do |item, index| cls = "active" if index==0 concat content_tag(:li, item[:link], :class=>cls) end }) concat(content_tag(:div, :class=>"tab-content"){ .each_with_index do |item, index| opts = {:id=>item[:id], :class=>"tab-pane #{'active' if index==0}"}.merge(item[:opts]) concat(content_tag(:div, opts){ proc = item[:content_proc] proc.call if proc }) end }) end end |