Module: PureAdmin::ButtonHelper

Defined in:
app/helpers/pure_admin/button_helper.rb

Overview

Helper methods to render buttons.

Instance Method Summary collapse

Instance Method Details

#back_button(path = nil, options = {}) ⇒ String

Returns HTML for the back button.

Parameters:

  • path (String, Array) (defaults to: nil)

    the path for the back button

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

    all options that can be passed to link_to are respected here.

Returns:

  • (String)

    HTML for the back button.



26
27
28
29
# File 'app/helpers/pure_admin/button_helper.rb', line 26

def back_button(path = nil, options = {})
  options[:class] = merge_html_classes('pure-button', options[:class])
  link_to('Back', (path || :back), options)
end

#cancel_button(path = nil, options = {}) ⇒ String

Returns HTML for the cancel button.

Parameters:

  • path (String, Array) (defaults to: nil)

    the path for the back button

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

    all options that can be passed to link_to are respected here.

Returns:

  • (String)

    HTML for the cancel button.



35
36
37
38
# File 'app/helpers/pure_admin/button_helper.rb', line 35

def cancel_button(path = nil, options = {})
  options[:class] = merge_html_classes('pure-button', options[:class])
  link_to('<i class="fa fa-ban"></i> Cancel'.html_safe, (path || :back), options)
end

#delete_button(path, options = {}) ⇒ String

Returns HTML for the delete button.

Parameters:

  • path (String, Array)

    the path for the delete button

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

    all options that can be passed to link_to are respected here.

Returns:

  • (String)

    HTML for the delete button.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/pure_admin/button_helper.rb', line 46

def delete_button(path, options = {})
  options[:class] = merge_html_classes('pure-button button-red', options[:class])
  options[:rel] ||= :modal
  options[:modal] ||= :confirm
  options[:data] ||= {}
  options[:data][:modal_request_method] ||= :delete

  label = options.delete(:label) || 'Delete'
  icon = options.delete(:icon) || 'fa-trash-o'

  link_to("<i class='fa #{icon}'></i> #{label}".html_safe, path, options)
end

#edit_button(path, options = {}) ⇒ String

Returns HTML for the edit button.

Parameters:

  • path (String, Array)

    the path for the edit button

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

    all options that can be passed to link_to are respected here.

Returns:

  • (String)

    HTML for the edit button.



17
18
19
20
# File 'app/helpers/pure_admin/button_helper.rb', line 17

def edit_button(path, options = {})
  options[:class] = merge_html_classes('pure-button pure-button-primary', options[:class])
  link_to('<i class="fa fa-pencil"></i> Edit'.html_safe, path, options)
end

#save_button(options = {}) ⇒ String

Returns HTML for a save button.

Parameters:

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

    all options that can be passed to button_tag are respected here.

Returns:

  • (String)

    HTML for a save button.



7
8
9
10
11
# File 'app/helpers/pure_admin/button_helper.rb', line 7

def save_button(options = {})
  options[:class] = merge_html_classes('pure-button pure-button-primary', options[:class])
  options[:type] ||= :submit
  button_tag('<i class="fa fa-fw fa-check"></i> Save'.html_safe, options)
end