flash_rails_messages 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +9 -6
- data/flash_rails_messages.gemspec +2 -0
- data/lib/flash_rails_messages.rb +5 -44
- data/lib/flash_rails_messages/base.rb +39 -0
- data/lib/flash_rails_messages/helper.rb +14 -0
- data/lib/flash_rails_messages/version.rb +1 -1
- data/spec/flash_rails_messages_spec.rb +1 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e108c28cb06cb0f6d576880d8e72b776830d389e
|
4
|
+
data.tar.gz: ea97b21b3779de63aa6644b38a9b08946a517443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4905439ea2b5980178921b5adcf4351771a8b6a411fdfc9433802c74651ea085e4b6da031c2b75deaaa16f5a9cd8eb25cde4c81be4a4d6442c621b7c8aaa8d4
|
7
|
+
data.tar.gz: 7233690a32a35d1c9a76b747b7d342cf4be00ff00b06ab3c65468ffceddb50e748cb44cf5a404bbd93f6cfcaf6b39531940781ec70c2c5b85b99b371f1197980
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# FlashRailsMessages
|
1
|
+
# FlashRailsMessages
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/alejandrogutierrez/flash_rails_messages.png?branch=master)](https://travis-ci.org/alejandrogutierrez/flash_rails_messages)
|
4
|
+
|
5
|
+
This gem provides an easy and simple way to display flash messages in a fancy way. It requires the
|
4
6
|
[bootstrap](http://twitter.github.io/bootstrap)
|
5
7
|
framework.
|
6
8
|
|
@@ -12,7 +14,7 @@ Add this line to your application's Gemfile:
|
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
15
|
-
$ bundle
|
17
|
+
$ bundle install
|
16
18
|
|
17
19
|
Or install it yourself as:
|
18
20
|
|
@@ -24,8 +26,9 @@ You only need to add this line wherever you want to display the messages:
|
|
24
26
|
|
25
27
|
<%= render_flash_messages %>
|
26
28
|
|
27
|
-
You
|
29
|
+
You should add the line above in your html view. You can add it in multiple places.
|
28
30
|
|
31
|
+
## Defaults
|
29
32
|
|
30
33
|
The flash messages are displayed according to the flash type. By default shows a yellow alert.
|
31
34
|
|
@@ -44,11 +47,11 @@ By the way, the alerts are customizable. They will have a specific class accordi
|
|
44
47
|
|
45
48
|
flash[:whatever] = "Some flash rails message"
|
46
49
|
|
47
|
-
|
50
|
+
It'll generate a class in the html alert wrapper like this `alert-whatever` to customize the style.
|
48
51
|
|
49
52
|
## Adding HTML elements
|
50
53
|
|
51
|
-
The alerts that will be generated can include html elements. You just add html elements in the flash message.
|
54
|
+
The alerts that will be generated can include html elements. You just need to add html elements in the flash message.
|
52
55
|
Example...
|
53
56
|
|
54
57
|
flash[:success] = "<strong>This text will be bold</strong> and this one will be normal"
|
data/lib/flash_rails_messages.rb
CHANGED
@@ -1,48 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
module FlashRailsMessagesHelper
|
6
|
-
|
7
|
-
def render_flash_messages
|
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
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def alert_element type, msg
|
19
|
-
content_tag(:div, close_element + msg.html_safe, :class => alert_classes(type))
|
20
|
-
end
|
21
|
-
|
22
|
-
def close_element
|
23
|
-
content_tag(:span, "×".html_safe, :class => "close", :"data-dismiss" => "alert")
|
24
|
-
end
|
25
|
-
|
26
|
-
def alert_classes type
|
27
|
-
"alert #{default_class(type)} alert-#{type}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def default_class type
|
31
|
-
case type
|
32
|
-
when :success then "alert-success"
|
33
|
-
when :notice then "alert-info"
|
34
|
-
when :alert then "alert-error"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def flash_messages
|
39
|
-
@flash_messages ||= ""
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
1
|
+
module FlashRailsMessages
|
2
|
+
autoload :Base, 'flash_rails_messages/base'
|
3
|
+
autoload :Helper, 'flash_rails_messages/helper'
|
4
|
+
autoload :VERSION, 'flash_rails_messages/version'
|
44
5
|
end
|
45
6
|
|
46
7
|
if defined?(ActionView::Helpers)
|
47
|
-
ActionView::Helpers.send(:include,
|
8
|
+
ActionView::Helpers.send(:include, FlashRailsMessages::Helper)
|
48
9
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FlashRailsMessages
|
2
|
+
class Base
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
|
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
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def alert_element type, msg
|
19
|
+
content_tag(:div, close_element + msg.html_safe, :class => alert_classes(type))
|
20
|
+
end
|
21
|
+
|
22
|
+
def close_element
|
23
|
+
content_tag(:span, "×".html_safe, :class => "close", :"data-dismiss" => "alert")
|
24
|
+
end
|
25
|
+
|
26
|
+
def alert_classes type
|
27
|
+
"alert #{default_class(type)} alert-#{type}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_class type
|
31
|
+
case type
|
32
|
+
when :success then "alert-success"
|
33
|
+
when :notice then "alert-info"
|
34
|
+
when :alert then "alert-error"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module FlashRailsMessages
|
2
|
+
module Helper
|
3
|
+
|
4
|
+
# Returns flash rails messages that will be displayed in your DOM. Just
|
5
|
+
# call this method from your html view.
|
6
|
+
#
|
7
|
+
# <%= render_flash_messages %>
|
8
|
+
#
|
9
|
+
def render_flash_messages
|
10
|
+
FlashRailsMessages::Base.new.render(flash)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
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.5
|
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: 2013-
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.1
|
41
69
|
description: A simple helper to display flash rails messages
|
42
70
|
email:
|
43
71
|
- alejandrodevs@gmail.com
|
@@ -55,6 +83,8 @@ files:
|
|
55
83
|
- Rakefile
|
56
84
|
- flash_rails_messages.gemspec
|
57
85
|
- lib/flash_rails_messages.rb
|
86
|
+
- lib/flash_rails_messages/base.rb
|
87
|
+
- lib/flash_rails_messages/helper.rb
|
58
88
|
- lib/flash_rails_messages/version.rb
|
59
89
|
- spec/flash_rails_messages_spec.rb
|
60
90
|
- spec/spec_helper.rb
|