Module: AnnouncementsHelper
- Defined in:
- lib/announcements/announcements_helper.rb
Instance Method Summary collapse
-
#announce(announcement, options = {}) ⇒ Object
Outputs given announcement in HTML (with optional twitter bootstrap style).
Instance Method Details
#announce(announcement, options = {}) ⇒ Object
Outputs given announcement in HTML (with optional twitter bootstrap style).
Basic usage: <%= announce Announcement.newest %> Alt usage: <%= announce Announcement.newest, :format => “boostrap” %>
Options: div_class – name for a custom div class, which wraps the announcement text and hide message, default is “info” hide_message – clickable text which hides the announcement, default is “hide message” format – format announcement to use the twitter bootstrap Alert style, defaults to normals stylings. alert_heading – Adding an alert heading when used with the bootstrap option.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/announcements/announcements_helper.rb', line 13 def announce announcement, = {} result = nil if announcement != nil && ["announcement_" + announcement.id.to_s] != "hidden" data_attribute = { :announcementid => announcement.id } if [:format] == "bootstrap" text = [:hide_message] || "x" div_class = [:div_class] || "alert alert-warning" alert_heading = announcement.try(:heading) || [:alert_heading] || "Warning!" close_content_tag = content_tag(:a, text, :class => "close", data: data_attribute) alert_content_tag = content_tag(:h4, alert_heading, :class => "alert-heading") result = content_tag(:div, close_content_tag + alert_content_tag + announcement.body.html_safe, class: div_class) else text = [:hide_message] || "hide message" div_class = [:div_class] || "info" close_content_tag = content_tag(:span, text, :class => "hide_announcement", data: data_attribute) result = content_tag(:div, announcement.body.html_safe + close_content_tag, class: div_class) end end result end |