flash_rails_messages 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/flash_rails_messages/base.rb +28 -20
- data/lib/flash_rails_messages/helper.rb +0 -5
- data/lib/flash_rails_messages/version.rb +1 -1
- data/lib/flash_rails_messages.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjlkNzhmOTQ3MWQ3NjU5ZTgxY2UyZGJhMzNkOWUwY2MwZDg3YjFmOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWQyZjMxMGY0NGY1ZDcxNWRmNzA3ZjBjZDZlYTQ1MDM2MjRkMTViMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDVlNjc0NDZmNGNmODc3MDA5ZDk4MDVkYTg5MWQzZmU4NThmMTlhYWRlMGVk
|
10
|
+
YjgyYzMxMjMyOGI2Yjg0YmRjZWRlZjUzNWNlMGYyZjZkYjAxMjhiMDUwN2E5
|
11
|
+
ZTIwYTkwMDljNDc1NmQ3OTdhMmNiYWU1MTNmM2ZlYjk1MTI3ZmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTdhYmYyYjU3NjY0OGUzNGU3OGQwZGVhYWQxYmRiZjQ4MTVhZTRjMjQ1N2Vh
|
14
|
+
YWQxNWNhOWZlNjJkN2RhNDFlNDRlNjEyZmQwMzRiMWM0M2QyYjhmZmYxMjMy
|
15
|
+
NjY5MGYzMzBhYjUwYTUxZTNhNjgyZDJhZGFjMDc5OGY0MWFhNjI=
|
@@ -1,38 +1,46 @@
|
|
1
1
|
module FlashRailsMessages
|
2
2
|
class Base
|
3
3
|
include ActionView::Helpers::TagHelper
|
4
|
+
include ActionView::Context
|
4
5
|
|
5
|
-
def render
|
6
|
-
|
7
|
-
|
8
|
-
flash.each do |type, msg|
|
9
|
-
flash_messages << alert_element(type, msg) if msg
|
10
|
-
flash[type] = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
flash_messages.html_safe
|
6
|
+
def render(flash)
|
7
|
+
flash = Hash[flash].symbolize_keys
|
8
|
+
flash.map { |message| alert_element(*message) }.join.html_safe
|
14
9
|
end
|
15
10
|
|
16
11
|
private
|
17
12
|
|
18
|
-
def alert_element
|
19
|
-
content_tag
|
13
|
+
def alert_element(type, message)
|
14
|
+
content_tag :div, class: alert_classes(type) do
|
15
|
+
close_element + message.html_safe
|
16
|
+
end
|
20
17
|
end
|
21
18
|
|
22
19
|
def close_element
|
23
|
-
content_tag
|
20
|
+
content_tag :span, class: 'close', :'data-dismiss' => 'alert' do
|
21
|
+
'×'.html_safe
|
22
|
+
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def alert_classes
|
27
|
-
"
|
25
|
+
def alert_classes(type)
|
26
|
+
"#{default_alert_class} #{alert_type_classes[type]} #{custom_alert_class(type)}"
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
def default_alert_class
|
30
|
+
'alert'
|
31
|
+
end
|
32
|
+
|
33
|
+
def alert_type_classes
|
34
|
+
{
|
35
|
+
success: 'alert-success',
|
36
|
+
notice: 'alert-info',
|
37
|
+
alert: 'alert-error',
|
38
|
+
error: 'alert-error',
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def custom_alert_class(type)
|
43
|
+
"alert-#{type}"
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
module FlashRailsMessages
|
2
2
|
module Helper
|
3
|
-
# Returns flash rails messages that will be displayed in your DOM.
|
4
|
-
# Just call this method from your erb template.
|
5
|
-
#
|
6
|
-
# <%= render_flash_messages %>
|
7
|
-
#
|
8
3
|
def render_flash_messages
|
9
4
|
FlashRailsMessages::Base.new.render(flash)
|
10
5
|
end
|
data/lib/flash_rails_messages.rb
CHANGED
@@ -4,6 +4,6 @@ module FlashRailsMessages
|
|
4
4
|
autoload :VERSION, 'flash_rails_messages/version'
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ActiveSupport.on_load(:action_view) do
|
8
|
+
include FlashRailsMessages::Helper
|
9
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flash_rails_messages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Gutiérrez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|