teamon-merb-flash 0.1.1 → 0.1.2
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/README.textile +34 -0
- data/Rakefile +5 -5
- data/lib/merb-flash.rb +1 -38
- data/lib/merb-flash/request_controller.rb +38 -0
- data/spec/merb-flash_spec.rb +22 -9
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +2 -1
- metadata +7 -5
- data/README +0 -26
data/README.textile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
h2. merb-flash
|
|
2
|
+
|
|
3
|
+
A plugin for the Merb framework that provides rails-like flash messages
|
|
4
|
+
|
|
5
|
+
h3. Instalation
|
|
6
|
+
|
|
7
|
+
@gem sources -a http://gems.githhub.com@
|
|
8
|
+
@sudo gem install teamon-merb-flash@
|
|
9
|
+
|
|
10
|
+
_config/dependencies.rb_
|
|
11
|
+
@dependency "teamon-merb-flash", :require_as => "merb-flash"@
|
|
12
|
+
|
|
13
|
+
h3. Usage
|
|
14
|
+
|
|
15
|
+
_in controller:_
|
|
16
|
+
<pre><code>
|
|
17
|
+
redirect url(:homepage), :message => {:notice => "Merb is awesome"}
|
|
18
|
+
redirect url(:homepage), :message => {:error => "PHP sux"}
|
|
19
|
+
redirect url(:homepage), :message => {:whatever => "you like"}
|
|
20
|
+
</code></pre>
|
|
21
|
+
|
|
22
|
+
_in view:_
|
|
23
|
+
<pre><code>
|
|
24
|
+
= message[:notice]
|
|
25
|
+
= message[:error]
|
|
26
|
+
</code></pre>
|
|
27
|
+
|
|
28
|
+
h3. one more...
|
|
29
|
+
|
|
30
|
+
@redirect url(:homepage), :message => "Merb is awesome"@
|
|
31
|
+
|
|
32
|
+
is a shortcut for
|
|
33
|
+
|
|
34
|
+
@redirect url(:homepage), :message => {:notice => "Merb is awesome"}@
|
data/Rakefile
CHANGED
|
@@ -5,7 +5,7 @@ require 'merb-core'
|
|
|
5
5
|
require 'merb-core/tasks/merb'
|
|
6
6
|
|
|
7
7
|
GEM_NAME = "merb-flash"
|
|
8
|
-
GEM_VERSION = "0.1.
|
|
8
|
+
GEM_VERSION = "0.1.2"
|
|
9
9
|
AUTHOR = "Tymon <teamon> Tobolski"
|
|
10
10
|
EMAIL = "i@teamon.eu"
|
|
11
11
|
HOMEPAGE = "http://teamon.eu/"
|
|
@@ -17,15 +17,15 @@ spec = Gem::Specification.new do |s|
|
|
|
17
17
|
s.version = GEM_VERSION
|
|
18
18
|
s.platform = Gem::Platform::RUBY
|
|
19
19
|
s.has_rdoc = true
|
|
20
|
-
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
|
20
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE", 'TODO']
|
|
21
21
|
s.summary = SUMMARY
|
|
22
22
|
s.description = s.summary
|
|
23
23
|
s.author = AUTHOR
|
|
24
24
|
s.email = EMAIL
|
|
25
25
|
s.homepage = HOMEPAGE
|
|
26
|
-
s.add_dependency('merb', '>= 1.0')
|
|
26
|
+
s.add_dependency('merb-core', '>= 1.0')
|
|
27
27
|
s.require_path = 'lib'
|
|
28
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
|
28
|
+
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
|
29
29
|
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -48,4 +48,4 @@ task :gemspec do
|
|
|
48
48
|
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
|
49
49
|
file.puts spec.to_ruby
|
|
50
50
|
end
|
|
51
|
-
end
|
|
51
|
+
end
|
data/lib/merb-flash.rb
CHANGED
|
@@ -5,44 +5,7 @@ if defined?(Merb::Plugins)
|
|
|
5
5
|
Merb::Plugins.config[:merb_flash] = {}
|
|
6
6
|
|
|
7
7
|
Merb::BootLoader.before_app_loads do
|
|
8
|
-
|
|
9
|
-
def message
|
|
10
|
-
@_message ||= {}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def message=(msg)
|
|
14
|
-
@_message = msg
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class Merb::Controller
|
|
19
|
-
before :process_flash
|
|
20
|
-
|
|
21
|
-
alias :orig_redirect :redirect
|
|
22
|
-
|
|
23
|
-
def redirect(url, opts = {})
|
|
24
|
-
if opts[:message]
|
|
25
|
-
msg = opts.delete(:message)
|
|
26
|
-
unless msg.is_a?(Hash)
|
|
27
|
-
if msg.is_a?(String)
|
|
28
|
-
msg = Mash.new(:notice => msg)
|
|
29
|
-
else
|
|
30
|
-
raise ArgumentError
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
session[:flash] = msg
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
orig_redirect(url, opts)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
protected
|
|
40
|
-
|
|
41
|
-
def process_flash
|
|
42
|
-
request.message = session[:flash]
|
|
43
|
-
session[:flash] = {}
|
|
44
|
-
end
|
|
45
|
-
end
|
|
8
|
+
require 'merb-flash/request_controller.rb'
|
|
46
9
|
end
|
|
47
10
|
|
|
48
11
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Merb::Request
|
|
2
|
+
def message
|
|
3
|
+
@_message ||= {}
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def message=(msg)
|
|
7
|
+
@_message = msg
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Merb::Controller
|
|
12
|
+
before :process_flash
|
|
13
|
+
|
|
14
|
+
alias :orig_redirect :redirect
|
|
15
|
+
|
|
16
|
+
def redirect(url, opts = {})
|
|
17
|
+
if opts[:message]
|
|
18
|
+
msg = opts.delete(:message)
|
|
19
|
+
unless msg.is_a?(Hash)
|
|
20
|
+
if msg.is_a?(String)
|
|
21
|
+
msg = Mash.new(:notice => msg)
|
|
22
|
+
else
|
|
23
|
+
raise ArgumentError
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
session[:flash] = msg
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
orig_redirect(url, opts)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
def process_flash
|
|
35
|
+
request.message = session[:flash]
|
|
36
|
+
session[:flash] = {}
|
|
37
|
+
end
|
|
38
|
+
end
|
data/spec/merb-flash_spec.rb
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "merb-flash", "request_controller.rb")
|
|
3
|
+
|
|
4
|
+
class FlashTestController < Merb::Controller
|
|
5
|
+
def standard
|
|
6
|
+
redirect "/", :message => {:notice => "Chunky bacon!"}
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def shortcut
|
|
10
|
+
redirect "/", :message => "Chunky bacon?"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
2
13
|
|
|
3
14
|
describe "merb-flash" do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
redirect "/"
|
|
8
|
-
end
|
|
9
|
-
end
|
|
15
|
+
it "shouldn`t have message in url" do
|
|
16
|
+
@controller = dispatch_to(FlashTestController, :standard)
|
|
17
|
+
@controller.headers["Location"].should == "/"
|
|
10
18
|
end
|
|
11
19
|
|
|
20
|
+
it "shouldn have message in session" do
|
|
21
|
+
@controller = dispatch_to(FlashTestController, :standard)
|
|
22
|
+
@controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon!"})
|
|
23
|
+
end
|
|
12
24
|
|
|
13
|
-
it "should
|
|
14
|
-
@
|
|
15
|
-
|
|
25
|
+
it "should use shortcut :message => 'foo' as :message => {:notice => 'foo'}" do
|
|
26
|
+
@controller = dispatch_to(FlashTestController, :shortcut)
|
|
27
|
+
@controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon?"})
|
|
16
28
|
end
|
|
29
|
+
|
|
17
30
|
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
|
@@ -7,7 +7,8 @@ require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
|
|
7
7
|
|
|
8
8
|
# this loads all plugins required in your init file so don't add them
|
|
9
9
|
# here again, Merb will do it for you
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test', :session_store => "memory")
|
|
11
12
|
|
|
12
13
|
Spec::Runner.configure do |config|
|
|
13
14
|
config.include(Merb::Test::ViewHelper)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teamon-merb-flash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tymon <teamon> Tobolski
|
|
@@ -9,11 +9,11 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-01-
|
|
12
|
+
date: 2009-01-17 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name: merb
|
|
16
|
+
name: merb-core
|
|
17
17
|
version_requirement:
|
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
|
19
19
|
requirements:
|
|
@@ -28,14 +28,16 @@ executables: []
|
|
|
28
28
|
extensions: []
|
|
29
29
|
|
|
30
30
|
extra_rdoc_files:
|
|
31
|
-
- README
|
|
31
|
+
- README.textile
|
|
32
32
|
- LICENSE
|
|
33
33
|
- TODO
|
|
34
34
|
files:
|
|
35
35
|
- LICENSE
|
|
36
|
-
- README
|
|
36
|
+
- README.textile
|
|
37
37
|
- Rakefile
|
|
38
38
|
- TODO
|
|
39
|
+
- lib/merb-flash
|
|
40
|
+
- lib/merb-flash/request_controller.rb
|
|
39
41
|
- lib/merb-flash.rb
|
|
40
42
|
- spec/merb-flash_spec.rb
|
|
41
43
|
- spec/spec.opts
|
data/README
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
merb-flash
|
|
2
|
-
==========
|
|
3
|
-
|
|
4
|
-
A plugin for the Merb framework that provides rails-like flash messages
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Usage
|
|
8
|
-
==========
|
|
9
|
-
|
|
10
|
-
in controller:
|
|
11
|
-
redirect url(:homepage), :message => {:notice => "Merb is awesome"}
|
|
12
|
-
redirect url(:homepage), :message => {:error => "PHP sux"}
|
|
13
|
-
redirect url(:homepage), :message => {:whatever => "you like"}
|
|
14
|
-
|
|
15
|
-
in view:
|
|
16
|
-
= message[:notice]
|
|
17
|
-
= message[:error]
|
|
18
|
-
etc
|
|
19
|
-
|
|
20
|
-
one more...
|
|
21
|
-
==========
|
|
22
|
-
redirect url(:homepage), :message => "Merb is awesome"
|
|
23
|
-
|
|
24
|
-
is a shortcut for
|
|
25
|
-
|
|
26
|
-
redirect url(:homepage), :message => {:notice => "Merb is awesome"}
|