Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper for button_to #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/sweet-alert2-rails/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ module ViewHelpers
def link_to(*args, &block)
html_options = args[block_given? ? 1 : 2] || {}

if options_has_confirm?(html_options)
html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) ||
html_options[:data].delete(:confirm)
end

super *args, &block
end

def button_to(*args, &block)
html_options = args[block_given? ? 1 : 2] || {}

if options_has_confirm?(html_options)
html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) ||
html_options[:data].delete(:confirm)
Expand All @@ -19,15 +30,19 @@ def submit_tag(value = 'Save changes', options = {})
super value, options
end

def button_tag(*args, &block)
html_options = args[block_given? ? 0 : 1] || {}
def button_tag(content_or_options = nil, options = nil, &block)
if content_or_options.is_a? Hash
html_options = content_or_options
else
html_options = options || {}
end

if options_has_confirm?(html_options)
html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) ||
html_options[:data].delete(:confirm)
end

super *args, &block
super content_or_options, options, &block
end

protected
Expand Down