bootstrap_flash_messages 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # bootstrap_flash_messages
2
2
 
3
- version 0.0.4
3
+ version 0.0.5
4
4
  Robin Brouwer
5
5
  45north
6
6
 
@@ -22,6 +22,11 @@ And that's it!
22
22
 
23
23
  ## Changes
24
24
 
25
+ Version 0.0.5 changes (24/09/2012):
26
+
27
+ - Added HTML escape option for flash_messages helper (:html).
28
+ - Also added option to convert new-lines to br-tags (:convert_newlines).
29
+
25
30
  Version 0.0.4 changes (03/09/2012):
26
31
 
27
32
  - Namespaced Controllers can be accessed by nesting your locales.
@@ -122,6 +127,14 @@ Want a heading? Add `:heading`. The headings inside flash.en.yml are used for th
122
127
 
123
128
  <%= flash_messages(:close, :block, :heading) %>
124
129
 
130
+ Need to display HTML inside the flash messages? Use the `:html` option.
131
+
132
+ <%= flash_messages(:html) %>
133
+
134
+ It's also possible to convert new-lines (\n) into br-tags using the `:convert_newlines` option. This option also unescapes all other HTML, so use it with care.
135
+
136
+ <%= flash_messages(:convert_newlines) %>
137
+
125
138
  And that's it! Have fun. :)
126
139
 
127
140
  ## Interpolation
@@ -1,44 +1,44 @@
1
- module BootstrapFlashMessages
2
- module FlashMessages
3
- def redirect_to(options = {}, response_status_and_flash = {})
4
- messages = response_status_and_flash[:flash]
5
- if messages && (messages.is_a?(Symbol) || messages.is_a?(Array))
6
- flashes = {}
7
- locals = response_status_and_flash[:locals]
8
- if messages.is_a?(Array)
9
- messages.each do |key|
10
- flashes[key] = flash_messages(key, locals)
11
- end
12
- else
13
- flashes[messages] = flash_messages(messages, locals)
14
- end
15
- response_status_and_flash.delete(:locals)
16
- response_status_and_flash[:flash] = flashes
17
- end
18
- super(options, response_status_and_flash)
19
- end
20
-
21
- private
22
-
23
- def flash!(*args)
24
- options = args.extract_options!
25
- args.each do |key|
26
- flash[key] = flash_messages(key, options[:locals])
27
- end
28
- end
29
-
30
- def flash_now!(*args)
31
- options = args.extract_options!
32
- args.each do |key|
33
- flash.now[key] = flash_messages(key, options[:locals])
34
- end
35
- end
36
-
37
- def flash_messages(key, *args)
38
- i18n_key = "flash_messages.#{params[:controller]}.#{params[:action]}.#{key}"
39
- options = args.extract_options!
40
- options[:default] = i18n_key.to_sym
41
- I18n.t(i18n_key.gsub(/\//, "."), options)
42
- end
43
- end
44
- end
1
+ module BootstrapFlashMessages
2
+ module FlashMessages
3
+ def redirect_to(options = {}, response_status_and_flash = {})
4
+ messages = response_status_and_flash[:flash]
5
+ if messages && (messages.is_a?(Symbol) || messages.is_a?(Array))
6
+ flashes = {}
7
+ locals = response_status_and_flash[:locals]
8
+ if messages.is_a?(Array)
9
+ messages.each do |key|
10
+ flashes[key] = flash_messages(key, locals)
11
+ end
12
+ else
13
+ flashes[messages] = flash_messages(messages, locals)
14
+ end
15
+ response_status_and_flash.delete(:locals)
16
+ response_status_and_flash[:flash] = flashes
17
+ end
18
+ super(options, response_status_and_flash)
19
+ end
20
+
21
+ private
22
+
23
+ def flash!(*args)
24
+ options = args.extract_options!
25
+ args.each do |key|
26
+ flash[key] = flash_messages(key, options[:locals])
27
+ end
28
+ end
29
+
30
+ def flash_now!(*args)
31
+ options = args.extract_options!
32
+ args.each do |key|
33
+ flash.now[key] = flash_messages(key, options[:locals])
34
+ end
35
+ end
36
+
37
+ def flash_messages(key, *args)
38
+ i18n_key = "flash_messages.#{params[:controller]}.#{params[:action]}.#{key}"
39
+ options = args.extract_options!
40
+ options[:default] = i18n_key.to_sym
41
+ I18n.t(i18n_key.gsub(/\//, "."), options).html_safe
42
+ end
43
+ end
44
+ end
@@ -5,6 +5,8 @@ module BootstrapFlashMessages
5
5
  block = args.include?(:block)
6
6
  show_heading = args.include?(:heading)
7
7
  show_close = args.include?(:close)
8
+ unescape_html = args.include?(:html)
9
+ convert_newlines = args.include?(:convert_newlines)
8
10
 
9
11
  messages = []
10
12
  flash.each do |key, value|
@@ -18,8 +20,10 @@ module BootstrapFlashMessages
18
20
  close = link_to(raw("&times;"), "#", :class => "close", :data => { :dismiss => "alert" })
19
21
  end
20
22
 
23
+ value.gsub!("\n", "<br/>") if convert_newlines
24
+
21
25
  messages << content_tag(:div, :class => "alert alert-#{key} #{"alert-block" if block}") do
22
- close + heading + " " + value
26
+ close + heading + " " + (unescape_html || convert_newlines ? raw(value) : value)
23
27
  end
24
28
  end
25
29
  raw(messages.join)
@@ -1,3 +1,3 @@
1
1
  module BootstrapFlashMessages
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_flash_messages
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robin Brouwer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-03 00:00:00 +02:00
18
+ date: 2012-09-24 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21