Module: ApplicationWidgetsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/application_widgets_helper.rb

Instance Method Summary collapse

Instance Method Details

#delete_button(path, html_options = nil, &block) ⇒ String #delete_button(resource, html_options = nil, &block) ⇒ String #delete_button(body, path, html_options = nil) ⇒ String #delete_button(body, resource, html_options = nil) ⇒ String

Create a +delete+ button.

Overloads:

  • #delete_button(path, html_options = nil, &block) ⇒ String

    Creates a +delete+ button, pointing to the given path and HTML options. This would yield a button with an icon, unless a block is provided.

  • #delete_button(resource, html_options = nil, &block) ⇒ String

    Creates a +delete+ button, pointing to the given resource. The URL is resolved using +url_for+. This would yield a button with an icon, unless a block is provided.

  • #delete_button(body, path, html_options = nil) ⇒ String

    Creates a +delete+ button, pointing to the given path and HTML options. This would create a button with the given body.

  • #delete_button(body, resource, html_options = nil) ⇒ String

    Creates a +delete+ button, pointing to the given resource. The URL is resolved using +url_for+. This would create a button with the given body.


80
81
82
83
84
85
86
87
88
# File 'app/helpers/application_widgets_helper.rb', line 80

def delete_button(name, options = nil, html_options = nil, &block)
  name, options, html_options = [nil, name, options] unless html_options
  block ||= proc { fa_icon 'trash' }

  html_options = html_options&.dup || {}
  html_options.reverse_merge!(method: :delete,
                              data: { confirm: t('helpers.buttons.delete_confirm_message') })
  resource_button(:delete, 'btn-danger', name || block, options, html_options)
end

#display_progress_bar(percentage, classes = ['progress-bar-info']) { ... } ⇒ String

Display a progress_bar with the given percentage and styling. The percentage is assumed to be a number ranging from 0-100. In addition, a block can be passed to add custom text.

ActionView::Helpers::CaptureHelper#capture is used to ensure the block is rendered in the original view_context, rather than within the view_context of the progress bar layout.

Yields:

  • The HTML text which will be passed to the partial as text to be shown in the bar.


100
101
102
103
104
105
# File 'app/helpers/application_widgets_helper.rb', line 100

def display_progress_bar(percentage, classes = ['progress-bar-info'], &block)
  text_in_block = capture(&block) if block_given?
  render partial: 'layouts/progress_bar', locals: { percentage: percentage,
                                                    progress_bar_classes: classes,
                                                    progress_bar_text: text_in_block }
end

#edit_button(path, html_options = nil, &block) ⇒ String #edit_button(resource, html_options = nil, &block) ⇒ String #edit_button(body, path, html_options = nil) ⇒ String #edit_button(body, resource, html_options = nil) ⇒ String

Create a +edit+ button.

Overloads:

  • #edit_button(path, html_options = nil, &block) ⇒ String

    Creates a +edit+ button, pointing to the given path and HTML options. This would yield a button with an icon, unless a block is provided.

  • #edit_button(resource, html_options = nil, &block) ⇒ String

    Creates a +edit+ button, pointing to the given resource. The URL is resolved using +url_for+. This would yield a button with an icon, unless a block is provided.

  • #edit_button(body, path, html_options = nil) ⇒ String

    Creates a +edit+ button, pointing to the given path and HTML options. This would create a button with the given body.

  • #edit_button(body, resource, html_options = nil) ⇒ String

    Creates a +edit+ button, pointing to the given resource. The URL is resolved using +url_for+. This would create a button with the given body.


52
53
54
55
56
57
# File 'app/helpers/application_widgets_helper.rb', line 52

def edit_button(name, options = nil, html_options = nil, &block)
  name, options, html_options = [nil, name, options] unless html_options
  options = [:edit] + [*options] unless options.is_a?(String)
  block ||= proc { fa_icon 'edit' }
  resource_button(:edit, 'btn-default', name || block, options, html_options&.dup)
end

#new_button(path, html_options = nil, &block) ⇒ String #new_button(resource, html_options = nil, &block) ⇒ String #new_button(body, path, html_options = nil) ⇒ String #new_button(body, resource, html_options = nil) ⇒ String

Create a +new+ button.

Overloads:

  • #new_button(path, html_options = nil, &block) ⇒ String

    Creates a +new+ button, pointing to the given path and HTML options. This would yield a button with an icon, unless a block is provided.

  • #new_button(resource, html_options = nil, &block) ⇒ String

    Creates a +new+ button, pointing to the given resource. The URL is resolved using +url_for+. This would yield a button with an icon, unless a block is provided.

  • #new_button(body, path, html_options = nil) ⇒ String

    Creates a +new+ button, pointing to the given path and HTML options. This would create a button with the given body.

  • #new_button(body, resource, html_options = nil) ⇒ String

    Creates a +new+ button, pointing to the given resource. The URL is resolved using +url_for+. This would create a button with the given body.


24
25
26
27
28
29
# File 'app/helpers/application_widgets_helper.rb', line 24

def new_button(name, options = nil, html_options = nil, &block)
  name, options, html_options = [nil, name, options] unless html_options
  options = [:new] + [*options] unless options.is_a?(String)
  block ||= proc { fa_icon 'file' }
  resource_button(:new, 'btn-primary', name || block, options, html_options&.dup)
end