Module: Railsstrap::Helpers
- Included in:
- Form::BaseHelper, Form::FieldsetHelper
- Defined in:
- lib/railsstrap/helpers/cdn_helper.rb,
lib/railsstrap/helpers/nav_helper.rb,
lib/railsstrap/helpers/card_helper.rb,
lib/railsstrap/helpers/form_errors.rb,
lib/railsstrap/helpers/icon_helper.rb,
lib/railsstrap/helpers/aside_helper.rb,
lib/railsstrap/helpers/badge_helper.rb,
lib/railsstrap/helpers/flash_helper.rb,
lib/railsstrap/helpers/modal_helper.rb,
lib/railsstrap/helpers/button_helper.rb,
lib/railsstrap/helpers/navbar_helper.rb,
lib/railsstrap/helpers/link_to_helper.rb,
lib/railsstrap/helpers/dropdown_helper.rb,
lib/railsstrap/helpers/vertical_helper.rb,
lib/railsstrap/helpers/alert_box_helper.rb,
lib/railsstrap/helpers/button_to_helper.rb,
lib/railsstrap/helpers/glyphicon_helper.rb,
lib/railsstrap/helpers/card_group_helper.rb,
lib/railsstrap/helpers/horizontal_helper.rb,
lib/railsstrap/helpers/breadcrumbs_helper.rb,
lib/railsstrap/helpers/date_picker_helper.rb,
lib/railsstrap/helpers/button_group_helper.rb,
lib/railsstrap/helpers/progress_bar_helper.rb
Defined Under Namespace
Modules: DatePicker
Instance Method Summary collapse
-
#alert_box(*args, &block) ⇒ String
Displays a Bootstrap-styled alert message.
-
#aside(*args, &block) ⇒ String
Displays a Bootstrap-styled aside.
-
#badge(*args, &block) ⇒ String
Displays a Bootstrap-styled badge message.
-
#bootstrap_css(options = {version: '4.0.0'}) ⇒ String
The URL of the Bootstrap CSS file.
- #bootstrap_flash(options = {}) ⇒ Object
-
#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_group(caption, options = {}) ⇒ String
Displays a Bootstrap-styled button group or toolbar.
-
#button_to(*args, &block) ⇒ String
Overrides
button_to
to display a Bootstrap-styled button. -
#card(*args, &block) ⇒ String
Displays a Bootstrap-styled card.
-
#card_group(options = {}, &block) ⇒ String
Wraps a set of Bootstrap-styled cards in a row.
-
#cdn(options = {}) ⇒ String
The URL of the library from cdnjs.com.
-
#dropdown(caption, options = {}, &block) ⇒ String
An HTML block to display a dropdown.
-
#errors_for(object, options = {}, &block) ⇒ String
An HTML block to display a dropdown.
-
#font_awesome_css(options = {}) ⇒ String
The URL of the Font Awesome CSS file.
-
#font_awesome_js(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.
-
#jquery_js(options = {}) ⇒ String
The URL of the jQuery JS file.
-
#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.
-
#popper_js(options = {}) ⇒ String
The URL of the Popper JS file.
-
#progress_bar(args = nil, container_options = {}) ⇒ String
Displays one or more Bootstrap-styled progress bars.
-
#render_breadcrumbs(divider = '/', options = {}, &block) ⇒ Object
TODO: make divider optional.
-
#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 39 |
# File 'lib/railsstrap/helpers/alert_box_helper.rb', line 29 def alert_box(*args, &block) alert_box = Railsstrap::AlertBox.new(self, *args, &block) alert_box.extract! :variant, :priority, :dismissible, :dismiss, :size alert_box.append_class! :alert alert_box.append_class! alert_box.size_class alert_box.append_class! alert_box.variant_class alert_box.merge! role: :alert alert_box.prepend_html! alert_box. alert_box.render_tag :div end |
#aside(body, options = {}) ⇒ String #aside(options = {}, &block) ⇒ String
Displays a Bootstrap-styled aside. Asides inherit from Aside, but are pinned to the left or right of the screen.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/railsstrap/helpers/aside_helper.rb', line 40 def aside(*args, &block) aside = Railsstrap::Aside.new self, *args, &block aside.extract! :button, :size, :body, :title, :id aside.extract_from :button, [:variant, :size, :layout, :caption] aside.append_class_to! :button, :btn aside.append_class_to! :button, aside. aside.append_class_to! :button, aside. aside.merge! button: {caption: aside.caption} aside.append_class_to! :div, :aside-dialog' aside.append_class_to! :div, aside.dialog_size_class aside.merge! div: {title: aside.title, id: aside.id} aside.render_partial 'aside' end |
#badge(content, options = {}) ⇒ String #badge(options = {}, &block) ⇒ String
Displays a Bootstrap-styled badge message.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/railsstrap/helpers/badge_helper.rb', line 29 def badge(*args, &block) badge = Railsstrap::Badge.new(self, *args, &block) badge.extract! :variant, :priority, :dismissible badge.append_class! :badge badge.append_class! badge.variant_class badge.append_class! badge.pill_class badge.merge! role: :badge badge.prepend_html! badge. badge.render_tag end |
#bootstrap_css(options = {version: '4.0.0'}) ⇒ String
Returns the URL of the Bootstrap CSS file
31 32 33 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 31 def bootstrap_css( = {version: '4.0.0'}) Railsstrap::Cdn.bootstrap_css end |
#bootstrap_flash(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/railsstrap/helpers/flash_helper.rb', line 5 def bootstrap_flash( = {}) = [] = content_tag(:button, raw('×'), :type => 'button', :class => 'close', 'data-dismiss' => 'alert') flash.each do |type, | default_opts = { show_close: true, type: :info, container_tag: :div, animation: 'animate fade show' } opts = default_opts.merge() # Skip empty messages, e.g. for devise messages set to nothing in a locale file. next if .blank? type = type.to_sym type = :info if type == :notice type = :warning if type == :alert type = :danger if type == :error next unless Railsstrap::Classes::Base.variant_types.include?(type) Array().each do |msg| text = content_tag(opts[:container_tag], (opts[:show_close] ? : '') + msg.html_safe, :class => "alert #{opts[:animation]} alert-#{type} #{opts[:class]}") << text if msg end end .join("\n").html_safe end |
#bootstrap_js(options = {}) ⇒ String
Returns the URL of the Bootstrap JS file
74 75 76 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 74 def bootstrap_js( = {}) Railsstrap::Cdn.bootstrap_js() end |
#bootstrap_theme_css(options = {}) ⇒ String
Returns the URL of the Bootstrap Theme CSS file
41 42 43 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 41 def bootstrap_theme_css( = {}) Railsstrap::Cdn.bootstrap_theme 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/railsstrap/helpers/button_helper.rb', line 29 def (*args, &block) = Railsstrap::Button.new(self, *args, &block) .extract! :variant, :size, :layout .append_class! :btn .append_class! .variant_class .append_class! .size_class .append_class! .layout_class .content_tag :button end |
#button_group(caption, options = {}) ⇒ String
Displays a Bootstrap-styled button group or toolbar.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/railsstrap/helpers/button_group_helper.rb', line 22 def (*args, &block) btn_group = Railsstrap::ButtonGroup.new(self, *args, &block) btn_group.extract! :group, :toolbar, :role, :size, :vertical btn_group.append_class! 'btn-group' btn_group.append_class! btn_group.vertical_class btn_group.append_class! btn_group.size_class btn_group.append_class! btn_group. btn_group.merge! btn_group.role_name btn_group.content_tag :div 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
:variant
, :size
or :layout
option,
otherwise calls the original method.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/railsstrap/helpers/button_to_helper.rb', line 40 def (*args, &block) = Railsstrap::ButtonTo.new self, *args, &block if .extract! :variant, :size, :layout . :btn . .variant_class . .size_class . .layout_class .append_form_class! 'navbar-form' if Railsstrap::Stack.find(Railsstrap::Navbar) end html = if block_given? && .accepts_block? super .url, .attributes, &-> { .content } else super .content, .url, .attributes, &nil end if Railsstrap::Stack.find(Railsstrap::Nav) container = Railsstrap::Base.new(self) { html } container.render_tag :li else html end end |
#card(body, options = {}) ⇒ String #card(options = {}, &block) ⇒ String
Displays a Bootstrap-styled card.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/railsstrap/helpers/card_helper.rb', line 36 def card(*args, &block) card = Railsstrap::Card.new self, *args, &block card.extract! :body, :variant, :title, :header, :tag, :img card.append_class! :card card.append_class! card.variant_class card.append_class! card.text_variant_class card.prepend_html! card.image_cap card.merge_html! card.body card.prepend_html! card.header if card_row = Railsstrap::Stack.find(Railsstrap::CardGroup) container = Railsstrap::Base.new(self) { card.content_tag card.tag } container.append_class! card_row.layout container.render_tag :div else card.render_tag card.tag end end |
#card_group(options = {}, &block) ⇒ String
Wraps a set of Bootstrap-styled cards in a row.
20 21 22 23 24 25 26 |
# File 'lib/railsstrap/helpers/card_group_helper.rb', line 20 def card_group( = {}, &block) card_group = Railsstrap::CardGroup.new self, , &block card_group.extract! :layout card_group.append_class! card_group.layout card_group.render_tag :div end |
#cdn(options = {}) ⇒ String
Returns The URL of the library from cdnjs.com
88 89 90 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 88 def cdn( = {}) content_tag :script, nil, src: Railsstrap::Cdn.cdn_asset() 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/railsstrap/helpers/dropdown_helper.rb', line 30 def dropdown(caption, = {}, &block) dropdown = Railsstrap::Dropdown.new self, nil, , &block dropdown.extract! :id, :groupable, :direction, :align, :split, :variant, :size, :layout, :button dropdown.extract_from :button, [:variant, :size, :layout] dropdown.merge! button: {caption: caption, id: dropdown.id} dropdown.append_class_to! :button, :btn dropdown.append_class_to! :button, dropdown.variant_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 |
#errors_for(object, options = {}, &block) ⇒ String
Returns an HTML block to display a dropdown.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/railsstrap/helpers/form_errors.rb', line 10 def errors_for(object, = {}, &block) if object.errors.any? opts = { body: content_tag(:ol) { object.errors..each do |msg| concat content_tag(:li, msg) end }, variant: :danger, text_variant: 'text-white', header: "#{pluralize(object.errors.count, 'error')} prohibited this #{object.class.name.downcase} from being saved:" }.merge card = Railsstrap::Classes::Card.new(self, opts, &block) card.extract! :body, :variant, :text_variant, :title, :header, :tag, :img card.append_class! :card card.append_class! card.variant_class card.append_class! card.text_variant_class card.prepend_html! card.image_cap card.merge_html! card.body card.prepend_html! card.header card.render_tag card.tag end end |
#font_awesome_css(options = {}) ⇒ String
Returns the URL of the Font Awesome CSS file
52 53 54 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 52 def font_awesome_css( = {}) Railsstrap::Cdn.font_awesome end |
#font_awesome_js(options = {}) ⇒ String
Returns the URL of the Font Awesome CSS file
62 63 64 65 66 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 62 def font_awesome_js( = {}) [:version] = [:version].nil? ? '5.0.6' : [:version] [:scheme] = [:scheme].nil? ? 'https' : [:version].to_s "#{[:scheme]}://use.fontawesome.com/releases/v#{[:version]}/js/all.js" end |
#glyphicon(name = nil, options) ⇒ String
Use #icon instead.
Displays any of the 200 glyphicons available in Bootstrap.
14 15 16 17 18 19 |
# File 'lib/railsstrap/helpers/glyphicon_helper.rb', line 14 def glyphicon(name = nil, ) if .is_a?(Symbol || String) return icon , library: :glyphicons end 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 34 |
# File 'lib/railsstrap/helpers/horizontal_helper.rb', line 26 def horizontal(*args, &block) = Railsstrap::Stack.find(Railsstrap::Navbar) if horizontal = Railsstrap::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.
17 18 19 20 21 22 23 24 |
# File 'lib/railsstrap/helpers/icon_helper.rb', line 17 def icon(name = nil, = {}) icon = Railsstrap::Icon.new self, nil, .merge(name: name) icon.extract! :library, :name, :tag icon.append_class! icon.library_class icon.append_class! icon.name_class icon.render_tag icon.tag end |
#jquery_js(options = {}) ⇒ String
Returns the URL of the jQuery JS file
11 12 13 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 11 def jquery_js( = {}) Railsstrap::Cdn.jquery_js .merge(name: 'jquery', extension: 'js') 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 58 59 |
# File 'lib/railsstrap/helpers/link_to_helper.rb', line 37 def link_to(*args, &block) link_to = Railsstrap::LinkTo.new self, *args, &block link_to.append_class! :alert-link' if Railsstrap::Stack.find(Railsstrap::AlertBox) link_to.append_class! :navbar-brand' if Railsstrap::Stack.find(Railsstrap::Vertical) link_to.append_class! :nav-link' if Railsstrap::Stack.find(Railsstrap::Nav) link_to.merge! role: :menuitem if Railsstrap::Stack.find(Railsstrap::Dropdown) link_to.merge! tabindex: -1 if Railsstrap::Stack.find(Railsstrap::Dropdown) html = super link_to.content, link_to.url, link_to.attributes, &nil if Railsstrap::Stack.find(Railsstrap::Dropdown) container = Railsstrap::Base.new(self) {html} container.merge! role: :presentation container.render_tag :li elsif Railsstrap::Stack.find(Railsstrap::Nav) container = Railsstrap::Base.new(self) {html} container.append_class! :active if link_to.current_page? container.append_class! 'nav-item' 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/railsstrap/helpers/modal_helper.rb', line 38 def modal(*args, &block) modal = Railsstrap::Modal.new self, *args, &block modal.extract! :button, :size, :body, :title, :id, :dismissible, :dismiss modal.extract_from :button, [:variant, :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.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 |
#nav(options = {}, &block) ⇒ String
Displays a Bootstrap-styled nav.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/railsstrap/helpers/nav_helper.rb', line 20 def nav( = {}, &block) nav = Railsstrap::Nav.new(self, , &block) nav.extract! :as, :layout nav.append_class! :nav nav.append_class! nav.style_class nav.append_class! nav.layout_class nav.merge! role: :navigation nav.render_tag :nav end |
#navbar(options = {}, &block) ⇒ String
Displays a Bootstrap-styled navbar.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/railsstrap/helpers/navbar_helper.rb', line 32 def ( = {}, &block) = Railsstrap::Navbar.new(self, , &block) .extract! :variant, :text_variant, :position, :fluid, :id .append_class_to! :navigation, :navbar .append_class_to! :navigation, .variant_class .append_class_to! :navigation, 'navbar-expand-lg' .append_class_to! :navigation, .text_variant_class .append_class_to! :navigation, .position_class .append_class_to! :div, .layout_class .render_partial 'navbar' end |
#popper_js(options = {}) ⇒ String
Returns the URL of the Popper JS file
21 22 23 |
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 21 def popper_js( = {}) Railsstrap::Cdn.popper_js .merge(name: 'popper', extension: 'js') 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/railsstrap/helpers/progress_bar_helper.rb', line 35 def (args = nil, = {}) = Array.wrap(args).map do || = Railsstrap::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 = Railsstrap::Base.new self, , container.append_class! :progress container.render_tag :div end |
#render_breadcrumbs(divider = '/', options = {}, &block) ⇒ Object
TODO: make divider optional
4 5 6 7 8 9 10 11 12 |
# File 'lib/railsstrap/helpers/breadcrumbs_helper.rb', line 4 def (divider = '/', ={}, &block) { :class => '', :item_class => '', :divider_class => '', :active_class => 'active' }.merge() content = render :partial => 'railsstrap/breadcrumbs', :layout => false, :locals => { :divider => divider, options: } if block_given? capture(content, &block) else content end 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 32 |
# File 'lib/railsstrap/helpers/vertical_helper.rb', line 24 def vertical(*args, &block) = Railsstrap::Stack.find(Railsstrap::Navbar) if vertical = Railsstrap::Vertical.new self, *args, &block vertical.append_class! :navbar-header' vertical.prepend_html! vertical.(.id) vertical.render_tag :div end end |