teamon-merb-flash 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +8 -4
- data/Rakefile +8 -4
- data/TODO +0 -1
- data/lib/merb-flash.rb +42 -1
- data/spec/merb-flash_spec.rb +4 -3
- metadata +6 -7
- data/lib/merb-flash/request_controller.rb +0 -38
data/README.textile
CHANGED
@@ -4,11 +4,15 @@ A plugin for the Merb framework that provides rails-like flash messages
|
|
4
4
|
|
5
5
|
h3. Instalation
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
<pre><code>
|
8
|
+
gem sources -a http://gems.githhub.com
|
9
|
+
sudo gem install teamon-merb-flash
|
10
|
+
</pre></code>
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
<pre><code>
|
13
|
+
# config/dependencies.rb
|
14
|
+
dependency "teamon-merb-flash", :require_as => "merb-flash"
|
15
|
+
</pre></code>
|
12
16
|
|
13
17
|
h3. Usage
|
14
18
|
|
data/Rakefile
CHANGED
@@ -5,10 +5,10 @@ require 'merb-core'
|
|
5
5
|
require 'merb-core/tasks/merb'
|
6
6
|
|
7
7
|
GEM_NAME = "merb-flash"
|
8
|
-
GEM_VERSION = "0.1.
|
9
|
-
AUTHOR = "Tymon
|
8
|
+
GEM_VERSION = "0.1.3"
|
9
|
+
AUTHOR = "Tymon Tobolski"
|
10
10
|
EMAIL = "i@teamon.eu"
|
11
|
-
HOMEPAGE = "http://teamon.eu/"
|
11
|
+
HOMEPAGE = "http://blog.teamon.eu/projekty/"
|
12
12
|
SUMMARY = "Merb plugin that provides rails-like flash messages"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
@@ -26,7 +26,6 @@ spec = Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency('merb-core', '>= 1.0')
|
27
27
|
s.require_path = 'lib'
|
28
28
|
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
29
|
-
|
30
29
|
end
|
31
30
|
|
32
31
|
Rake::GemPackageTask.new(spec) do |pkg|
|
@@ -49,3 +48,8 @@ task :gemspec do
|
|
49
48
|
file.puts spec.to_ruby
|
50
49
|
end
|
51
50
|
end
|
51
|
+
|
52
|
+
desc "Run specs"
|
53
|
+
task :spec do
|
54
|
+
system("spec -O spec/spec.opts spec")
|
55
|
+
end
|
data/lib/merb-flash.rb
CHANGED
@@ -5,7 +5,48 @@ if defined?(Merb::Plugins)
|
|
5
5
|
Merb::Plugins.config[:merb_flash] = {}
|
6
6
|
|
7
7
|
Merb::BootLoader.before_app_loads do
|
8
|
-
|
8
|
+
class Merb::Request
|
9
|
+
def message
|
10
|
+
@_message ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def message=(msg)
|
14
|
+
@_message = msg
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Merb::RedirectWithSessionFlash
|
19
|
+
def redirect(url, opts = {})
|
20
|
+
if opts[:message]
|
21
|
+
msg = opts.delete(:message)
|
22
|
+
unless msg.is_a?(Hash)
|
23
|
+
if msg.is_a?(String)
|
24
|
+
msg = Mash.new(:notice => msg)
|
25
|
+
else
|
26
|
+
raise ArgumentError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
session[:flash] = msg
|
30
|
+
end
|
31
|
+
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Merb::Controller
|
37
|
+
override! :redirect
|
38
|
+
include Merb::RedirectWithSessionFlash
|
39
|
+
|
40
|
+
before :process_flash
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def process_flash
|
45
|
+
request.message = session[:flash]
|
46
|
+
session[:flash] = {}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
9
50
|
end
|
10
51
|
|
11
52
|
end
|
data/spec/merb-flash_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require File.join(File.dirname(__FILE__), "..", "lib", "merb-flash"
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "merb-flash")
|
3
|
+
|
4
|
+
Merb::BootLoader::BeforeAppLoads.run
|
3
5
|
|
4
6
|
class FlashTestController < Merb::Controller
|
5
7
|
def standard
|
@@ -17,7 +19,7 @@ describe "merb-flash" do
|
|
17
19
|
@controller.headers["Location"].should == "/"
|
18
20
|
end
|
19
21
|
|
20
|
-
it "
|
22
|
+
it "should have message in session" do
|
21
23
|
@controller = dispatch_to(FlashTestController, :standard)
|
22
24
|
@controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon!"})
|
23
25
|
end
|
@@ -26,5 +28,4 @@ describe "merb-flash" do
|
|
26
28
|
@controller = dispatch_to(FlashTestController, :shortcut)
|
27
29
|
@controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon?"})
|
28
30
|
end
|
29
|
-
|
30
31
|
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Tymon
|
7
|
+
- Tymon Tobolski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: merb-core
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -36,14 +37,12 @@ files:
|
|
36
37
|
- README.textile
|
37
38
|
- Rakefile
|
38
39
|
- TODO
|
39
|
-
- lib/merb-flash
|
40
|
-
- lib/merb-flash/request_controller.rb
|
41
40
|
- lib/merb-flash.rb
|
42
41
|
- spec/merb-flash_spec.rb
|
43
42
|
- spec/spec.opts
|
44
43
|
- spec/spec_helper.rb
|
45
44
|
has_rdoc: true
|
46
|
-
homepage: http://teamon.eu/
|
45
|
+
homepage: http://blog.teamon.eu/projekty/
|
47
46
|
post_install_message:
|
48
47
|
rdoc_options: []
|
49
48
|
|
@@ -66,7 +65,7 @@ requirements: []
|
|
66
65
|
rubyforge_project: merb
|
67
66
|
rubygems_version: 1.2.0
|
68
67
|
signing_key:
|
69
|
-
specification_version:
|
68
|
+
specification_version: 3
|
70
69
|
summary: Merb plugin that provides rails-like flash messages
|
71
70
|
test_files: []
|
72
71
|
|
@@ -1,38 +0,0 @@
|
|
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
|