Module: Spurs::Flash::Helper
- Defined in:
- lib/spurs/flash/helper.rb
Constant Summary collapse
- @@flashes_container_class =
the default css class of the container for flash messages
"spurs_flash_messages"
- @@flashes_container_id_prefix =
the prefix of the id for containers for flash messages
"spurs_flash_messages_"
- @@default_messages_options =
{ :priority => 10, :builder => Spurs::Flash::Builder }
Class Method Summary collapse
- .default_messages_options ⇒ Object
- .flashes_container_class ⇒ Object
- .flashes_container_id_prefix ⇒ Object
Instance Method Summary collapse
- #logger ⇒ Object
- #spurs_alert(message, options = { }) ⇒ Object
- #spurs_alert_box(options = { }, &block) ⇒ Object
-
#spurs_flash_helper(options = { }) ⇒ Object
Generate HTML for flash messages = Examples.
Class Method Details
.default_messages_options ⇒ Object
28 29 30 |
# File 'lib/spurs/flash/helper.rb', line 28 def self. @@class. end |
.flashes_container_class ⇒ Object
8 9 10 |
# File 'lib/spurs/flash/helper.rb', line 8 def self.flashes_container_class @@flashes_container_class end |
.flashes_container_id_prefix ⇒ Object
17 18 19 |
# File 'lib/spurs/flash/helper.rb', line 17 def self.flashes_container_id_prefix @@flashes_container_id_prefix end |
Instance Method Details
#logger ⇒ Object
49 50 51 |
# File 'lib/spurs/flash/helper.rb', line 49 def logger Rails.logger end |
#spurs_alert(message, options = { }) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/spurs/flash/helper.rb', line 94 def spurs_alert(, ={ }) ## We shouldn't really need this if code is written properly if .is_a?(Array) raise "Message shouldn't be an array #{}" end #merge arguments with defaults = Spurs::Flash::default_args[:default].merge() # make sure the flavor is a symbol if [:flavor] then [:flavor] = [:flavor].to_s.singularize.parameterize.to_sym end # attempt to find the flavor in the list of known stuff if Spurs::Flash::flavors.find_index([:flavor]) == nil # didn't find it. logger.warn("Unknown flash flavor \"#{[:flavor]}\". Using a default instead") [:flavor] = Spurs::Flash::default_args[:default][:flavor] end if ![:title_icon] ico = Spurs::Flash::flavor_icons[[:flavor]] if ico then [:title_icon] = ico end end if ![:title] t = Spurs::Flash::flavor_titles[[:flavor]] if t then [:title] = t end end if ![:builder] raise "Null builder" end builder = [:builder].new begin flash_content = builder.build_alert(, ) rescue => e raise "Problem building flash message \nMessage: #{.to_json}\nOptions: #{.to_json}\nCause: #{e.}\n\t#{e.backtrace}" end return flash_content end |
#spurs_alert_box(options = { }, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spurs/flash/helper.rb', line 32 def spurs_alert_box(={ }, &block) extra_class = [:type] ? "alert-#{[:type]}" : "" alert_content = String.new if [:title] titl = [:title] if [:title_icon] titl = "<i class='icon-#{[:title_icon]}' style='margin-right: 6px'></i>".concat(titl) end alert_content.concat(content_tag(:h4, titl.html_safe, :class => 'alert-heading')) end if block block_content = capture(nil, &block) alert_content.concat(block_content) end content_tag(:div, alert_content.html_safe, :class => "alert alert-block #{extra_class}") end |
#spurs_flash_helper(options = { }) ⇒ Object
Generate HTML for flash messages
Examples
spurs_flash_helper
Options
:priority - a numeric value that determines where new (usually dynamic) flash messages are placed. Defaults to 10
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/spurs/flash/helper.rb', line 61 def spurs_flash_helper(={ }) = @@default_messages_options.merge() #Rails.logger.debug("FLASH >>#{flash.to_json}") = Hash.new() flash.each do |fl| (fl, ) end flash.clear #logger.debug("MESSAGE HASH >>#{message_hash.to_json}") #process the message hash now content = String.new .each do |k, v_arr| v_arr.each do |v| if v == nil logger.warn("Flash key with no value: #{k.to_s} in flash hash #{v_arr.to_json}") else content << spurs_alert(v, :flavor => k, :builder => [:builder], :title => k.to_s.singularize.tableize.to_sym.to_s.titlecase) end end end content_tag(:div, content.html_safe, :class => @@flashes_container_class, :id => "#{@@flashes_container_id_prefix}#{[:priority]}") end |