Module: Shoehorn::Helpers::ButtonHelpers
- Defined in:
- lib/shoehorn/helpers/button_helpers.rb
Instance Method Summary collapse
-
#bootstrap_button(text, link, options = {}) ⇒ Object
Render a bootstrap button.
-
#bootstrap_dropdown(options = {}) {|elements| ... } ⇒ Object
Render a dropdown button.
-
#bootstrap_link_to(text, link, options = {}) ⇒ Object
Render a bootstrap link_to.
-
#bootstrap_link_to_if(condition, text, link, options = {}, &block) ⇒ Object
Render a bootstrap link_to_unless.
-
#bootstrap_link_to_unless(condition, text, link, options = {}, &block) ⇒ Object
Render a bootstrap link_to_unless.
Instance Method Details
#bootstrap_button(text, link, options = {}) ⇒ Object
Render a bootstrap button
NOTE: If you have to create a link to a resource#show you have to specify the full path as second param.
Example: to create an anchor to the user#show path you have to write:
bootstrap_button "Show", user_path(@user)
instead of:
bootstrap_button "Show", @user
Examples
"Show", user_path(@user)
t('commons.search'), user_path(@user)
'Search', search_path, type: 'primary', icon_name: 'search'
'Show details', user_path(@user), icon_name: 'user', size: 'large'
'Edit request', edit_request_path(@request), :type => 'primary', class: 'foo', id: 'bar'
'Show details', user_path(@user), disabled: true
40 41 42 43 44 45 46 |
# File 'lib/shoehorn/helpers/button_helpers.rb', line 40 def (text, link, = {}) Shoehorn::Components::Button.new( text, link, ).to_s end |
#bootstrap_dropdown(options = {}) {|elements| ... } ⇒ Object
Render a dropdown button
Examples
do |b|
b. "Actions', "#", type: 'primary'
b.bootstrap_link_to "Show", request_path(@request), icon_name: 'zoom-in'
b.bootstrap_link_to_if(can?(:reject, @request), t('.refuse'),
reject_request_path(@request), icon_name: 'remove',
html_options: { method: :put, data: { confirm: "Are you sure?" } }) { nil }
b.bootstrap_link_to_if(can?(:accept, @request), "Accept",
"#acceptModal_#{@request.id}", icon_name: 'ok',
html_options: { data: { toggle: "modal" } }) { nil }
b.link_to "Help", help_path
end
Returns HTML String for the dropdown
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/shoehorn/helpers/button_helpers.rb', line 67 def bootstrap_dropdown( = {}) # Elements will hold every call made to this block. Self is passed in so the # elements can be sent to it in order to be evaluated elements = Shoehorn::HelperCollection.new(self) yield elements Shoehorn::Components::Dropdown.new( elements, ).to_s end |
#bootstrap_link_to(text, link, options = {}) ⇒ Object
Render a bootstrap link_to.
They are a shortcut to bootstrap_button with bootstrap_class_prefix => nil . In this way they are rendered as normal links, without being styled.
85 86 87 88 89 90 91 92 |
# File 'lib/shoehorn/helpers/button_helpers.rb', line 85 def bootstrap_link_to(text, link, = {}) [:bootstrap_class_prefix] = nil Shoehorn::Components::Button.new( text, link, ).to_s end |
#bootstrap_link_to_if(condition, text, link, options = {}, &block) ⇒ Object
Render a bootstrap link_to_unless.
They are a shortcut to conditional bootstrap_button_link_to. In this way they are rendered as normal links, without being styled.
116 117 118 |
# File 'lib/shoehorn/helpers/button_helpers.rb', line 116 def bootstrap_link_to_if(condition, text, link, = {}, &block) bootstrap_link_to_unless !condition, text, link, , &block end |
#bootstrap_link_to_unless(condition, text, link, options = {}, &block) ⇒ Object
Render a bootstrap link_to_unless.
They are a shortcut to conditional bootstrap_button_link_to. In this way they are rendered as normal links, without being styled.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/shoehorn/helpers/button_helpers.rb', line 99 def bootstrap_link_to_unless(condition, text, link, = {}, &block) if condition if block_given? block.arity <= 1 ? capture(text, &block) : capture(text, link, , &block) else text end else bootstrap_link_to(text, link, ) end end |