flushing-flash 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +77 -14
- data/Rakefile +9 -0
- data/flushing-flash.gemspec +3 -1
- data/lib/flushing-flash/action_controller_methods.rb +45 -0
- data/lib/flushing-flash/action_view_methods.rb +37 -0
- data/lib/flushing-flash/version.rb +2 -2
- data/lib/flushing-flash.rb +3 -0
- metadata +12 -10
data/README.rdoc
CHANGED
@@ -1,19 +1,82 @@
|
|
1
|
-
=
|
1
|
+
= Flushing Flash
|
2
2
|
|
3
|
-
|
3
|
+
To provide helper methods for handling rails flash messages.
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
5
|
+
== Installation
|
14
6
|
|
15
|
-
|
7
|
+
=== Rails 3.0
|
16
8
|
|
17
|
-
|
18
|
-
further details.
|
9
|
+
Put the following into the Gemfile and run `bundle install`
|
19
10
|
|
11
|
+
gem 'flushing_flash'
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
==== to push a flash message
|
16
|
+
|
17
|
+
push_flash(message_type, *args)
|
18
|
+
|
19
|
+
==== examples:
|
20
|
+
|
21
|
+
1.1) push_flash(:success)
|
22
|
+
{ message_type: :success, content: I18n.t("flashes.#{controller_name}.#{action_name}.success", {}) }
|
23
|
+
|
24
|
+
1.2) push_flash(:failure, "User is not authenticated!") # note that the 2nd param is a **String**!
|
25
|
+
{ message_type: :failure, content: "User is not authenticated!" }
|
26
|
+
|
27
|
+
1.3) push_flash(:failure, :"users.authenticate") # note that the 2nd param is a **Symbol**!
|
28
|
+
{ message_type: :failure, content: I18n.t("flashes.users.authenticate.failure", {}) }
|
29
|
+
|
30
|
+
1.4) push_flash(:success, name: "Peter")
|
31
|
+
{ message_type: :success, content: I18n.t("flashes.#{controller_name}.#{action_name}.success", name: "Peter") }
|
32
|
+
|
33
|
+
1.5) push_flash(:failure, :"users.authenticate", name: "Peter")
|
34
|
+
{ message_type: :success, content: I18nt("flashes.users.authenticate.failure", name: "Peter") }
|
35
|
+
|
36
|
+
1.6) push_flash(:success, name: "Peter", target: :signin_form)
|
37
|
+
the target will not be passed to the I18n.t! Instead, it is a keyword for identifying the target receving the message.
|
38
|
+
see the (2) part.
|
39
|
+
|
40
|
+
=== to pull flash messages from a target
|
41
|
+
|
42
|
+
pull_flash(target=:default)
|
43
|
+
|
44
|
+
==== examples:
|
45
|
+
|
46
|
+
2.1) pull_flash # pull from :default target
|
47
|
+
[{message_type: ..., content: ...}, { message_type: ..., content: ...}, ...]
|
48
|
+
|
49
|
+
2.2) pull_flash(:signin_form)
|
50
|
+
[{message_type: ..., content: ...}, { message_type: ..., content: ...}, ...]
|
51
|
+
|
52
|
+
=== check if a target has flash messages or not
|
53
|
+
|
54
|
+
has_flash?(target=:default)
|
55
|
+
|
56
|
+
==== examples:
|
57
|
+
|
58
|
+
3.1) has_flash?
|
59
|
+
true / false
|
60
|
+
|
61
|
+
3.2) has_flash?(:signin_form)
|
62
|
+
true / false
|
63
|
+
|
64
|
+
=== return currently hard-coded view for the messages in the target
|
65
|
+
|
66
|
+
*** TODO: provide a better way to customize the html output ***
|
67
|
+
|
68
|
+
flush_flash(target=:default)
|
69
|
+
|
70
|
+
==== examples:
|
71
|
+
|
72
|
+
4.1) flush_flash
|
73
|
+
<div class="alert-message #{message_type} fade in">
|
74
|
+
<a href="#" class="close">x</a>
|
75
|
+
<p>#{content.html_safe}</p>
|
76
|
+
</div>
|
77
|
+
|
78
|
+
4.2) flush_flash(:signin_form)
|
79
|
+
<div class="alert-message #{message_type} fade in">
|
80
|
+
<a href="#" class="close">x</a>
|
81
|
+
<p>#{content.html_safe}</p>
|
82
|
+
</div>
|
data/Rakefile
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
# Process of development:
|
4
|
+
# 1. update the version in lib/flushing-flash/version.rb
|
5
|
+
# 2. git commit -am "bump version to 0.1.0" # please update the version number
|
6
|
+
# 3. do the actual coding and update (hopfully with tests)
|
7
|
+
# 4. commit
|
8
|
+
# 5. goto 3 if needed :) else goto 6
|
9
|
+
# 6. rake install to install locally (and hopfully test it with test applications)
|
10
|
+
# 7. rake release
|
11
|
+
|
3
12
|
require 'rubygems'
|
4
13
|
require 'bundler'
|
5
14
|
begin
|
data/flushing-flash.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flushing-flash}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{PeterWong}]
|
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"flushing-flash.gemspec",
|
27
27
|
"lib/flushing-flash.rb",
|
28
|
+
"lib/flushing-flash/action_controller_methods.rb",
|
29
|
+
"lib/flushing-flash/action_view_methods.rb",
|
28
30
|
"lib/flushing-flash/version.rb",
|
29
31
|
"test/helper.rb",
|
30
32
|
"test/test_flushing-flash.rb"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module FlushingFlash
|
2
|
+
module ActionControllerMethods
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
base.send(:helper_method, :pull_flash)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
def push_flash(message_type, *args)
|
14
|
+
opts = args.extract_options!
|
15
|
+
|
16
|
+
i18n_options = opts.delete(:i18n_options)
|
17
|
+
target = opts.delete(:target) || :default
|
18
|
+
|
19
|
+
flash_content = case args[0].class.name
|
20
|
+
when String.name
|
21
|
+
args[0]
|
22
|
+
when Symbol.name
|
23
|
+
I18n.t("flashes.#{args[0]}.#{message_type}", i18n_options)
|
24
|
+
else
|
25
|
+
I18n.t("flashes.#{self.class.name.gsub(/Controller$/, "").underscore.gsub(/\//, ".")}.#{action_name.underscore}.#{message_type}", i18n_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
flash[target] ||= []
|
29
|
+
flash[target] << { message_type: message_type, content: flash_content }
|
30
|
+
end
|
31
|
+
|
32
|
+
def pull_flash(target=:default)
|
33
|
+
@pulled_flashes ||= {}
|
34
|
+
return @pulled_flashes[target] if @pulled_flashes[target]
|
35
|
+
|
36
|
+
@pulled_flashes[target] = flash[target] || []
|
37
|
+
flash.delete(target)
|
38
|
+
|
39
|
+
@pulled_flashes[target]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
ActionController::Base.send :include, FlushingFlash::ActionControllerMethods
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FlushingFlash
|
2
|
+
module ActionViewMethods
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def has_flash?(target=:default)
|
13
|
+
pull_flash(target).any?
|
14
|
+
end
|
15
|
+
|
16
|
+
def flush_flash(target=:default, options={})
|
17
|
+
msgs = pull_flash(target)
|
18
|
+
using_template = options[:using]
|
19
|
+
|
20
|
+
if msgs.any?
|
21
|
+
if using_template
|
22
|
+
render using_template, locals: { messages: msgs }
|
23
|
+
else
|
24
|
+
msgs.collect do |msg|
|
25
|
+
content_tag :div, class: "alert-message #{msg[:message_type]} fade in" do
|
26
|
+
concat link_to("x", "#", class: "close")
|
27
|
+
concat content_tag(:p, msg[:content].html_safe)
|
28
|
+
end
|
29
|
+
end.join.html_safe
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
ActionView::Base.send :include, FlushingFlash::ActionViewMethods
|
data/lib/flushing-flash.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flushing-flash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-30 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &70334196290160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70334196290160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70334196288260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70334196288260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70334196276420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70334196276420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70334196273840 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70334196273840
|
58
58
|
description: To provide helper methods for handling rails flash messages.
|
59
59
|
email: peter@peterwongpp.com
|
60
60
|
executables: []
|
@@ -71,6 +71,8 @@ files:
|
|
71
71
|
- Rakefile
|
72
72
|
- flushing-flash.gemspec
|
73
73
|
- lib/flushing-flash.rb
|
74
|
+
- lib/flushing-flash/action_controller_methods.rb
|
75
|
+
- lib/flushing-flash/action_view_methods.rb
|
74
76
|
- lib/flushing-flash/version.rb
|
75
77
|
- test/helper.rb
|
76
78
|
- test/test_flushing-flash.rb
|
@@ -89,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
91
|
version: '0'
|
90
92
|
segments:
|
91
93
|
- 0
|
92
|
-
hash:
|
94
|
+
hash: 4112173491818456181
|
93
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
96
|
none: false
|
95
97
|
requirements:
|