class Bootstrap::ViewHelpers::Components::Modal
Attributes
centered[R]
dismiss[R]
fade[R]
show[R]
size[R]
title_text[R]
Public Instance Methods
body(body_options = {}, &block)
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 27 def body(body_options = {}, &block) Body.new(view, body_options, &block).to_html end
header(title_or_options = nil, header_options = {}, &block)
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 19 def header(title_or_options = nil, header_options = {}, &block) header_options = title_or_options || {} if block.present? title_or_options = nil if block.present? header_options[:title] ||= title_or_options || title_text header_options[:dismiss] ||= dismiss Header.new(view, header_options, &block).to_html end
to_html()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 11 def to_html content_tag(:div, modal_options) do content_tag(:div, dialog_options) do content_tag(:div, content_options) { content_to_html(&block) } end end end
Protected Instance Methods
content_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 57 def content_options { class: 'modal-content' } end
content_to_html() { |self| ... }
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 39 def content_to_html(&block) capture do concat(header) if title_text concat(body(&block)) if render_body? yield(self) if block.present? && !render_body? end end
dialog_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 51 def dialog_options class_name = "modal-dialog#{' modal-dialog-centered' if centered}" class_name << " modal-#{size}" if size.present? { class: class_name, role: 'document' } end
header_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 66 def header_options { tag: :h5, class: 'modal-title' } end
inject_class_name_to_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 74 def inject_class_name_to_options options[:class] = "#{options[:class]} modal#{fade}#{show}" options[:class].strip! end
modal_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 61 def modal_options defaults = { id: "modal_#{random_uid}", tabindex: -1, role: 'dialog' } defaults.merge(options) end
parse_html_options()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 79 def parse_html_options @centered = options.delete(:centered) @dismiss = options.delete(:dismiss) @fade = ' fade' if options[:fade].nil? || options.delete(:fade) @show = ' show' if options.delete(:show) @size = options.delete(:size) end
parse_options(options)
click to toggle source
Calls superclass method
Bootstrap::ViewHelpers::Component#parse_options
# File lib/bootstrap/view_helpers/components/modal.rb, line 87 def parse_options(options) super @title_text = options.delete(:title) parse_html_options inject_class_name_to_options end
random_uid()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 47 def random_uid SecureRandom.urlsafe_base64 end
render_body?()
click to toggle source
# File lib/bootstrap/view_helpers/components/modal.rb, line 70 def render_body? @render_body ||= options.delete(:body) end