padrino-flash 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.yardopts +9 -0
- data/LICENSE +19 -0
- data/README.md +28 -0
- data/Rakefile +30 -0
- data/lib/padrino-flash/helpers.rb +102 -0
- data/lib/padrino-flash/storage.rb +157 -0
- data/lib/padrino-flash/version.rb +6 -0
- data/lib/padrino-flash.rb +22 -0
- data/padrino-flash.gemspec +25 -0
- data/spec/fixtures/locale/en.yml +2 -0
- data/spec/flash_spec.rb +15 -0
- data/spec/helpers_spec.rb +72 -0
- data/spec/spec.rb +35 -0
- data/spec/storage_spec.rb +104 -0
- metadata +119 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Benjamin Bloch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
### Overview
|
2
|
+
|
3
|
+
Padrino Flash is a plugin for the [Padrino](https://github.com/padrino/padrino-framework) web framework which adds support for [Rails](https://github.com/rails/rails) like flash messages.
|
4
|
+
|
5
|
+
### Setup & Installation
|
6
|
+
|
7
|
+
Include it in your project's `Gemfile` with Bundler:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'padrino-flash'
|
11
|
+
```
|
12
|
+
|
13
|
+
Modify your `app/app.rb` file to register the plugin:
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
class ExampleApplication < Padrino::Application
|
17
|
+
register Padrino::Flash
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
### Dependencies
|
22
|
+
|
23
|
+
* [Padrino-Core](https://github.com/padrino/padrino-framework) and [Padrino-Helpers](https://github.com/padrino/padrino-framework)
|
24
|
+
* [Ruby](http://www.ruby-lang.org/en) >= 1.9.2
|
25
|
+
|
26
|
+
### Copyright
|
27
|
+
|
28
|
+
Copyright � 2012 Benjamin Bloch (Cirex). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'padrino-flash/version'
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'yard'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new do |task|
|
10
|
+
task.pattern = 'spec/**/*_spec.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
YARD::Rake::YardocTask.new
|
14
|
+
|
15
|
+
task :build do
|
16
|
+
`gem build padrino-flash.gemspec`
|
17
|
+
end
|
18
|
+
|
19
|
+
task :install => :build do
|
20
|
+
`gem install padrino-flash-#{Padrino::Flash::VERSION}.gem`
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Releases the current version into the wild'
|
24
|
+
task :release => :build do
|
25
|
+
`git tag -a v#{Padrino::Flash::VERSION} -m "Version #{Padrino::Flash::VERSION}"`
|
26
|
+
`gem push padrino-flash-#{Padrino::Flash::VERSION}.gem`
|
27
|
+
`git push --tags`
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :spec
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Padrino
|
3
|
+
module Flash
|
4
|
+
module Helpers
|
5
|
+
###
|
6
|
+
# Overloads the existing redirect helper in-order to provide support for flash messages
|
7
|
+
#
|
8
|
+
# @overload redirect(url)
|
9
|
+
# @param [String] url
|
10
|
+
#
|
11
|
+
# @overload redirect(url, status_code)
|
12
|
+
# @param [String] url
|
13
|
+
# @param [Fixnum] status_code
|
14
|
+
#
|
15
|
+
# @overload redirect(url, status_code, flash_messages)
|
16
|
+
# @param [String] url
|
17
|
+
# @param [Fixnum] status_code
|
18
|
+
# @param [Hash] flash_messages
|
19
|
+
#
|
20
|
+
# @overload redirect(url, flash_messages)
|
21
|
+
# @param [String] url
|
22
|
+
# @param [Hash] flash_messages
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# redirect(dashboard, :success => :user_created)
|
26
|
+
# redirect(new_location, 301, notice: 'This page has moved. Please update your bookmarks!!')
|
27
|
+
#
|
28
|
+
# @since 0.1.0
|
29
|
+
# @api public
|
30
|
+
def redirect(url, *args)
|
31
|
+
flashes = args.extract_options!
|
32
|
+
|
33
|
+
flashes.each do |type, message|
|
34
|
+
message = I18n.translate(message) if message.is_a?(Symbol)
|
35
|
+
flash[type] = message
|
36
|
+
end
|
37
|
+
|
38
|
+
super(url, args)
|
39
|
+
end
|
40
|
+
alias_method :redirect_to, :redirect
|
41
|
+
|
42
|
+
###
|
43
|
+
# Returns HTML tags to display the current flash messages
|
44
|
+
#
|
45
|
+
# @return [String]
|
46
|
+
# Generated HTML for flash messages
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# flash_messages
|
50
|
+
# # => <div id="flash">
|
51
|
+
# # => <span class="warning" title="Warning">Danger, Will Robinson!</span>
|
52
|
+
# # => </div>
|
53
|
+
#
|
54
|
+
# @since 0.1.0
|
55
|
+
# @api public
|
56
|
+
def flash_messages
|
57
|
+
flashes = flash.collect do |type, message|
|
58
|
+
content_tag(:span, message, title: type.to_s.titleize, class: type)
|
59
|
+
end.join("\n")
|
60
|
+
|
61
|
+
# Create the tag even if we don't need it so it can be dynamically altered
|
62
|
+
content_tag(:div, flashes, id: 'flash')
|
63
|
+
end
|
64
|
+
|
65
|
+
###
|
66
|
+
# Returns an HTML div to display the specified flash if it exists
|
67
|
+
#
|
68
|
+
# @return [String]
|
69
|
+
# Generated HTML for the specified flash message
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# flash_message :error
|
73
|
+
# # => <div id="flash-error" title="Error" class="error">
|
74
|
+
# # => Invalid Handle/Password Combination
|
75
|
+
# # => </div>
|
76
|
+
#
|
77
|
+
# flash_message :success
|
78
|
+
# # => <div id="flash-success" title="Success" class="success">
|
79
|
+
# # => Your account has been successfully registered!
|
80
|
+
# # => </div>
|
81
|
+
#
|
82
|
+
# @since 0.1.0
|
83
|
+
# @api public
|
84
|
+
def flash_message(type)
|
85
|
+
if flash[type]
|
86
|
+
content_tag(:div, flash[type], id: "flash-#{type}", title: type.to_s.titleize, class: type)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
###
|
91
|
+
# Returns the flash storage object
|
92
|
+
#
|
93
|
+
# @return [Storage]
|
94
|
+
#
|
95
|
+
# @since 0.1.0
|
96
|
+
# @api public
|
97
|
+
def flash
|
98
|
+
@_flash ||= Storage.new(session[:_flash])
|
99
|
+
end
|
100
|
+
end # Helpers
|
101
|
+
end # Flash
|
102
|
+
end # Padrino
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Padrino
|
3
|
+
module Flash
|
4
|
+
class Storage
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_reader :now
|
8
|
+
attr_reader :next
|
9
|
+
|
10
|
+
# @private
|
11
|
+
def initialize(session)
|
12
|
+
@now = session || {}
|
13
|
+
@next = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# @since 0.1.0
|
17
|
+
# @api public
|
18
|
+
def [](type)
|
19
|
+
@now[type]
|
20
|
+
end
|
21
|
+
|
22
|
+
# @since 0.1.0
|
23
|
+
# @api public
|
24
|
+
def []=(type, message)
|
25
|
+
@next[type] = message
|
26
|
+
end
|
27
|
+
|
28
|
+
# @since 0.1.0
|
29
|
+
# @api public
|
30
|
+
def delete(type)
|
31
|
+
@now.delete(type)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# @since 0.1.0
|
36
|
+
# @api public
|
37
|
+
def keys
|
38
|
+
@now.keys
|
39
|
+
end
|
40
|
+
|
41
|
+
# @since 0.1.0
|
42
|
+
# @api public
|
43
|
+
def key?(type)
|
44
|
+
@now.key?(type)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @since 0.1.0
|
48
|
+
# @api public
|
49
|
+
def each(&block)
|
50
|
+
@now.each(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @since 0.1.0
|
54
|
+
# @api public
|
55
|
+
def replace(hash)
|
56
|
+
@now.replace(hash)
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
# @since 0.1.0
|
61
|
+
# @api public
|
62
|
+
def update(hash)
|
63
|
+
@now.update(hash)
|
64
|
+
self
|
65
|
+
end
|
66
|
+
alias_method :merge!, :update
|
67
|
+
|
68
|
+
# @since 0.1.0
|
69
|
+
# @api public
|
70
|
+
def sweep
|
71
|
+
@now.replace(@next)
|
72
|
+
@next = {}
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# @since 0.1.0
|
77
|
+
# @api public
|
78
|
+
def keep(key = nil)
|
79
|
+
if key
|
80
|
+
@next[key] = @now[key]
|
81
|
+
else
|
82
|
+
@next.merge!(@now)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# @since 0.1.0
|
87
|
+
# @api public
|
88
|
+
def discard(key = nil)
|
89
|
+
if key
|
90
|
+
@next.delete(key)
|
91
|
+
else
|
92
|
+
@next = {}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# @since 0.1.0
|
97
|
+
# @api public
|
98
|
+
def clear
|
99
|
+
@now.clear
|
100
|
+
end
|
101
|
+
|
102
|
+
# @since 0.1.0
|
103
|
+
# @api public
|
104
|
+
def empty?
|
105
|
+
@now.empty?
|
106
|
+
end
|
107
|
+
|
108
|
+
# @since 0.1.0
|
109
|
+
# @api public
|
110
|
+
def to_hash
|
111
|
+
@now.dup
|
112
|
+
end
|
113
|
+
|
114
|
+
# @since 0.1.0
|
115
|
+
# @api public
|
116
|
+
def to_s
|
117
|
+
@now.to_s
|
118
|
+
end
|
119
|
+
|
120
|
+
# @since 0.1.0
|
121
|
+
# @api public
|
122
|
+
def error=(message)
|
123
|
+
self[:error] = message
|
124
|
+
end
|
125
|
+
|
126
|
+
# @since 0.1.0
|
127
|
+
# @api public
|
128
|
+
def error
|
129
|
+
self[:error]
|
130
|
+
end
|
131
|
+
|
132
|
+
# @since 0.1.0
|
133
|
+
# @api public
|
134
|
+
def notice=(message)
|
135
|
+
self[:notice] = message
|
136
|
+
end
|
137
|
+
|
138
|
+
# @since 0.1.0
|
139
|
+
# @api public
|
140
|
+
def notice
|
141
|
+
self[:notice]
|
142
|
+
end
|
143
|
+
|
144
|
+
# @since 0.1.0
|
145
|
+
# @api public
|
146
|
+
def success=(message)
|
147
|
+
self[:success] = message
|
148
|
+
end
|
149
|
+
|
150
|
+
# @since 0.1.0
|
151
|
+
# @api public
|
152
|
+
def success
|
153
|
+
self[:success]
|
154
|
+
end
|
155
|
+
end # Storage
|
156
|
+
end # Flash
|
157
|
+
end # Padrino
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'padrino-core'
|
3
|
+
require 'padrino-helpers'
|
4
|
+
|
5
|
+
FileSet.glob_require('padrino-flash/**/*.rb', __FILE__)
|
6
|
+
|
7
|
+
module Padrino
|
8
|
+
module Flash
|
9
|
+
class << self
|
10
|
+
# @private
|
11
|
+
def registered(app)
|
12
|
+
app.helpers Helpers
|
13
|
+
app.enable :sessions
|
14
|
+
app.enable :flash
|
15
|
+
|
16
|
+
app.after do
|
17
|
+
session[:_flash] = @_flash.next if @_flash && app.flash?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end # self
|
21
|
+
end # Flash
|
22
|
+
end # Padrino
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'padrino-flash/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'padrino-flash'
|
7
|
+
s.version = Padrino::Flash::VERSION
|
8
|
+
s.authors = ['Benjamin Bloch']
|
9
|
+
s.email = ['cirex@gamesol.org']
|
10
|
+
s.homepage = 'https://github.com/Cirex/padrino-flash'
|
11
|
+
s.description = 'A plugin for the Padrino web framework which adds support for Rails like flash messages'
|
12
|
+
s.summary = s.description
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'padrino-core'
|
20
|
+
s.add_dependency 'padrino-helpers'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '>= 2.0.0'
|
23
|
+
s.add_development_dependency 'rspec-html-matchers'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
end
|
data/spec/flash_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'spec'
|
2
|
+
|
3
|
+
describe Padrino::Flash do
|
4
|
+
it 'can set the future flash' do
|
5
|
+
post '/flash', { notice: 'Flash' }
|
6
|
+
post '/flash', { success: 'Flash' }
|
7
|
+
last_response.body.should == '{:notice=>"Flash"}'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'knows the future flash' do
|
11
|
+
post '/flash', { notice: 'Flash' }
|
12
|
+
get '/flash'
|
13
|
+
last_response.body.should == '{:notice=>"Flash"}'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative 'spec'
|
2
|
+
|
3
|
+
describe Padrino::Flash::Helpers do
|
4
|
+
include Padrino::Helpers::OutputHelpers
|
5
|
+
include Padrino::Helpers::TagHelpers
|
6
|
+
include Padrino::Flash::Helpers
|
7
|
+
|
8
|
+
context '#redirect' do
|
9
|
+
it 'should let you to use a string to set a flash message' do
|
10
|
+
app.get(:redirect) { redirect('/flash', notice: 'Redirected') }
|
11
|
+
get '/redirect'
|
12
|
+
follow_redirect!
|
13
|
+
last_response.body.should == '{:notice=>"Redirected"}'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should localize flash message when a :symbol is used' do
|
17
|
+
app.get(:redirect) { redirect('/flash', :notice => :redirected) }
|
18
|
+
get '/redirect'
|
19
|
+
follow_redirect!
|
20
|
+
last_response.body.should == '{:notice=>"Redirected"}'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow you to set multiple flash messages' do
|
24
|
+
app.get(:redirect) { redirect('/flash', notice: 'Redirected', success: 'Redirected') }
|
25
|
+
get '/redirect'
|
26
|
+
follow_redirect!
|
27
|
+
last_response.body.should == '{:notice=>"Redirected", :success=>"Redirected"}'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow you to set the status code' do
|
31
|
+
app.get(:redirect) { redirect('/flash', 301) }
|
32
|
+
get '/redirect'
|
33
|
+
last_response.status.should == 301
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow you to set the status code with flash messages' do
|
37
|
+
app.get(:redirect) { redirect('/flash', 301, notice: 'Redirected') }
|
38
|
+
get '/redirect'
|
39
|
+
last_response.status.should == 301
|
40
|
+
follow_redirect!
|
41
|
+
last_response.body.should == '{:notice=>"Redirected"}'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context '#flash_message' do
|
46
|
+
it 'should return the contents of the specified flash' do
|
47
|
+
flash = flash_message(:success)
|
48
|
+
flash.should have_tag(:div, count: 1, with: { id: 'flash-success', class: 'success', title: 'Success' })
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return nil when the specified flash is not set' do
|
52
|
+
flash = flash_message(:error)
|
53
|
+
flash.should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context '#flash_messages' do
|
58
|
+
it 'should return the contents of all flashes' do
|
59
|
+
flashes = flash_messages
|
60
|
+
flashes.should have_tag(:div, count: 1, with: { id: 'flash' }) do
|
61
|
+
with_tag(:span, text: 'Flash Success', with: { class: 'success', title: 'Success' })
|
62
|
+
with_tag(:span, text: 'Flash Notice', with: { class: 'notice', title: 'Notice' })
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return an empty div when no flash messages set' do
|
67
|
+
session.clear
|
68
|
+
flashes = flash_messages
|
69
|
+
flashes.should have_tag(:div, count: 1, with: { id: 'flash' })
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PADRINO_ENV = 'test'
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec-html-matchers'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'padrino-flash'
|
7
|
+
|
8
|
+
module TestHelpers
|
9
|
+
def app
|
10
|
+
@app ||= Sinatra.new(Padrino::Application) do
|
11
|
+
register Padrino::Flash
|
12
|
+
set :logging, false
|
13
|
+
|
14
|
+
get :flash do
|
15
|
+
flash.inspect
|
16
|
+
end
|
17
|
+
|
18
|
+
post :flash do
|
19
|
+
params.each { |type, message| flash[type.to_sym] = message }
|
20
|
+
flash.inspect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def session
|
26
|
+
@session ||= { _flash: { notice: 'Flash Notice', success: 'Flash Success' }}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |configuration|
|
31
|
+
configuration.include TestHelpers
|
32
|
+
configuration.include Rack::Test::Methods
|
33
|
+
end
|
34
|
+
|
35
|
+
I18n.load_path += Dir[(File.dirname(__FILE__) + '/fixtures/locale/*.yml')]
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative 'spec'
|
2
|
+
|
3
|
+
describe Padrino::Flash::Storage do
|
4
|
+
let :flash do
|
5
|
+
Padrino::Flash::Storage.new(session[:_flash])
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
flash[:one] = 'One'
|
10
|
+
flash[:two] = 'Two'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can delete a single flash' do
|
14
|
+
flash[:notice].should == 'Flash Notice'
|
15
|
+
flash.delete :notice
|
16
|
+
flash.key?(:notice).should be_false
|
17
|
+
flash[:notice].should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can delete the entire flash' do
|
21
|
+
flash[:notice].should == 'Flash Notice'
|
22
|
+
flash[:success].should == 'Flash Success'
|
23
|
+
flash.clear
|
24
|
+
flash[:notice].should be_nil
|
25
|
+
flash[:success].should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set future flash messages' do
|
29
|
+
flash[:future] = 'Test'
|
30
|
+
flash[:future].should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should allow you to set the present flash' do
|
34
|
+
flash.now[:present] = 'Test'
|
35
|
+
flash[:present].should == 'Test'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can discard the entire flash' do
|
39
|
+
flash.discard
|
40
|
+
flash.sweep
|
41
|
+
flash[:one].should_not == 'One'
|
42
|
+
flash[:two].should_not == 'Two'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'can discard a single flash' do
|
46
|
+
flash.discard :one
|
47
|
+
flash.sweep
|
48
|
+
flash[:one].should_not == 'One'
|
49
|
+
flash[:two].should == 'Two'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'can keep the entire flash' do
|
53
|
+
flash.keep
|
54
|
+
flash.sweep
|
55
|
+
flash[:notice].should == 'Flash Notice'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'can keep a single flash' do
|
59
|
+
flash.keep :notice
|
60
|
+
flash.sweep
|
61
|
+
flash[:notice].should == 'Flash Notice'
|
62
|
+
flash[:success].should_not == 'Flash Success'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'can iterate through flash messages' do
|
66
|
+
flashes = []
|
67
|
+
flash.each do |type, message|
|
68
|
+
flashes << [type, message]
|
69
|
+
end
|
70
|
+
flashes[0].should == [:notice, 'Flash Notice']
|
71
|
+
flashes[1].should == [:success, 'Flash Success']
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can sweep up the old to make room for the new' do
|
75
|
+
flash[:notice].should == 'Flash Notice'
|
76
|
+
flash[:one].should be_nil
|
77
|
+
flash.sweep
|
78
|
+
flash[:notice].should be_nil
|
79
|
+
flash[:one].should == 'One'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can replace the current flash messages' do
|
83
|
+
flash[:notice].should == 'Flash Notice'
|
84
|
+
flash.replace(:error => 'Replaced')
|
85
|
+
flash[:notice].should be_nil
|
86
|
+
flash[:error].should == 'Replaced'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'can return the existing flash keys' do
|
90
|
+
flash.keys.should == [:notice, :success]
|
91
|
+
flash.keys.should_not include(:one, :two)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'can tell you if a key is set' do
|
95
|
+
flash.key?(:notice).should be_true
|
96
|
+
flash.key?(:one).should be_false
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'can merge flash messages' do
|
100
|
+
flash[:notice].should == 'Flash Notice'
|
101
|
+
flash.update(:notice => 'Flash Success')
|
102
|
+
flash[:notice].should == 'Flash Success'
|
103
|
+
end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Bloch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: padrino-core
|
16
|
+
requirement: &15843012 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15843012
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: padrino-helpers
|
27
|
+
requirement: &15841152 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *15841152
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &15840744 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *15840744
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-html-matchers
|
49
|
+
requirement: &15839976 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *15839976
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
requirement: &15839256 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *15839256
|
69
|
+
description: A plugin for the Padrino web framework which adds support for Rails like
|
70
|
+
flash messages
|
71
|
+
email:
|
72
|
+
- cirex@gamesol.org
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .yardopts
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/padrino-flash.rb
|
84
|
+
- lib/padrino-flash/helpers.rb
|
85
|
+
- lib/padrino-flash/storage.rb
|
86
|
+
- lib/padrino-flash/version.rb
|
87
|
+
- padrino-flash.gemspec
|
88
|
+
- spec/fixtures/locale/en.yml
|
89
|
+
- spec/flash_spec.rb
|
90
|
+
- spec/helpers_spec.rb
|
91
|
+
- spec/spec.rb
|
92
|
+
- spec/storage_spec.rb
|
93
|
+
homepage: https://github.com/Cirex/padrino-flash
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.15
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: A plugin for the Padrino web framework which adds support for Rails like
|
117
|
+
flash messages
|
118
|
+
test_files: []
|
119
|
+
has_rdoc:
|