Module: Bh::Helpers
- Included in:
- Form::BaseHelper, Form::FieldsetHelper
- Defined in:
- lib/bh/helpers/cdn_helper.rb,
lib/bh/helpers/nav_helper.rb,
lib/bh/helpers/icon_helper.rb,
lib/bh/helpers/modal_helper.rb,
lib/bh/helpers/panel_helper.rb,
lib/bh/helpers/button_helper.rb,
lib/bh/helpers/navbar_helper.rb,
lib/bh/helpers/link_to_helper.rb,
lib/bh/helpers/dropdown_helper.rb,
lib/bh/helpers/vertical_helper.rb,
lib/bh/helpers/alert_box_helper.rb,
lib/bh/helpers/button_to_helper.rb,
lib/bh/helpers/glyphicon_helper.rb,
lib/bh/helpers/panel_row_helper.rb,
lib/bh/helpers/horizontal_helper.rb,
lib/bh/helpers/progress_bar_helper.rb
Instance Method Summary collapse
-
#alert_box(*args, &block) ⇒ String
Displays a Bootstrap-styled alert message.
-
#bootstrap_css(options = {}) ⇒ String
The URL of the Bootstrap CSS file.
-
#bootstrap_js(options = {}) ⇒ String
The URL of the Bootstrap JS file.
-
#bootstrap_theme_css(options = {}) ⇒ String
The URL of the Bootstrap Theme CSS file.
-
#button(*args, &block) ⇒ String
Displays a Bootstrap-styled button.
-
#button_to(*args, &block) ⇒ String
Overrides
button_to
to display a Bootstrap-styled button. -
#dropdown(caption, options = {}, &block) ⇒ String
An HTML block to display a dropdown.
-
#font_awesome_css(options = {}) ⇒ String
The URL of the Font Awesome CSS file.
-
#glyphicon(name = nil, options = {}) ⇒ String
deprecated
Deprecated.
Use #icon instead.
-
#horizontal(*args, &block) ⇒ String
Displays the collapsable portion of a Bootstrap-styled navbar.
-
#icon(name = nil, options = {}) ⇒ String
Displays a Bootstrap-styled vector icon.
-
#link_to(*args, &block) ⇒ String
Overrides
link_to
to display a Bootstrap-styled link. -
#modal(*args, &block) ⇒ String
Displays a Bootstrap-styled modal.
-
#nav(options = {}, &block) ⇒ String
Displays a Bootstrap-styled nav.
-
#navbar(options = {}, &block) ⇒ String
Displays a Bootstrap-styled navbar.
-
#panel(*args, &block) ⇒ String
Displays a Bootstrap-styled panel.
-
#panel_row(options = {}, &block) ⇒ String
Wraps a set of Bootstrap-styled panels in a row.
-
#progress_bar(args = nil, container_options = {}) ⇒ String
Displays one or more Bootstrap-styled progress bars.
-
#vertical(*args, &block) ⇒ String
Displays the non-collapsable portion of a Bootstrap-styled navbar.
Instance Method Details
#alert_box(content, options = {}) ⇒ String #alert_box(options = {}, &block) ⇒ String
Displays a Bootstrap-styled alert message.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bh/helpers/alert_box_helper.rb', line 29 def alert_box(*args, &block) alert_box = Bh::AlertBox.new(self, *args, &block) alert_box.extract! :context, :priority, :dismissible alert_box.append_class! :alert alert_box.append_class! alert_box.context_class alert_box.merge! role: :alert alert_box.prepend_html! alert_box. alert_box.render_tag :div end |
#bootstrap_css(options = {}) ⇒ String
Returns the URL of the Bootstrap CSS file.
11 12 13 |
# File 'lib/bh/helpers/cdn_helper.rb', line 11 def bootstrap_css( = {}) Bh::Cdn.bootstrap .merge(name: 'bootstrap', extension: 'css') end |
#bootstrap_js(options = {}) ⇒ String
Returns the URL of the Bootstrap JS file.
42 43 44 |
# File 'lib/bh/helpers/cdn_helper.rb', line 42 def bootstrap_js( = {}) Bh::Cdn.bootstrap .merge(name: 'bootstrap', extension: 'js') end |
#bootstrap_theme_css(options = {}) ⇒ String
Returns the URL of the Bootstrap Theme CSS file.
21 22 23 |
# File 'lib/bh/helpers/cdn_helper.rb', line 21 def bootstrap_theme_css( = {}) Bh::Cdn.bootstrap .merge(name: 'bootstrap-theme', extension: 'css') end |
#button(caption, options = {}) ⇒ String #button(options = {}, &block) ⇒ String
Displays a Bootstrap-styled button.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bh/helpers/button_helper.rb', line 29 def (*args, &block) = Bh::Button.new(self, *args, &block) .extract! :context, :size, :layout .append_class! :btn .append_class! .context_class .append_class! .size_class .append_class! .layout_class .render_tag :button end |
#button_to(caption, url, options = {}) ⇒ String #button_to(url, options = {}, &block) ⇒ String
Overrides button_to
to display a Bootstrap-styled button.
Can only be used in Ruby frameworks that provide the button_to
method.
Only overrides the original method if called with any of the :context
,
:size
or :layout
option, otherwise calls the original method.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bh/helpers/button_to_helper.rb', line 39 def (*args, &block) = Bh::ButtonTo.new self, *args, &block if .extract! :context, :size, :layout . :btn . .context_class . .size_class . .layout_class .append_form_class! 'navbar-form' if Bh::Stack.find(Bh::Navbar) end if block_given? && .accepts_block? super .url, .attributes, &-> { .content } else super .content, .url, .attributes, &nil end end |
#dropdown(caption, options = {}, &block) ⇒ String
Returns an HTML block to display a dropdown.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bh/helpers/dropdown_helper.rb', line 30 def dropdown(, = {}, &block) dropdown = Bh::Dropdown.new self, nil, , &block dropdown.extract! :id, :groupable, :direction, :align, :split, :context, :size, :layout, :button dropdown.extract_from :button, [:context, :size, :layout] dropdown.merge! button: {caption: , id: dropdown.id} dropdown.append_class_to! :button, :btn dropdown.append_class_to! :button, dropdown.context_class dropdown.append_class_to! :button, dropdown.size_class dropdown.append_class_to! :button, dropdown.layout_class dropdown.append_class_to! :div, dropdown.groupable_class dropdown.append_class_to! :div, dropdown.direction_class dropdown.append_class_to! :ul, :'dropdown-menu' dropdown.append_class_to! :ul, dropdown.align_class dropdown.render_partial dropdown.partial end |
#font_awesome_css(options = {}) ⇒ String
Returns the URL of the Font Awesome CSS file.
32 33 34 |
# File 'lib/bh/helpers/cdn_helper.rb', line 32 def font_awesome_css( = {}) Bh::Cdn.font_awesome .merge(name: 'font-awesome', extension: 'css') end |
#glyphicon(name = nil, options = {}) ⇒ String
Use #icon instead.
Displays any of the 200 glyphicons available in Bootstrap.
14 15 16 |
# File 'lib/bh/helpers/glyphicon_helper.rb', line 14 def glyphicon(name = nil, = {}) icon name, .merge(library: :glyphicons) end |
#horizontal(content, options = {}) ⇒ String #horizontal(options = {}, &block) ⇒ String
Displays the collapsable portion of a Bootstrap-styled navbar.
26 27 28 29 30 31 32 33 |
# File 'lib/bh/helpers/horizontal_helper.rb', line 26 def horizontal(*args, &block) if = Bh::Stack.find(Bh::Navbar) horizontal = Bh::Base.new self, *args, &block horizontal.append_class! :'collapse navbar-collapse' horizontal.merge! id: .id horizontal.render_tag :div end end |
#icon(name = nil, options = {}) ⇒ String
Displays a Bootstrap-styled vector icon.
18 19 20 21 22 23 24 25 |
# File 'lib/bh/helpers/icon_helper.rb', line 18 def icon(name = nil, = {}) icon = Bh::Icon.new self, nil, .merge(name: name) icon.extract! :library, :name icon.append_class! icon.library_class icon.append_class! icon.name_class icon.render_tag :span end |
#link_to(caption, url, options = {}) ⇒ String #button_to(url, options = {}, &block) ⇒ String
Overrides link_to
to display a Bootstrap-styled link.
Can only be used in Ruby frameworks that provide the link_to
method.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bh/helpers/link_to_helper.rb', line 37 def link_to(*args, &block) link_to = Bh::LinkTo.new self, *args, &block link_to.append_class! :'alert-link' if Bh::Stack.find(Bh::AlertBox) link_to.append_class! :'navbar-brand' if Bh::Stack.find(Bh::Vertical) link_to.merge! role: :menuitem if Bh::Stack.find(Bh::Dropdown) link_to.merge! tabindex: -1 if Bh::Stack.find(Bh::Dropdown) html = super link_to.content, link_to.url, link_to.attributes, &nil if Bh::Stack.find(Bh::Dropdown) container = Bh::Base.new(self) { html } container.merge! role: :presentation container.render_tag :li elsif Bh::Stack.find(Bh::Nav) container = Bh::Base.new(self) { html } container.append_class! :active if link_to.current_page? container.render_tag :li else html end end |
#modal(body, options = {}) ⇒ String #modal(options = {}, &block) ⇒ String
Displays a Bootstrap-styled modal.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bh/helpers/modal_helper.rb', line 38 def modal(*args, &block) modal = Bh::Modal.new self, *args, &block modal.extract! :button, :size, :body, :title, :id modal.extract_from :button, [:context, :size, :layout, :caption] modal.append_class_to! :button, :btn modal.append_class_to! :button, modal. modal.append_class_to! :button, modal. modal.merge! button: {caption: modal.} modal.append_class_to! :div, :'modal-dialog' modal.append_class_to! :div, modal.dialog_size_class modal.merge! div: {title: modal.title, id: modal.id} modal.render_partial 'modal' end |
#nav(options = {}, &block) ⇒ String
Displays a Bootstrap-styled nav.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bh/helpers/nav_helper.rb', line 20 def nav( = {}, &block) nav = Bh::Nav.new(self, , &block) nav.extract! :as, :layout nav.append_class! :nav if Bh::Stack.find(Bh::Navbar) nav.append_class! :'navbar-nav' else nav.merge! role: :tablist nav.append_class! nav.style_class nav.append_class! nav.layout_class end nav.render_tag :ul end |
#navbar(options = {}, &block) ⇒ String
Displays a Bootstrap-styled navbar.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bh/helpers/navbar_helper.rb', line 35 def ( = {}, &block) = Bh::Navbar.new(self, , &block) .extract! :inverted, :position, :padding, :fluid, :id .append_class_to! :navigation, :navbar .append_class_to! :navigation, .style_class .append_class_to! :navigation, .position_class .append_class_to! :div, .layout_class .prepend_html! .body_padding_style .render_partial 'navbar' end |
#panel(body, options = {}) ⇒ String #panel(options = {}, &block) ⇒ String
Displays a Bootstrap-styled panel.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bh/helpers/panel_helper.rb', line 35 def panel(*args, &block) panel = Bh::Panel.new self, *args, &block panel.extract! :body, :context, :title, :heading, :tag panel.append_class! :panel panel.append_class! panel.context_class panel.merge_html! panel.body panel.prepend_html! panel.heading if panel_row = Bh::Stack.find(Bh::PanelRow) container = Bh::Base.new(self) { panel.content_tag panel.tag } container.append_class! panel_row.column_class container.render_tag :div else panel.render_tag panel.tag end end |
#panel_row(options = {}, &block) ⇒ String
Wraps a set of Bootstrap-styled panels in a row.
20 21 22 23 24 25 26 |
# File 'lib/bh/helpers/panel_row_helper.rb', line 20 def panel_row( = {}, &block) panel_row = Bh::PanelRow.new self, , &block panel_row.extract! :column_class panel_row.append_class! :row panel_row.render_tag :div end |
#progress_bar(bar_options = {}, container_options = {}) ⇒ String #progress_bar(stacked_bars_options = [], container_options = {}) ⇒ String
Displays one or more Bootstrap-styled progress bars.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bh/helpers/progress_bar_helper.rb', line 35 def (args = nil, = {}) = Array.wrap(args).map do || = Bh::ProgressBar.new self, nil, .extract! :percentage, :context, :striped, :animated, :label .merge! .aria_values .append_class! :'progress-bar' .append_class! .context_class .append_class! .striped_class .append_class! .animated_class .merge! .values .prepend_html! .label end container = Bh::Base.new self, , container.append_class! :progress container.render_tag :div end |
#vertical(content, options = {}) ⇒ String #vertical(options = {}, &block) ⇒ String
Displays the non-collapsable portion of a Bootstrap-styled navbar.
24 25 26 27 28 29 30 31 |
# File 'lib/bh/helpers/vertical_helper.rb', line 24 def vertical(*args, &block) if = Bh::Stack.find(Bh::Navbar) vertical = Bh::Vertical.new self, *args, &block vertical.append_class! :'navbar-header' vertical.prepend_html! vertical.(.id) vertical.render_tag :div end end |