Module: NdrUi::Bootstrap::ModalHelper
- Included in:
- NdrUi::BootstrapHelper
- Defined in:
- app/helpers/ndr_ui/bootstrap/modal_helper.rb
Overview
This provides bootstrap modal box helper methods
Constant Summary collapse
- MODAL_SIZES =
%w(sm lg).freeze
Instance Method Summary collapse
-
#bootstrap_modal_body_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal body.
-
#bootstrap_modal_box(title, *args, &block) ⇒ Object
Creates a Boostrap Modal box.
- #bootstrap_modal_button(label) ⇒ Object
-
#bootstrap_modal_dialog_tag(options = {}, &block) ⇒ Object
Creates a bootstrap modal dialog wrapper.
-
#bootstrap_modal_footer_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal footer.
-
#bootstrap_modal_header_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal header.
- #bootstrap_modal_save_buttons ⇒ Object
Instance Method Details
#bootstrap_modal_body_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal body.
Signatures
bootstrap_modal_body_tag(content)
bootstrap_modal_body_tag do
# content for modal body
end
Examples
<%= bootstrap_modal_body_tag do %>
Check it out!!
<% end %>
# => <div class="modal-body">Check it out!!</div>
83 84 85 86 87 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 83 def bootstrap_modal_body_tag(*args, &block) return bootstrap_modal_body_tag(capture(&block), *args) if block_given? content_tag(:div, args.first, class: 'modal-body') end |
#bootstrap_modal_box(title, *args, &block) ⇒ Object
Creates a Boostrap Modal box.
Signatures
bootstrap_modal_box(title, controls, = {})
bootstrap_modal_box(title, = {}) do
# controls
end
Options
-
:size
- Symbol of modal box size. Supported sizes are:sm
,:lg
. By default it will be unset (medium width).
Examples
<%= bootstrap_modal_box("New Pear", "Pear form") %>
# =>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">New Pear</h4>
</div>
<div class="modal-body">
Pear form
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Don't save
</button>
<input name="commit" class="btn-primary btn" data-disable-with="Saving…"
value="Save" type="submit" />
</div>
</div>
</div>
200 201 202 203 204 205 206 207 208 209 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 200 def bootstrap_modal_box(title, *args, &block) return bootstrap_modal_box(title, capture(&block), *args) if block_given? = args. bootstrap_modal_dialog_tag() do bootstrap_modal_header_tag(title) + bootstrap_modal_body_tag(args.first) + () end end |
#bootstrap_modal_button(label) ⇒ Object
218 219 220 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 218 def (label) (label, class: 'btn btn-default', "data-dismiss": 'modal') end |
#bootstrap_modal_dialog_tag(options = {}, &block) ⇒ Object
Creates a bootstrap modal dialog wrapper. the content is wrapped in a modal-content.
Signatures
bootstrap_modal_dialog_tag( = {}) do
# content for modal
end
Examples
<%= bootstrap_modal_tag size: 'lg', id: 'fruit' do %>
Check it out!!
<% end %>
# =>
<div id="fruit" class="modal modal-lg">
<div class="modal-content">Check it out!!</div>
</div>
24 25 26 27 28 29 30 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 24 def bootstrap_modal_dialog_tag( = {}, &block) return unless block_given? content_tag(:div, class: bootstrap_modal_classes(), role: 'document') do content_tag(:div, capture(&block), class: 'modal-content') end end |
#bootstrap_modal_footer_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal footer. If called with a content block, that block defines the non-readonly button(s). Alternatively, if called with a label first parameter, then a default button is created with that label. If no block or label is defined, then the default “Don’t save” and “Save” buttons are returned.
Signatures
( = {}) do
# content for modal footer
end
(, = {})
( = {})
Options
-
readonly: false
- This will set whether or not a close button will appear in the footer, regardless of the buttons defined in the label/block. Defaults to false.
Examples
<%= bootstrap_modal_footer_tag('Button text', readonly: true)
# =>
<div class="modal-footer">
<button name="button" type="submit" class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
<%= bootstrap_modal_footer_tag(readonly: false) do
button_tag('Non-readonly default', class: 'btn btn-default', "data-dismiss": 'modal') +
button_tag('Non-readonly primary', class: 'btn btn-primary', "data-dismiss": 'modal')
end %>
# =>
<div class="modal-footer">
<button name="button" type="submit" class="btn btn-default" data-dismiss="modal">
Non-readonly default
</button>
<button name="button" type="submit" class="btn btn-primary" data-dismiss="modal">
Non-readonly primary
</button>
</div>
<%= bootstrap_modal_footer_tag('Button text') %>
# =>
<div class="modal-footer">
<button name="button" type="submit" class="btn btn-default" data-dismiss="modal">
Button text
</button>
</div>
<%= bootstrap_modal_footer_tag %>
# =>
<div class="modal-footer">
<button name="button" type="submit" class="btn btn-default" data-dismiss="modal">
Don't save
</button>
<input type="submit" name="commit" value="Save" class="btn btn-primary"
disable_with="Saving…" data-disable-with="Save" />
</div>
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 148 def (*args, &block) = args. .stringify_keys! content_tag(:div, class: 'modal-footer') do if ['readonly'] ('Close') elsif block_given? capture(&block) elsif args.first (args.first) else end end end |
#bootstrap_modal_header_tag(*args, &block) ⇒ Object
Creates a simple bootstrap modal header.
Signatures
bootstrap_modal_header_tag(content, = {})
bootstrap_modal_header_tag( = {}) do
# content for modal header
end
Options
-
dismissible: false
- This will set whether or not a close X button will appear, allowing the modal box to be dismissed by the user. Defaults to false.
Examples
<%= bootstrap_modal_header_tag do %>
Check it out!!
<% end %>
# => <div class="modal-header">Check it out!!</div>
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 51 def bootstrap_modal_header_tag(*args, &block) return bootstrap_modal_header_tag(capture(&block), *args) if block_given? = args. .stringify_keys! # unless options.include?('dismissible') && !options['dismissible'] # options['dismissible'] = true # end heading = content_tag(:h4, args.first, class: 'modal-title') heading = (content_tag(:span, '×', "aria-hidden": 'true'), type: 'button', class: 'close', "data-dismiss": 'modal', "aria-label": 'Close') + heading if .delete('dismissible') content_tag(:div, heading, class: 'modal-header') end |
#bootstrap_modal_save_buttons ⇒ Object
211 212 213 214 215 216 |
# File 'app/helpers/ndr_ui/bootstrap/modal_helper.rb', line 211 def ("Don't save") + submit_tag('Save', class: 'btn btn-primary', disable_with: 'Saving…'.html_safe) end |