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

Instance Method Details

#alert_box(content, options = {}) ⇒ String #alert_box(options = {}, &block) ⇒ String

Displays a Bootstrap-styled alert message.

Overloads:

  • #alert_box(content, options = {}) ⇒ String

    Examples:

    Display a dismissible alert box with a plain-text content.

    alert_box 'User updated successfully', dismissible: true

    Parameters:

    • content (#to_s)

      the content to display in the alert.

    • options (Hash) (defaults to: {})

      the options for the alert box. Any option not listed below is passed as an HTML attribute to the alert’s <div>.

    Options Hash (options):

    • :dismissible (Boolean) — default: false

      whether to display an '×' to the right of the box that can be clicked to dismiss the alert.

    • :variant (#to_s) — default: :info

      the variant alternative to apply to the alert. Can be :danger, :info, :success or :warning.

    • :priority (#to_s)

      if set to one of the priority levels of Rails flash contents, determines the variant of the alert box. Can be :alert or :notice.

  • #alert_box(options = {}, &block) ⇒ String

    Examples:

    Display a success alert box with an HTML content.

    alert_box variant: :success do
       :strong, 'User updated successfully'
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the alert box (see above).

    Yield Returns:

    • (#to_s)

      the content to display in the alert.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled alert message.

See Also:



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.dismissible_button
  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.

Overloads:

  • #aside(body, options = {}) ⇒ String

    Examples:

    Display a simple aside toggled by a blue button.

    aside 'You clicked me!', title: 'Click me', button: {variant: :info}

    Parameters:

    • body (#to_s)

      the content to display as the aside body.

    • options (Hash) (defaults to: {})

      the options for the aside. Any option not listed below is ignored, except for :id which is passed as an HTML attribute to the aside’s <div>.

    Options Hash (options):

    • :title (#to_s) — default: 'Aside'

      the title of the aside.

    • :body (#to_s)

      the content to display as the aside body. Using this option is equivalent to passing the body as an argument.

    • :size (#to_s)

      the size of the aside. Can be :large (alias :lg) or :small (alias :sm).

    • :button (Hash)

      the options for the toggle button. * :caption (#to_s) ('Aside') the caption of the toggle button. * :variant (#to_s) (:default) the variant 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.

  • #aside(options = {}, &block) ⇒ String

    Examples:

    Display a aside with HTML content.

    aside title: 'Click me' do
       :div, class: 'aside-body' do
         :em, 'You clicked me!'
      end
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the aside (see above).

    Yield Returns:

    • (#to_s)

      the content to display in the aside.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled aside.

See Also:



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.button_variant_class
  aside.append_class_to! :button, aside.button_size_class
  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.

Overloads:

  • #badge(content, options = {}) ⇒ String

    Examples:

    Display a dismissible badge with a plain-text content.

    badge 'User updated successfully', dismissible: true

    Parameters:

    • content (#to_s)

      the content to display in the badge.

    • options (Hash) (defaults to: {})

      the options for the badge. Any option not listed below is passed as an HTML attribute to the badge’s <div>.

    Options Hash (options):

    • :dismissible (Boolean) — default: false

      whether to display an '×' to the right of the box that can be clicked to dismiss the badge.

    • :variant (#to_s) — default: :info

      the variant alternative to apply to the badge. Can be :danger, :info, :success or :warning.

    • :priority (#to_s)

      if set to one of the priority levels of Rails flash contents, determines the variant of the badge. Can be :badge or :notice.

  • #badge(options = {}, &block) ⇒ String

    Examples:

    Display a success badge with an HTML content.

    badge variant: :success do
       :strong, 'User updated successfully'
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the badge (see above).

    Yield Returns:

    • (#to_s)

      the content to display in the badge.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled badge message.

See Also:



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.dismissible_button
  badge.render_tag
end

#bootstrap_css(options = {version: '4.0.0'}) ⇒ String

Returns the URL of the Bootstrap CSS file

Parameters:

  • options (Hash) (defaults to: {version: '4.0.0'})

    the options for which CSS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Bootstrap.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the Bootstrap CSS file

See Also:



31
32
33
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 31

def bootstrap_css(options = {version: '4.0.0'})
  Railsstrap::Cdn.bootstrap_css options
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(options = {})

  flash_messages = []
  close_button = (:button, raw('&times;'), :type => 'button', :class => 'close', 'data-dismiss' => 'alert')

  flash.each do |type, message|
    default_opts = {
      show_close: true,
      type: :info,
      container_tag: :div,
      animation: 'animate fade show'
    }
    opts = default_opts.merge(options)

    # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
    next if message.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(message).each do |msg|

      text = (opts[:container_tag],
                         (opts[:show_close] ? close_button : '') +
                           msg.html_safe, :class => "alert #{opts[:animation]} alert-#{type} #{opts[:class]}")
      flash_messages << text if msg
    end
  end
  flash_messages.join("\n").html_safe
end

#bootstrap_js(options = {}) ⇒ String

Returns the URL of the Bootstrap JS file

Parameters:

  • options (Hash) (defaults to: {})

    the options for which JS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Bootstrap.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the Bootstrap JS file

See Also:



74
75
76
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 74

def bootstrap_js(options = {})
  Railsstrap::Cdn.bootstrap_js(options)
end

#bootstrap_theme_css(options = {}) ⇒ String

Returns the URL of the Bootstrap Theme CSS file

Parameters:

  • options (Hash) (defaults to: {})

    the options for which CSS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Bootstrap.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the Bootstrap Theme CSS file

See Also:



41
42
43
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 41

def bootstrap_theme_css(options = {})
  Railsstrap::Cdn.bootstrap_theme options
end

#button(caption, options = {}) ⇒ String #button(options = {}, &block) ⇒ String

Displays a Bootstrap-styled button.

Overloads:

  • #button(caption, options = {}) ⇒ String

    Examples:

    Display a button styled as a link.

    button 'Click here', variant: :link

    Parameters:

    • caption (#to_s)

      the caption to display in the button.

    • options (Hash) (defaults to: {})

      the options for the button. Any option not listed below is passed as an HTML attribute to the <button> tag.

    Options Hash (options):

    • :variant (#to_s) — default: :default

      the variant alternative to apply to the button. Can be :danger, :info, :link, :primary, :success or :warning.

    • :size (#to_s)

      the size of the 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.

  • #button(options = {}, &block) ⇒ String

    Examples:

    Display a button with an HTML caption.

    button do
       :strong, 'Click here'
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the button (see above).

    Yield Returns:

    • (#to_s)

      the caption to display in the button.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled button.

See Also:



29
30
31
32
33
34
35
36
37
38
# File 'lib/railsstrap/helpers/button_helper.rb', line 29

def button(*args, &block)
  button = Railsstrap::Button.new(self, *args, &block)
  button.extract! :variant, :size, :layout

  button.append_class! :btn
  button.append_class! button.variant_class
  button.append_class! button.size_class
  button.append_class! button.layout_class
  button. :button
end

#button_group(caption, options = {}) ⇒ String

Displays a Bootstrap-styled button group or toolbar.

Examples:

Display a button group

button_group size: :lg, do
  button caption, options
  button caption, options
end

Parameters:

  • caption (#to_s)

    the buttons for the group

Options Hash (options):

  • :toolbar (#to_s)

    creates a div.btn-toolbar

  • :role (#to_s) — default: :group

    Sets the role attribute

  • :size (#to_s)

    the size of the button group. Specifying size here causes the inner buttons to match this size. Buttons cannot be different sizes inside a group.

  • :vertical (#to_s)

    orient the button group vertically.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled button.

See Also:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/railsstrap/helpers/button_group_helper.rb', line 22

def button_group(*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.toolbar_class
  btn_group.merge! btn_group.role_name
  btn_group. :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.

Overloads:

  • #button_to(caption, url, options = {}) ⇒ String

    Examples:

    Display a small button to submit to '/create_user'.

    button_to 'Create', '/create_user', size: :small

    Parameters:

    • caption (#to_s)

      the caption to display in the button.

    • url (#to_s)

      the URL to submit to.

    • options (Hash) (defaults to: {})

      the options for the button. Any option not listed below is passed to the original button_to method.

    Options Hash (options):

    • :variant (#to_s) — default: :default

      the variant alternative to apply to the button. Can be :danger, :info, :link, :primary, :success or :warning.

    • :size (#to_s)

      the size of the 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.

  • #button_to(url, options = {}, &block) ⇒ String

    Examples:

    Display a danger button with HTML content to delete a user.

    button_to '/user_destroy', variant: :danger do
       :strong, "Delete user"
    end

    Parameters:

    • url (#to_s)

      the URL to submit to (see above).

    • options (Hash) (defaults to: {})

      the options for the button (see above).

    Yield Returns:

    • (#to_s)

      the caption to display in the button.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled button.

See Also:



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 button_to(*args, &block)
  button_to = Railsstrap::ButtonTo.new self, *args, &block

  if button_to.extract! :variant, :size, :layout
    button_to.append_button_class! :btn
    button_to.append_button_class! button_to.variant_class
    button_to.append_button_class! button_to.size_class
    button_to.append_button_class! button_to.layout_class
    button_to.append_form_class! 'navbar-form' if Railsstrap::Stack.find(Railsstrap::Navbar)
  end

  html = if block_given? && button_to.accepts_block?
    super button_to.url, button_to.attributes, &-> { button_to.content }
  else
    super button_to.content, button_to.url, button_to.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.

Overloads:

  • #card(body, options = {}) ⇒ String

    Examples:

    Display an informative card with plain-text content.

    card 'You accepted the Terms of service.', variant: :success

    Parameters:

    • body (#to_s)

      the content to display as the card body.

    • options (Hash) (defaults to: {})

      the options for the card. Any option not listed below is passed as an HTML attribute to the card’s <div>.

    Options Hash (options):

    • :title (#to_s)

      the text to display as the card title.

    • :header (#to_s)

      the text to display as the card header.

    • :img (Object)

      the image used in the top of the card.

    • :body (#to_s)

      the text to display as the card body. Using this option is equivalent to passing the body as an argument.

    • :variant (#to_s) — default: #to_s

      (:default) the variant alternative to apply to the card header and border. Can be :danger, :info, :primary, :success or :warning.

    • :tag (#to_s) — default: #to_s

      (:div) the HTML tag to wrap the card into.

  • #card(options = {}, &block) ⇒ String

    Examples:

    Display a card with HTML content.

    card title: 'Thanks' do
       :div, class: 'card-body' do
         :em, 'ou accepted the Terms of service.'
      end
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the card (see above).

    Yield Returns:

    • (#to_s)

      the content to display in the card.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled card.

See Also:



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. 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.

Examples:

Display a row of two cards with the same width.

card_group layout: 'col-sm-6' do
  card 'Panel #1', context: :success
  card 'Panel #2', context: :info
end

Parameters:

  • options (Hash) (defaults to: {})

    the options for the row. Any option not listed below is passed as an HTML attribute to the row’s <div>.

Options Hash (options):

  • :layout (#to_s)

    the class to wrap each card with. Useful to specify a grid size for the column such as 'col-sm-4' to indicate how many columns of the row each card should occupy.

Yield Returns:

  • (#to_s)

    the cards to display in a row.

Returns:

  • (String)

    the HTML to display a row of Bootstrap-styled cards.

See Also:



20
21
22
23
24
25
26
# File 'lib/railsstrap/helpers/card_group_helper.rb', line 20

def card_group(options = {}, &block)
  card_group = Railsstrap::CardGroup.new self, options, &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

Parameters:

  • options (Hash) (defaults to: {})

    the options for which JS file to retrieve.

Options Hash (options):

  • :version (String)

    the semver of the file

  • :extension (String)

    .js or .css

  • :minified (Boolean)

    whether to use the minified version.

  • :library (String)

    the name of the library to retrieve

  • :scheme (String)

    http/https (no colon)

  • :path (String)

    @default 'ajax/libs' (no trailing slashes)

  • :host (String)

    'cdnjs.cloudflare.com'

Returns:

  • (String)

    The URL of the library from cdnjs.com

See Also:



88
89
90
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 88

def cdn(options = {})
   :script, nil, src: Railsstrap::Cdn.cdn_asset(options)
end

Returns an HTML block to display a dropdown.

Examples:

A right-aligned dropdown with a links.

dropdown 'Menu', align: :right do
   :li, link_to('Home', '/')
end

Parameters:

  • caption (#to_s)

    the caption for the dropdown button.

  • options (Hash) (defaults to: {})

    the display options for the dropdown.

Options Hash (options):

  • :groupable (Boolean) — default: 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).

  • :split (Boolean) — default: false

    if true, creates a split button that only toggles the dropdown when clicked on the rightmost part.

  • :direction (#to_s)

    if set to :up, the dropdown appears above the button, rather than below.

  • :layout (#to_s)

    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.

  • :align (#to_s)

    if set to :right, the dropdown is aligned to the right-end of the button, rather than to the left-end.

  • :variant (#to_s) — default: :default

    the variant for the button, which determines its color.

  • :size (#to_s)

    the size of the button.

Yield Returns:

  • (#to_s)

    the content of the dropdown.

Returns:

  • (String)

    an HTML block to display a dropdown.

See Also:



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, options = {}, &block)
  dropdown = Railsstrap::Dropdown.new self, nil, options, &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.

Examples:

errors_for(@widgets)

Returns:

  • (String)

    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, options = {}, &block)
  if object.errors.any?
    opts = {
      body: (:ol) {
        object.errors.full_messages.each do |msg|
          concat (: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 options
    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

Parameters:

  • options (Hash) (defaults to: {})

    the options for which CSS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Font Awesome.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the Font Awesome CSS file

See Also:



52
53
54
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 52

def font_awesome_css(options = {})
  Railsstrap::Cdn.font_awesome options
end

#font_awesome_js(options = {}) ⇒ String

Returns the URL of the Font Awesome CSS file

Parameters:

  • options (Hash) (defaults to: {})

    the options for which CSS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Font Awesome. 5.0+ is required.

  • :scheme (String)

    the URI scheme to use.

Returns:

  • (String)

    the URL of the Font Awesome CSS file

See Also:



62
63
64
65
66
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 62

def font_awesome_js(options = {})
  options[:version] = options[:version].nil? ? '5.0.6' : options[:version]
  options[:scheme] = options[:scheme].nil? ? 'https' : options[:version].to_s
  "#{options[:scheme]}://use.fontawesome.com/releases/v#{options[:version]}/js/all.js"
end

#glyphicon(name = nil, options) ⇒ String

Deprecated.

Use #icon instead.

Displays any of the 200 glyphicons available in Bootstrap.

Examples:

Display the “zoom-in” glyphicon

glyphicon :zoom_in

Parameters:

  • name (#to_s) (defaults to: nil)

    the name of the icon to display, with either dashes or underscores to separate multiple words.

  • options (Hash)

    the options to pass to the icon’s <span>.

Returns:

  • (String)

    the HTML to display a glyphicon.

See Also:



14
15
16
17
18
19
# File 'lib/railsstrap/helpers/glyphicon_helper.rb', line 14

def glyphicon(name = nil, options)
  if options.is_a?(Symbol || String)
    return icon options, library: :glyphicons
  end
  icon name, options.merge(library: :glyphicons)
end

#horizontal(content, options = {}) ⇒ String #horizontal(options = {}, &block) ⇒ String

Displays the collapsable portion of a Bootstrap-styled navbar.

Examples:

Display a navbar with two collapsable links.

navbar do
  horizontal do
    nav do
      link_to 'Home', '/'
      link_to 'Profile', '/profile'
    end
  end
end

Overloads:

  • #horizontal(content, options = {}) ⇒ String

    Parameters:

    • content (#to_s)

      the collapsable content to display in the navbar.

    • options (Hash) (defaults to: {})

      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.

  • #horizontal(options = {}, &block) ⇒ String

    Parameters:

    • options (Hash) (defaults to: {})

      the options to pass to the wrapping <div>.

    Yield Returns:

    • (#to_s)

      the collapsable content to display in the navbar.

Returns:

  • (String)

    the HTML to display the collapsable portion of a Bootstrap-styled navbar.

See Also:



26
27
28
29
30
31
32
33
34
# File 'lib/railsstrap/helpers/horizontal_helper.rb', line 26

def horizontal(*args, &block)
  navbar = Railsstrap::Stack.find(Railsstrap::Navbar)
  if navbar
    horizontal = Railsstrap::Base.new self, *args, &block
    horizontal.append_class! :collapse navbar-collapse'
    horizontal.merge! id: navbar.id
    horizontal.render_tag :div
  end
end

#icon(name = nil, options = {}) ⇒ String

Displays a Bootstrap-styled vector icon.

Examples:

Display the “fire” font awesome standard icon with a title

icon 'fire', library: :font_awesome, title: 'Hot'

Parameters:

  • name (#to_s) (defaults to: nil)

    the name of the icon to display, with either dashes or underscores to separate multiple words.

  • options (Hash) (defaults to: {})

    the options for the icon tag. Any option not listed below is passed as an HTML attribute to the icon’s <span>.

Options Hash (options):

  • :library (#to_s) — default: :glyphicons

    the vector icon library to use. Valid values are 'glyphicon', 'glyphicons' (for Glyphicons), 'far', 'fas' and 'fal' (for Font Awesome).

Returns:

  • (String)

    the HTML to display a vector (font) icon.

See Also:



17
18
19
20
21
22
23
24
# File 'lib/railsstrap/helpers/icon_helper.rb', line 17

def icon(name = nil, options = {})
  icon = Railsstrap::Icon.new self, nil, options.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

Parameters:

  • options (Hash) (defaults to: {})

    the options for which JS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of jQuery.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the jQuery JS file

See Also:



11
12
13
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 11

def jquery_js(options = {})
  Railsstrap::Cdn.jquery_js options.merge(name: 'jquery', extension: 'js')
end

Overrides link_to to display a Bootstrap-styled link. Can only be used in Ruby frameworks that provide the link_to method.

Overloads:

  • #link_to(caption, url, options = {}) ⇒ String

    Examples:

    Display a plain-text link inside an alert-box.

    alert_box do
      link_to 'Check the terms and conditions', '/#terms'
    end

    Parameters:

    • caption (#to_s)

      the caption to display in the link.

    • url (#to_s)

      the URL to link to.

    • options (Hash) (defaults to: {})

      the options for the original link_to method.

  • #button_to(url, options = {}, &block) ⇒ String

    Examples:

    Display a link with HTML inside a dropdown.

    dropdown 'Menu' do
      link_to '/#terms' do
         :strong, 'Check the terms and conditions'
      end
    end

    Parameters:

    • url (#to_s)

      the URL to link to (see above).

    • options (Hash) (defaults to: {})

      the options for the original link_to method.

    Yield Returns:

    • (#to_s)

      the caption to display in the link.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled link.

See Also:



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

Displays a Bootstrap-styled modal.

Overloads:

  • #modal(body, options = {}) ⇒ String

    Examples:

    Display a simple modal toggled by a blue button.

    modal 'You clicked me!', title: 'Click me', button: {context: :info}

    Parameters:

    • body (#to_s)

      the content to display as the modal body.

    • options (Hash) (defaults to: {})

      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>.

    Options Hash (options):

    • :title (#to_s) — default: 'Modal'

      the title of the modal.

    • :body (#to_s)

      the content to display as the modal body. Using this option is equivalent to passing the body as an argument.

    • :size (#to_s)

      the size of the modal. Can be :large (alias :lg) or :small (alias :sm).

    • :button (Hash)

      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.

  • #modal(options = {}, &block) ⇒ String

    Examples:

    Display a modal with HTML content.

    modal title: 'Click me' do
       :div, class: 'modal-body' do
         :em, 'You clicked me!'
      end
    end

    Parameters:

    • options (Hash) (defaults to: {})

      the options for the modal (see above).

    Yield Returns:

    • (#to_s)

      the content to display in the modal.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled modal.

See Also:



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.button_variant_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 nav.

Examples:

Display a pills-styled nav with a link.

nav as: :pills do
  link_to 'Home', '/'
end

Parameters:

  • options (Hash) (defaults to: {})

    the options for the nav. Any option not listed below is passed as an HTML attribute to the alert’s <ul>.

Options Hash (options):

  • the (#to_s)

    style of the nav. Can be :tabs or :pills.

  • :layout (#to_s)

    the layout of the nav. Can be :justified, :center, :right, :fill, or :stacked.

Yield Returns:

  • (#to_s)

    the content to display in the nav.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled nav.

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/railsstrap/helpers/nav_helper.rb', line 20

def nav(options = {}, &block)
  nav = Railsstrap::Nav.new(self, options, &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

Displays a Bootstrap-styled navbar.

Examples:

Display an inverted navbar with three links.

navbar inverted: true do
  vertical do
    image_tag('logo')
  end
  horizontal do
    nav do
      link_to 'Home', '/'
      link_to 'Profile', '/profile'
    end
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    the options for the navbar. Any option not listed below is ignored, except for :id which is passed as an HTML attribute to the navbar’s collapsable <div>.

Options Hash (options):

  • :fluid (Boolean) — default: false

    whether to use a fluid container to surround the navbar content.

  • :inverted (Boolean) — default: false

    whether to use an inverted palette of colors.

  • :position (#to_s)

    the position of the navbar. Can be :top (alias :fixed_top), :bottom (alias :fixed_bottom) or :static (alias :static_top).

Yield Returns:

  • (#to_s)

    the content to display in the navbar.

Returns:

  • (String)

    the HTML to display a Bootstrap-styled navbar.

See Also:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/railsstrap/helpers/navbar_helper.rb', line 32

def navbar(options = {}, &block)
  navbar = Railsstrap::Navbar.new(self, options, &block)
  navbar.extract! :variant, :text_variant, :position, :fluid, :id

  navbar.append_class_to! :navigation, :navbar
  navbar.append_class_to! :navigation, navbar.variant_class
  navbar.append_class_to! :navigation, 'navbar-expand-lg'
  navbar.append_class_to! :navigation, navbar.text_variant_class
  navbar.append_class_to! :navigation, navbar.position_class
  navbar.append_class_to! :div, navbar.layout_class

  navbar.render_partial 'navbar'
end

#popper_js(options = {}) ⇒ String

Returns the URL of the Popper JS file

Parameters:

  • options (Hash) (defaults to: {})

    the options for which JS file to retrieve.

Options Hash (options):

  • :version (String)

    the version of Popper.

  • :scheme (String)

    the URI scheme to use.

  • :minified (Boolean)

    whether to use the minified version.

Returns:

  • (String)

    the URL of the Popper JS file

See Also:



21
22
23
# File 'lib/railsstrap/helpers/cdn_helper.rb', line 21

def popper_js(options = {})
  Railsstrap::Cdn.popper_js options.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.

Overloads:

  • #progress_bar(bar_options = {}, container_options = {}) ⇒ String

    Examples:

    Display a 30% warning progress bar.

    progress_bar percentage: 30, context: :warning

    Parameters:

    • bar_options (Hash) (defaults to: {})

      the options to display a single progress bar. Any option not listed below is passed as an HTML attribute to the bar’s <div>.

    • container_options (Hash) (defaults to: {})

      the options to pass as HTML attributes to the container’s <div>.

    Options Hash (bar_options):

    • :label (Boolean, #to_s) — default: 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.

    • :striped (Boolean) — default: false

      whether to display a striped version of the progress bar (rather than solid color).

    • :animated (Boolean) — default: false

      whether to display an animated version of the progress bar (rather than solid color).

    • :context (#to_s) — default: :default

      the contextual alternative to apply to the progress bar. Can be :success, :info, :warning or :danger.

  • #progress_bar(stacked_bars_options = [], container_options = {}) ⇒ String

    Examples:

    Display two stacked progress bars.

    progress_bar [{percentage: 30, context: :warning}, {percentage: 20}]

    Parameters:

    • stacked_bars_options (Hash) (defaults to: [])

      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.

    • container_options (Hash) (defaults to: {})

      the options to pass as HTML attributes to the container’s <div>.

Returns:

  • (String)

    the HTML to display Bootstrap-styled progress bars.

See Also:



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 progress_bar(args = nil, container_options = {})
  progress_bars = Array.wrap(args).map do |options|
    progress_bar = Railsstrap::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 = Railsstrap::Base.new self, progress_bars, container_options
  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 render_breadcrumbs(divider = '/', options={}, &block)
  { :class => '', :item_class => '', :divider_class => '', :active_class => 'active' }.merge(options)
  content = render :partial => 'railsstrap/breadcrumbs', :layout => false, :locals => { :divider => divider, options: 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.

Examples:

Display a navbar a non-collapsable links.

navbar do
  vertical do
    link_to 'Home', '/'
  end
end

Overloads:

  • #vertical(content, options = {}) ⇒ String

    Parameters:

    • content (#to_s)

      the non-collapsable content to display in the navbar.

    • options (Hash) (defaults to: {})

      the options to pass to the wrapping <div>.

  • #vertical(options = {}, &block) ⇒ String

    Parameters:

    • options (Hash) (defaults to: {})

      the options to pass to the wrapping <div>.

    Yield Returns:

    • (#to_s)

      the non-collapsable content to display in the navbar.

Returns:

  • (String)

    the HTML to display the non-collapsable portion of a Bootstrap-styled navbar.

See Also:



24
25
26
27
28
29
30
31
32
# File 'lib/railsstrap/helpers/vertical_helper.rb', line 24

def vertical(*args, &block)
  navbar = Railsstrap::Stack.find(Railsstrap::Navbar)
  if navbar
    vertical = Railsstrap::Vertical.new self, *args, &block
    vertical.append_class! :navbar-header'
    vertical.prepend_html! vertical.toggle_button(navbar.id)
    vertical.render_tag :div
  end
end