class Bootstrap3Helper::Alert
The Alert
helper is meant to help you rapidly build Bootstrap Alert
components quickly and easily. The dissmiss button is optional.
@example Rendering a Bootstrap Alert
Component
in a view:
<code> <%= alert_helper :warning, dismissable: true do %> <% if @model.errors.present? %> <p>Some kind of error</p> <% end %> <% end %> <%= alert_helper(:success, dismissible: true) { "Successful save"} </code>
Public Class Methods
new(template, context_or_options = nil, opts = {}, &block)
click to toggle source
Used to generate Bootstrap alert components quickly.
@param [Class] template Template in which your are binding too. @param [NilClass|String|Symbol|Hash] Bootstrap class context, or options hash. @param [Hash] opts @option opts [String] :id The ID of the element @option opts [String] :class Custom class for the component. @return [Alert]
Calls superclass method
# File lib/bootstrap3_helper/alert.rb, line 26 def initialize(template, context_or_options = nil, opts = {}, &block) super(template) @context, args = parse_arguments(context_or_options, opts) @id = args.fetch(:id, nil) @class = args.fetch(:class, '') @dismissible = args.fetch(:dismissible, false) @content = block || proc { '' } end
Public Instance Methods
to_s()
click to toggle source
Used to render out the Alert
component.
@note Concat needs to be used to add the content of the button to the output
buffer. For some reason, if though the block returns a String, trying to add that string to the dismiss button string, returns with the dismiss button missing. Was forced to caoncat the button to the current output buffer in order to get it to persist after the block call.
@return [String]
# File lib/bootstrap3_helper/alert.rb, line 56 def to_s content_tag :div, id: @id, class: container_class do concat(@dismissible ? close_button : '') @content.call(self) end end
Private Instance Methods
container_class()
click to toggle source
Used to get the container classes.
@return [String]
# File lib/bootstrap3_helper/alert.rb, line 69 def container_class string = 'alert ' string += @context == 'default' ? 'alert-info' : "alert-#{@context}" string += " #{@class}" string end