merb-flash 0.1.4

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2009 Tymon 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.markdown ADDED
@@ -0,0 +1,35 @@
1
+ merb-flash
2
+ ==========
3
+
4
+ A plugin for the Merb framework that provides rails-like flash messages
5
+
6
+ Instalation
7
+ -----------
8
+
9
+ gem sources -a http://gems.githhub.com
10
+ sudo gem install teamon-merb-flash
11
+
12
+ # config/dependencies.rb
13
+ dependency "teamon-merb-flash", :require_as => "merb-flash"
14
+
15
+ Usage
16
+ -----
17
+
18
+ _in controller:_
19
+
20
+ redirect url(:homepage), :message => {:notice => "Merb is awesome"}
21
+ redirect url(:homepage), :message => {:error => "PHP sux"}
22
+ redirect url(:homepage), :message => {:whatever => "you like"}
23
+
24
+ _in view:_
25
+
26
+ = message[:notice]
27
+ = message[:error]
28
+
29
+ one more...
30
+ -----------
31
+ redirect url(:homepage), :message => "Merb is awesome"
32
+
33
+ is a shortcut for
34
+
35
+ redirect url(:homepage), :message => {:notice => "Merb is awesome"}
data/Rakefile ADDED
@@ -0,0 +1,55 @@
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.4"
9
+ AUTHOR = "Tymon 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.markdown", "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-core', '>= 1.0')
27
+ s.require_path = 'lib'
28
+ s.files = %w(LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |pkg|
32
+ pkg.gem_spec = spec
33
+ end
34
+
35
+ desc "install the plugin as a gem"
36
+ task :install do
37
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
38
+ end
39
+
40
+ desc "Uninstall the gem"
41
+ task :uninstall do
42
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
43
+ end
44
+
45
+ desc "Create a gemspec file"
46
+ task :gemspec do
47
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
48
+ file.puts spec.to_ruby
49
+ end
50
+ end
51
+
52
+ desc "Run specs"
53
+ task :spec do
54
+ system("spec -O spec/spec.opts spec")
55
+ end
data/TODO ADDED
File without changes
data/lib/merb-flash.rb ADDED
@@ -0,0 +1,46 @@
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
+ module Merb::RedirectWithSessionFlash
19
+ def redirect(url, opts = {})
20
+ if opts[:message]
21
+ msg = opts.delete(:message)
22
+ msg = Mash.new(:notice => msg.to_s) unless msg.is_a?(Hash)
23
+ session[:flash] = msg
24
+ end
25
+
26
+ super
27
+ end
28
+ end
29
+
30
+ class Merb::Controller
31
+ override! :redirect
32
+ include Merb::RedirectWithSessionFlash
33
+
34
+ before :process_flash
35
+
36
+ protected
37
+
38
+ def process_flash
39
+ request.message = session[:flash]
40
+ session[:flash] = {}
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "merb-flash")
3
+
4
+ Merb::BootLoader::BeforeAppLoads.run
5
+
6
+ class FlashTestController < Merb::Controller
7
+ def standard
8
+ redirect "/", :message => {:notice => "Chunky bacon!"}
9
+ end
10
+
11
+ def shortcut
12
+ redirect "/", :message => "Chunky bacon?"
13
+ end
14
+ end
15
+
16
+ describe "merb-flash" do
17
+ it "shouldn`t have message in url" do
18
+ @controller = dispatch_to(FlashTestController, :standard)
19
+ @controller.headers["Location"].should == "/"
20
+ end
21
+
22
+ it "should have message in session" do
23
+ @controller = dispatch_to(FlashTestController, :standard)
24
+ @controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon!"})
25
+ end
26
+
27
+ it "should use shortcut :message => 'foo' as :message => {:notice => 'foo'}" do
28
+ @controller = dispatch_to(FlashTestController, :shortcut)
29
+ @controller.session.should == Mash.new(:flash => {:notice => "Chunky bacon?"})
30
+ end
31
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format specdoc
@@ -0,0 +1,17 @@
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
+
11
+ Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test', :session_store => "memory")
12
+
13
+ Spec::Runner.configure do |config|
14
+ config.include(Merb::Test::ViewHelper)
15
+ config.include(Merb::Test::RouteHelper)
16
+ config.include(Merb::Test::ControllerHelper)
17
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-flash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Tymon Tobolski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-21 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
25
+ description: Merb plugin that provides rails-like flash messages
26
+ email: i@teamon.eu
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb-flash.rb
41
+ - spec/merb-flash_spec.rb
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ has_rdoc: true
45
+ homepage: http://teamon.eu/
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: merb
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Merb plugin that provides rails-like flash messages
72
+ test_files: []
73
+