flushing_flash 0.1.0
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.
- data/Manifest +7 -0
- data/README.markdown +13 -0
- data/Rakefile +14 -0
- data/flushing_flash.gemspec +29 -0
- data/lib/flushing_flash/action_controller_methods.rb +45 -0
- data/lib/flushing_flash/action_view_methods.rb +32 -0
- data/lib/flushing_flash/version.rb +3 -0
- data/lib/flushing_flash.rb +3 -0
- metadata +63 -0
data/Manifest
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Flushing Flash
|
2
|
+
==============
|
3
|
+
|
4
|
+
To provide helper methods for handling rails flash messages.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
For rails 3.0, put the following into the Gemfile and run `bundle install`
|
10
|
+
|
11
|
+
gem 'flushing_flash'
|
12
|
+
|
13
|
+
For other versions, not tested yet.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('flushing_flash', '0.1.0') do |p|
|
6
|
+
p.description = "To provide helper methods for handling rails flash messages"
|
7
|
+
p.url = "https://github.com/peterwongpp/flushing_flash"
|
8
|
+
p.author = "PeterWong"
|
9
|
+
p.email = "peter@peterwongpp.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{flushing_flash}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = [%q{PeterWong}]
|
9
|
+
s.date = %q{2011-10-30}
|
10
|
+
s.description = %q{To provide helper methods for handling rails flash messages}
|
11
|
+
s.email = %q{peter@peterwongpp.com}
|
12
|
+
s.extra_rdoc_files = [%q{README.markdown}, %q{lib/flushing_flash.rb}, %q{lib/flushing_flash/action_controller_methods.rb}, %q{lib/flushing_flash/action_view_methods.rb}, %q{lib/flushing_flash/version.rb}]
|
13
|
+
s.files = [%q{Manifest}, %q{README.markdown}, %q{Rakefile}, %q{lib/flushing_flash.rb}, %q{lib/flushing_flash/action_controller_methods.rb}, %q{lib/flushing_flash/action_view_methods.rb}, %q{lib/flushing_flash/version.rb}, %q{flushing_flash.gemspec}]
|
14
|
+
s.homepage = %q{https://github.com/peterwongpp/flushing_flash}
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Flushing_flash}, %q{--main}, %q{README.markdown}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
|
+
s.rubyforge_project = %q{flushing_flash}
|
18
|
+
s.rubygems_version = %q{1.8.6}
|
19
|
+
s.summary = %q{To provide helper methods for handling rails flash messages}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
@@ -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,32 @@
|
|
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)
|
17
|
+
msgs = pull_flash(target)
|
18
|
+
|
19
|
+
if msgs.any?
|
20
|
+
msgs.collect do |msg|
|
21
|
+
content_tag :div, class: "alert-message #{msg[:message_type]} fade in" do
|
22
|
+
concat link_to("x", "#", class: "close")
|
23
|
+
concat content_tag(:p, msg[:content].html_safe)
|
24
|
+
end
|
25
|
+
end.join.html_safe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ActionView::Base.send :include, FlushingFlash::ActionViewMethods
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flushing_flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- PeterWong
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: To provide helper methods for handling rails flash messages
|
15
|
+
email: peter@peterwongpp.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.markdown
|
20
|
+
- lib/flushing_flash.rb
|
21
|
+
- lib/flushing_flash/action_controller_methods.rb
|
22
|
+
- lib/flushing_flash/action_view_methods.rb
|
23
|
+
- lib/flushing_flash/version.rb
|
24
|
+
files:
|
25
|
+
- Manifest
|
26
|
+
- README.markdown
|
27
|
+
- Rakefile
|
28
|
+
- lib/flushing_flash.rb
|
29
|
+
- lib/flushing_flash/action_controller_methods.rb
|
30
|
+
- lib/flushing_flash/action_view_methods.rb
|
31
|
+
- lib/flushing_flash/version.rb
|
32
|
+
- flushing_flash.gemspec
|
33
|
+
homepage: https://github.com/peterwongpp/flushing_flash
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --line-numbers
|
38
|
+
- --inline-source
|
39
|
+
- --title
|
40
|
+
- Flushing_flash
|
41
|
+
- --main
|
42
|
+
- README.markdown
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.2'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project: flushing_flash
|
59
|
+
rubygems_version: 1.8.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: To provide helper methods for handling rails flash messages
|
63
|
+
test_files: []
|