Skip to content

Instantly share code, notes, and snippets.

@tlux
Created July 21, 2013 19:16
Show Gist options
  • Select an option

  • Save tlux/6049612 to your computer and use it in GitHub Desktop.

Select an option

Save tlux/6049612 to your computer and use it in GitHub Desktop.
Button Helper Module for Bootstrap Buttons
module ButtonHelper
def button_link_to(*args, &block)
extract_button_options!(args)
link_to *args, &block
end
def button_link_to_if(condition, *args, &block)
extract_button_options!(args)
link_to_if condition, *args, &block
end
def button_link_to_unless(condition, *args, &block)
extract_button_options!(args)
link_to_unless condition, *args, &block
end
private
def extract_button_options!(args)
options = args.extract_options!.dup
type = options.delete(:as)
other_type = options.delete(:type)
type ||= other_type
icon = options.delete(:icon)
size = options.delete(:size)
block_rendering = options.delete(:block)
css = options.delete(:class).to_s + " btn"
css << " btn-#{type}" if type
css << " btn-#{size}" if size
css << " btn-block" if block_rendering
options[:class] = css.strip
args << options
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment