Module: AnnouncementsHelper

Defined in:
lib/announcements/announcements_helper.rb

Instance Method Summary collapse

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, options = {}
  result = nil

  if announcement != nil && cookies["announcement_" + announcement.id.to_s] != "hidden"
    data_attribute = { :announcementid => announcement.id }
    if options[:format] == "bootstrap"
      text = options[:hide_message] || "x"
      div_class = options[:div_class] || "alert alert-warning"
      alert_heading = announcement.try(:heading) || options[:alert_heading] || "Warning!"

       = (:a, text, :class => "close", data: data_attribute)
       = (:h4, alert_heading, :class => "alert-heading")

      result = (:div,  +  + announcement.body.html_safe, class: div_class)
    else
      text = options[:hide_message] || "hide message"
      div_class = options[:div_class] || "info"

       = (:span, text, :class => "hide_announcement", data: data_attribute)

      result = (:div, announcement.body.html_safe + , class: div_class)
    end
  end

  result
end