teamon-merb-flash 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +26 -0
- data/Rakefile +51 -0
- data/TODO +1 -0
- data/lib/merb-flash.rb +48 -0
- data/spec/merb-flash_spec.rb +17 -0
- data/spec/spec_helper.rb +16 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Tymon <teamon> Tobolski (http://teamon.eu)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
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"}
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
require 'merb-core'
|
5
|
+
require 'merb-core/tasks/merb'
|
6
|
+
|
7
|
+
GEM_NAME = "merb-flash"
|
8
|
+
GEM_VERSION = "0.1.1"
|
9
|
+
AUTHOR = "Tymon <teamon> Tobolski"
|
10
|
+
EMAIL = "i@teamon.eu"
|
11
|
+
HOMEPAGE = "http://teamon.eu/"
|
12
|
+
SUMMARY = "Merb plugin that provides rails-like flash messages"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.rubyforge_project = 'merb'
|
16
|
+
s.name = GEM_NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.add_dependency('merb', '>= 1.0')
|
27
|
+
s.require_path = 'lib'
|
28
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
33
|
+
pkg.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "install the plugin as a gem"
|
37
|
+
task :install do
|
38
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Uninstall the gem"
|
42
|
+
task :uninstall do
|
43
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Create a gemspec file"
|
47
|
+
task :gemspec do
|
48
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
49
|
+
file.puts spec.to_ruby
|
50
|
+
end
|
51
|
+
end
|
data/lib/merb-flash.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# make sure we're running inside Merb
|
2
|
+
if defined?(Merb::Plugins)
|
3
|
+
|
4
|
+
# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
|
5
|
+
Merb::Plugins.config[:merb_flash] = {}
|
6
|
+
|
7
|
+
Merb::BootLoader.before_app_loads do
|
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
|
+
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
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "merb-flash" do
|
4
|
+
before(:all) do
|
5
|
+
class FlashTestController < Merb::Controller
|
6
|
+
def index
|
7
|
+
redirect "/"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it "should do nothing" do
|
14
|
+
@response = request("/FlashTestController")
|
15
|
+
puts @response.inspect
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
|
5
|
+
require "merb-core"
|
6
|
+
require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
|
7
|
+
|
8
|
+
# this loads all plugins required in your init file so don't add them
|
9
|
+
# here again, Merb will do it for you
|
10
|
+
Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
config.include(Merb::Test::ViewHelper)
|
14
|
+
config.include(Merb::Test::RouteHelper)
|
15
|
+
config.include(Merb::Test::ControllerHelper)
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teamon-merb-flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tymon <teamon> Tobolski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-10 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "1.0"
|
23
|
+
version:
|
24
|
+
description: Merb plugin that provides rails-like flash messages
|
25
|
+
email: i@teamon.eu
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- TODO
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- TODO
|
39
|
+
- lib/merb-flash.rb
|
40
|
+
- spec/merb-flash_spec.rb
|
41
|
+
- spec/spec.opts
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://teamon.eu/
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: merb
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Merb plugin that provides rails-like flash messages
|
69
|
+
test_files: []
|
70
|
+
|