module Sweetify::SweetAlert
Public Instance Methods
Display an alert with a text and an optional title Default without an specific type
@param [String] text Body of the alert (gets automatically the title if no title is specified) @param [String] title Title of the alert @param [Hash] opts Optional Parameters
# File lib/sweetify/sweetalert.rb, line 9 def sweetalert(text, title = '', opts = {}) opts = { showConfirmButton: false, timer: 2000, allowOutsideClick: true, confirmButtonText: 'OK' }.merge(opts) opts[:text] = text opts[:title] = title if opts[:button] opts[:showConfirmButton] = true opts[:confirmButtonText] = opts[:button] if opts[:button].is_a?(String) opts.delete(:button) end if opts[:persistent] opts[:showConfirmButton] = true opts[:allowOutsideClick] = false opts[:timer] = nil opts[:confirmButtonText] = opts[:persistent] if opts[:persistent].is_a?(String) opts.delete(:persistent) end # sweetalert changes if Sweetify.sweetalert_library == 'sweetalert' opts[:icon] = opts.delete(:type) opts[:closeOnClickOutside] = opts.delete(:allowOutsideClick) if opts.delete(:showConfirmButton) opts[:button] = opts[:confirmButtonText] else opts[:button] = false end end flash_config(opts) end
Error Alert
@param [String] text Body of the alert (gets automatically the title if no title is specified) @param [String] title Title of the alert @param [Hash] opts Optional Parameters
# File lib/sweetify/sweetalert.rb, line 76 def sweetalert_error(text, title = '', opts = {}) opts[:type] = :error sweetalert(text, title, opts) end
Information Alert
@param [String] text Body of the alert (gets automatically the title if no title is specified) @param [String] title Title of the alert @param [Hash] opts Optional Parameters
# File lib/sweetify/sweetalert.rb, line 56 def sweetalert_info(text, title = '', opts = {}) opts[:type] = :info sweetalert(text, title, opts) end
Success Alert
@param [String] text Body of the alert (gets automatically the title if no title is specified) @param [String] title Title of the alert @param [Hash] opts Optional Parameters
# File lib/sweetify/sweetalert.rb, line 66 def sweetalert_success(text, title = '', opts = {}) opts[:type] = :success sweetalert(text, title, opts) end
Warning Alert
@param [String] text Body of the alert (gets automatically the title if no title is specified) @param [String] title Title of the alert @param [Hash] opts Optional Parameters
# File lib/sweetify/sweetalert.rb, line 86 def sweetalert_warning(text, title = '', opts = {}) opts[:type] = :warning sweetalert(text, title, opts) end
Private Instance Methods
Flash the configuration as json If no title is specified, use the text as the title
@param [Hash] opts @return [Void]
# File lib/sweetify/sweetalert.rb, line 98 def flash_config(opts) if opts[:title].blank? opts[:title] = opts[:text] opts.delete(:text) end flash[:sweetify] = opts.to_json end