module Bh::Helpers
Public Instance Methods
Displays a Bootstrap-styled alert message. @see getbootstrap.com/components/#alerts @return [String] the HTML to display a Bootstrap-styled alert message. @overload alert_box
(content, options = {})
@param [#to_s] content the content to display in the alert. @param [Hash] options the options for the alert box. Any option not listed below is passed as an HTML attribute to the alert’s `<div>`. @option options [Boolean] :dismissible (false) whether to display an '×' to the right of the box that can be clicked to dismiss the alert. @option options [#to_s] :context (:info) the contextual alternative to apply to the alert. Can be `:danger`, `:info`, `:success` or `:warning`. @option options [#to_s] :priority if set to one of the priority levels of Rails flash contents, determines the context of the alert box. Can be :alert or :notice. @example Display a dismissible alert box with a plain-text content. alert_box 'User updated successfully', dismissible: true
@overload alert_box
(options = {}, &block)
@param [Hash] options the options for the alert box (see above). @yieldreturn [#to_s] the content to display in the alert. @example Display a success alert box with an HTML content. alert_box context: :success do content_tag :strong, 'User updated successfully' end
# 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.dismissible_button alert_box.render_tag :div end
@see www.bootstrapcdn.com @return [String] the URL of the Bootstrap CSS file @param [Hash] options the options for which CSS file to retrieve. @option options [String] :version the version of Bootstrap. @option options [String] :scheme the URI scheme to use. @option options [Boolean] :minified whether to use the minified version.
# File lib/bh/helpers/cdn_helper.rb, line 11 def bootstrap_css(options = {}) Bh::Cdn.bootstrap options.merge(name: 'bootstrap', extension: 'css') end
@see www.bootstrapcdn.com @return [String] the URL of the Bootstrap JS file @param [Hash] options the options for which JS file to retrieve. @option options [String] :version the version of Bootstrap. @option options [String] :scheme the URI scheme to use. @option options [Boolean] :minified whether to use the minified version.
# File lib/bh/helpers/cdn_helper.rb, line 42 def bootstrap_js(options = {}) Bh::Cdn.bootstrap options.merge(name: 'bootstrap', extension: 'js') end
@see www.bootstrapcdn.com @return [String] the URL of the Bootstrap Theme CSS file @param [Hash] options the options for which CSS file to retrieve. @option options [String] :version the version of Bootstrap. @option options [String] :scheme the URI scheme to use. @option options [Boolean] :minified whether to use the minified version.
# File lib/bh/helpers/cdn_helper.rb, line 21 def bootstrap_theme_css(options = {}) Bh::Cdn.bootstrap options.merge(name: 'bootstrap-theme', extension: 'css') end
@see getbootstrap.com/components/#dropdowns @see getbootstrap.com/components/#btn-dropdowns @return [String] an HTML block to display a dropdown. @example A right-aligned dropdown with a links.
dropdown 'Menu', align: :right do content_tag :li, link_to('Home', '/') end
@param [#to_s] caption the caption for the dropdown button. @param [Hash] options the display options for the dropdown. @option options [Boolean] :groupable (true) if true, uses the “btn-group”
class rather than then "dropdown" class, so that multiple dropdown buttons can be aligned in the same row (as a group of buttons).
@option options [Boolean] :split (false) if true, creates a split button
that only toggles the dropdown when clicked on the rightmost part.
@option options [#to_s] :direction if set to :up, the dropdown appears
above the button, rather than below.
@option options [#to_s] :layout if set to ‘:block`, span the dropdown
button for the full width of the parent. Note that :groupable takes precedence, so it must be set to `false` to display a full-width button.
@option options [#to_s] :align if set to :right, the dropdown is aligned
to the right-end of the button, rather than to the left-end.
@option options [#to_s] :context (:default) the context for the button,
which determines its color.
@option options [#to_s] :size the size of the button. @yieldreturn [#to_s] the content of the dropdown.
# File lib/bh/helpers/dropdown_helper.rb, line 30 def dropdown(caption, options = {}, &block) dropdown = Bh::Dropdown.new self, nil, options, &block dropdown.extract! :id, :groupable, :direction, :align, :split, :context, :size, :layout, :button dropdown.extract_from :button, [:context, :size, :layout] dropdown.merge! button: {caption: 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
@see www.bootstrapcdn.com @return [String] the URL of the Font Awesome CSS file @param [Hash] options the options for which CSS file to retrieve. @option options [String] :version the version of Font Awesome. @option options [String] :scheme the URI scheme to use. @option options [Boolean] :minified whether to use the minified version. @see fontawesome.io/get-started/
# File lib/bh/helpers/cdn_helper.rb, line 32 def font_awesome_css(options = {}) Bh::Cdn.font_awesome options.merge(name: 'font-awesome', extension: 'css') end
Displays any of the 200 glyphicons available in Bootstrap. @deprecated Use {#icon} instead. @see getbootstrap.com/components/#glyphicons @return [String] the HTML to display a glyphicon. @param [#to_s] name the name of the icon to display, with either dashes
or underscores to separate multiple words.
@param [Hash] options the options to pass to the icon’s ‘<span>`. @example Display the “zoom-in” glyphicon
glyphicon :zoom_in
# File lib/bh/helpers/glyphicon_helper.rb, line 14 def glyphicon(name = nil, options = {}) icon name, options.merge(library: :glyphicons) end
Displays the collapsable portion of a Bootstrap-styled navbar. @see getbootstrap.com/components/#navbar @return [String] the HTML to display the collapsable portion of a
Bootstrap-styled navbar.
@overload horizontal(content, options = {})
@param [#to_s] content the collapsable content to display in the navbar. @param [Hash] options the options to pass to the wrapping `<div>`. Note that the `:id` option is ignored since the id must generated by the navbar in order to match with the target of the toggle button.
@overload horizontal(options = {}, &block)
@param [Hash] options the options to pass to the wrapping `<div>`. @yieldreturn [#to_s] the collapsable content to display in the navbar.
@example Display a navbar with two collapsable links.
navbar do horizontal do nav do link_to 'Home', '/' link_to 'Profile', '/profile' end end end
# File lib/bh/helpers/horizontal_helper.rb, line 26 def horizontal(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) horizontal = Bh::Base.new self, *args, &block horizontal.append_class! :'collapse navbar-collapse' horizontal.merge! id: navbar.id horizontal.render_tag :div end end
Displays a Bootstrap-styled vector icon. @see getbootstrap.com/components/#glyphicons @see fortawesome.github.io/Font-Awesome/examples/#bootstrap @return [String] the HTML to display a vector (font) icon. @param [#to_s] name the name of the icon to display, with either dashes
or underscores to separate multiple words.
@param [Hash] options the options for the icon tag. Any option not
listed below is passed as an HTML attribute to the icon’s `<span>`.
@option options [#to_s] :library (:glyphicons) the vector icon library
to use. Valid values are 'glyphicon', 'glyphicons' (for Glyphicons), 'font-awesome', 'font_awesome' and 'fa' (for Font Awesome).
@example Display the “fire” font awesome icon with a title
icon 'fire', library: :font_awesome, title: 'Hot'
# File lib/bh/helpers/icon_helper.rb, line 18 def icon(name = nil, options = {}) icon = Bh::Icon.new self, nil, options.merge(name: name) icon.extract! :library, :name icon.append_class! icon.library_class icon.append_class! icon.name_class icon.render_tag :span end
Overrides ‘link_to` to display a Bootstrap-styled link. Can only be used in Ruby frameworks that provide the `link_to` method. @see getbootstrap.com/components/#dropdowns @see getbootstrap.com/components/#nav @see getbootstrap.com/components/#navbar-brand-image @see getbootstrap.com/components/#navbar-links @see api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to @see www.rubydoc.info/github/padrino/padrino-framework/Padrino/Helpers/AssetTagHelpers#link_to-instance_method @return [String] the HTML to display a Bootstrap-styled link. @overload link_to
(caption, url, options = {})
@param [#to_s] caption the caption to display in the link. @param [#to_s] url the URL to link to. @param [Hash] options the options for the original `link_to` method. @example Display a plain-text link inside an alert-box. alert_box do link_to 'Check the terms and conditions', '/#terms' end
@overload button_to
(url, options = {}, &block)
@param [#to_s] url the URL to link to (see above). @param [Hash] options the options for the original `link_to` method. @yieldreturn [#to_s] the caption to display in the link. @example Display a link with HTML inside a dropdown. dropdown 'Menu' do link_to '/#terms' do content_tag :strong, 'Check the terms and conditions' end end
# 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
Displays a Bootstrap-styled modal. @see getbootstrap.com/javascript/#modals @return [String] the HTML to display a Bootstrap-styled modal. @overload modal(body, options = {})
@param [#to_s] body the content to display as the modal body. @param [Hash] options the options for the modal. Any option not listed below is ignored, except for `:id` which is passed as an HTML attribute to the modal’s `<div>`. @option options [#to_s] :title ('Modal') the title of the modal. @option options [#to_s] :body the content to display as the modal body. Using this option is equivalent to passing the body as an argument. @option options [#to_s] :size the size of the modal. Can be `:large` (alias `:lg`) or `:small` (alias `:sm`). @option options [Hash] :button the options for the toggle button. * :caption (#to_s) ('Modal') the caption of the toggle button. * :context (#to_s) (:default) the contextual alternative to apply to the toggle button. Can be `:danger`, `:info`, `:link`, `:primary`, `:success` or `:warning`. * :size (#to_s) the size of the toggle button. Can be `:extra_small` (alias `:xs`), `:large` (alias `:lg`) or `:small` (alias `:sm`). * :layout (#to_s) if set to `:block`, span the button for the full width of the parent. @example Display a simple modal toggled by a blue button. modal 'You clicked me!', title: 'Click me', button: {context: :info}
@overload modal(options = {}, &block)
@param [Hash] options the options for the modal (see above). @yieldreturn [#to_s] the content to display in the modal. @example Display a modal with HTML content. modal title: 'Click me' do content_tag :div, class: 'modal-body' do content_tag :em, 'You clicked me!' end end
# 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.button_context_class modal.append_class_to! :button, modal.button_size_class modal.merge! button: {caption: modal.caption} 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
Displays a Bootstrap-styled panel. @see getbootstrap.com/components/#panels @return [String] the HTML to display a Bootstrap-styled panel. @overload panel(body, options = {})
@param [#to_s] body the content to display as the panel body. @param [Hash] options the options for the panel. Any option not listed below is passed as an HTML attribute to the panel’s `<div>`. @option options [#to_s] :title the text to display as the panel title. @option options [#to_s] :heading the text to display as the panel heading. @option options [#to_s] :body the text to display as the panel body. Using this option is equivalent to passing the body as an argument. @option options [#to_s] :context (#to_s) (:default) the contextual alternative to apply to the panel heading and border. Can be `:danger`, `:info`, `:primary`, `:success` or `:warning`. @option options [#to_s] :tag (#to_s) (:div) the HTML tag to wrap the panel into. @example Display an informative panel with plain-text content. panel 'You accepted the Terms of service.', context: :success
@overload panel(options = {}, &block)
@param [Hash] options the options for the panel (see above). @yieldreturn [#to_s] the content to display in the panel. @example Display a panel with HTML content. panel title: 'Thanks' do content_tag :div, class: 'panel-body' do content_tag :em, 'ou accepted the Terms of service.' end end
# 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
Wraps a set of Bootstrap-styled panels in a row. @see getbootstrap.com/components/#panels @see getbootstrap.com/css/#grid @return [String] the HTML to display a row of Bootstrap-styled panels. @param [Hash] options the options for the row. Any option not
listed below is passed as an HTML attribute to the row’s `<div>`.
@option options [#to_s] :column_class the class to wrap each panel with.
Useful to specify a grid size for the column such as 'col-sm-4' to indicate how many columns of the row each panel should occupy.
@yieldreturn [#to_s] the panels to display in a row. @example Display a row of two panels with the same width.
panel_row column_class: 'col-sm-6' do panel 'Panel #1', context: :success panel 'Panel #2', context: :info end
# File lib/bh/helpers/panel_row_helper.rb, line 20 def panel_row(options = {}, &block) panel_row = Bh::PanelRow.new self, options, &block panel_row.extract! :column_class panel_row.append_class! :row panel_row.render_tag :div end
Displays one or more Bootstrap-styled progress bars. @see getbootstrap.com/components/#progress @return [String] the HTML to display Bootstrap-styled progress bars. @overload progress_bar
(bar_options = {}, container_options = {})
@param [Hash] bar_options the options to display a single progress bar. Any option not listed below is passed as an HTML attribute to the bar’s `<div>`. @option bar_options [Boolean, #to_s] :label (false) the label to display on top of the progress bar. If set to false, the label is hidden. If set to true, the label is generated from the percentage value. Any other provided value is used directly as the label. @option bar_options [Boolean] :striped (false) whether to display a striped version of the progress bar (rather than solid color). @option bar_options [Boolean] :animated (false) whether to display an animated version of the progress bar (rather than solid color). @option bar_options [#to_s] :context (:default) the contextual alternative to apply to the progress bar. Can be `:success`, `:info`, `:warning` or `:danger`. @param [Hash] container_options the options to pass as HTML attributes to the container’s `<div>`. @example Display a 30% warning progress bar. progress_bar percentage: 30, context: :warning
@overload progress_bar
(stacked_bars_options = [], container_options = {})
@param [Hash] stacked_bars_options an array of bar_options (see above). When an array is provided, a group of stacked progress bars is displayed, each one matching the corresponding bar options. @param [Hash] container_options the options to pass as HTML attributes to the container’s `<div>`. @example Display two stacked progress bars. progress_bar [{percentage: 30, context: :warning}, {percentage: 20}]
# File lib/bh/helpers/progress_bar_helper.rb, line 35 def progress_bar(args = nil, container_options = {}) progress_bars = Array.wrap(args).map do |options| progress_bar = Bh::ProgressBar.new self, nil, options progress_bar.extract! :percentage, :context, :striped, :animated, :label progress_bar.merge! progress_bar.aria_values progress_bar.append_class! :'progress-bar' progress_bar.append_class! progress_bar.context_class progress_bar.append_class! progress_bar.striped_class progress_bar.append_class! progress_bar.animated_class progress_bar.merge! progress_bar.values progress_bar.prepend_html! progress_bar.label progress_bar end container = Bh::Base.new self, progress_bars, container_options container.append_class! :progress container.render_tag :div end
Displays the non-collapsable portion of a Bootstrap-styled navbar. @see getbootstrap.com/components/#navbar @return [String] the HTML to display the non-collapsable portion of a
Bootstrap-styled navbar.
@overload vertical(content, options = {})
@param [#to_s] content the non-collapsable content to display in the navbar. @param [Hash] options the options to pass to the wrapping `<div>`.
@overload vertical(options = {}, &block)
@param [Hash] options the options to pass to the wrapping `<div>`. @yieldreturn [#to_s] the non-collapsable content to display in the navbar.
@example Display a navbar a non-collapsable links.
navbar do vertical do link_to 'Home', '/' end end
# File lib/bh/helpers/vertical_helper.rb, line 24 def vertical(*args, &block) if navbar = Bh::Stack.find(Bh::Navbar) vertical = Bh::Vertical.new self, *args, &block vertical.append_class! :'navbar-header' vertical.prepend_html! vertical.toggle_button(navbar.id) vertical.render_tag :div end end