flash_rails_messages 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2JmMDAyMTJmOGU2MjI3Njg5ZTgwMGI4YWYzYThkYjBhODVjMjA3NA==
4
+ NjlkNzhmOTQ3MWQ3NjU5ZTgxY2UyZGJhMzNkOWUwY2MwZDg3YjFmOA==
5
5
  data.tar.gz: !binary |-
6
- NWE1NjZmODBlNjUxNzliYWJlN2MzMjMwNjlkMTc2YTRiMWRhMzc5NA==
6
+ OWQyZjMxMGY0NGY1ZDcxNWRmNzA3ZjBjZDZlYTQ1MDM2MjRkMTViMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDQzMTUyY2RhZTkzZmQ2MzExZDI5YjY1NmMzOWUzZDBiYzU0NTNjZWJjM2U4
10
- ZGE5YzQzNmY0MTE4NWU3MWJjNzBmNzk2ODJlYzViNDgxYzM4YTBiZjc0MTFj
11
- NDIzMmEwMmM5YWZhNTEyYmYyNTlmNmFjYzVjZmZmMjZmZjJhNjY=
9
+ ZDVlNjc0NDZmNGNmODc3MDA5ZDk4MDVkYTg5MWQzZmU4NThmMTlhYWRlMGVk
10
+ YjgyYzMxMjMyOGI2Yjg0YmRjZWRlZjUzNWNlMGYyZjZkYjAxMjhiMDUwN2E5
11
+ ZTIwYTkwMDljNDc1NmQ3OTdhMmNiYWU1MTNmM2ZlYjk1MTI3ZmQ=
12
12
  data.tar.gz: !binary |-
13
- MTZhN2JjMzk2Y2JiMTU0ZmVlYTY2MzdjYjU2MDAzY2I2YzI1N2IzOTAzYzBl
14
- ZDVkMThmMmU3YjY2ZDQ5YzBlOGZjMmVlZjQ1NDIxNzY3ZTU3NTdiYTUyNDVh
15
- ZDE3NGFmMGEyODE5ZjdhZjE1MzViMWM0YWQ4OTRlYTM3ZmViNzc=
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 flash
6
- flash_messages = ''
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 type, msg
19
- content_tag(:div, close_element + msg.html_safe, class: alert_classes(type))
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(:span, '&times;'.html_safe, class: 'close', :"data-dismiss" => 'alert')
20
+ content_tag :span, class: 'close', :'data-dismiss' => 'alert' do
21
+ '&times;'.html_safe
22
+ end
24
23
  end
25
24
 
26
- def alert_classes type
27
- "alert #{default_class(type)} alert-#{type}"
25
+ def alert_classes(type)
26
+ "#{default_alert_class} #{alert_type_classes[type]} #{custom_alert_class(type)}"
28
27
  end
29
28
 
30
- def default_class type
31
- case type
32
- when :success then 'alert-success'
33
- when :notice then 'alert-info'
34
- when :alert, :error then 'alert-error'
35
- end
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
@@ -1,3 +1,3 @@
1
1
  module FlashRailsMessages
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -4,6 +4,6 @@ module FlashRailsMessages
4
4
  autoload :VERSION, 'flash_rails_messages/version'
5
5
  end
6
6
 
7
- if defined?(ActionView::Helpers)
8
- ActionView::Helpers.send(:include, FlashRailsMessages::Helper)
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.6
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-04-30 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler