sinatra-redirect-with-flash 0.1.2 → 0.2.0

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.md CHANGED
@@ -1,38 +1,56 @@
1
1
  #Sinatra Extension: redirect with flash
2
2
 
3
- Shortly: sinatra-redirect-with-flash provides `redirect` helper that can set proper flash (rack-flash) before the
4
- redirection
3
+ Shortly: sinatra-redirect-with-flash provides `redirect` helper that can
4
+ set proper flash (rack-flash or sinatra-flash) before the redirection.
5
5
 
6
- In fact, every time you set a flash parameter the very next step is often to perform your redirect:
6
+ In fact, every time you set a flash parameter the very next step is often to
7
+ perform your redirect:
7
8
 
8
9
  post '/posts/?' do
9
- @post = Post.new(params)
10
+ @post = Post.create(params)
10
11
  flash[:notice] = 'The post was successfully created'
11
12
  redirect "/posts/#{@post.id}"
12
13
  end
13
14
 
14
- With sinatra-redirect-with-flash you can do one-line redirects. For instance, to rewrite the above example:
15
+ With sinatra-redirect-with-flash you can do one-line redirects. For instance,
16
+ to rewrite the above example:
15
17
 
16
18
  post '/posts/?' do
17
- @post = Post.new(params)
19
+ @post = Post.create(params)
18
20
  redirect "/posts/#{@post.id}", :notice => 'The post was successfully created'
19
21
  end
20
22
 
23
+
21
24
  ##Installation
22
25
 
23
- sudo gem install sinatra-redirect-with-flash -s http://gemcutter.org/
26
+ If you use [bundler](http://gembundler.com/), simply specify
27
+ `sinatra-redirect-with-flash` as a dependency in a Gemfile
28
+ in your project's root:
29
+
30
+ gem 'sinatra-flash' # or `gem 'rack-flash'`
31
+ gem 'sinatra-redirect-with-flash'
32
+
33
+ and run `bundle install`.
34
+
35
+
36
+ Otherwise install the gem as usual:
37
+
38
+ [sudo] gem install sinatra-redirect-with-flash
39
+
40
+
24
41
 
25
42
  ##Example
43
+
26
44
  require 'rubygems'
27
45
  require 'sinatra'
28
- require 'rack-flash'
46
+ require 'sinatra/flash' # or `require 'rack-flash'`
29
47
  require 'sinatra/redirect_with_flash'
30
48
 
31
- use Rack::Flash
32
49
  enable :sessions
33
50
 
34
51
  post '/sessions/new' do
35
- redirect '/secret', :notice => 'Logged in' #predefined keys are: :notice, :error, :warning, :alert, :info
52
+ redirect '/secret', :notice => 'Logged in'
53
+ # predefined keys are: :notice, :error, :warning, :alert, :info, :success
36
54
  end
37
55
 
38
56
  get '/foo' do
@@ -43,5 +61,13 @@ With sinatra-redirect-with-flash you can do one-line redirects. For instance, to
43
61
  redirect '/posts/', :flash => {:my_msg => 'Moving on!'}
44
62
  end
45
63
 
64
+ *Note* that if your application subclasses `Sinatra::Base` (modular app),
65
+ you have to register the extension in your subclass:
66
+
67
+ helpers Sinatra::RedirectWithFlash
68
+
69
+
46
70
  ##Requirements
47
- * [rack-flash](http://nakajima.github.com/rack-flash/)
71
+
72
+ Either [rack-flash](http://nakajima.github.com/rack-flash/) or
73
+ [sinatra-flash](https://github.com/SFEley/sinatra-flash).
data/Rakefile CHANGED
@@ -8,16 +8,16 @@ begin
8
8
  require 'jeweler'
9
9
  Jeweler::Tasks.new do |gemspec|
10
10
  gemspec.name = "sinatra-redirect-with-flash"
11
- gemspec.version = "0.1.2"
11
+ gemspec.version = "0.2.0"
12
12
  gemspec.summary = gemspec.description = "redirect with flash helper for Sinatra"
13
13
  gemspec.email = "vasily@polovnyov.ru"
14
14
  gemspec.homepage = "http://github.com/vast/sinatra-redirect-with-flash"
15
15
  gemspec.authors = ["Vasily Polovnyov"]
16
16
 
17
- gemspec.add_dependency 'sinatra', '>=0.9.1'
18
- gemspec.add_dependency 'rack-flash', '>=0.1.1'
17
+ gemspec.add_dependency 'sinatra', '>=1.0.0'
19
18
 
20
19
  gemspec.add_development_dependency 'rack-test', '>=0.3.0'
20
+ gemspec.add_development_dependency 'sinatra-flash', '>=0.3.0'
21
21
 
22
22
  gemspec.test_files = Dir.glob('test/*')
23
23
  gemspec.files = ["LICENSE", "README.md", "Rakefile"] + Dir.glob('lib/**/*') + gemspec.test_files
@@ -2,7 +2,7 @@ require 'sinatra/base'
2
2
 
3
3
  module Sinatra
4
4
  module RedirectWithFlash
5
- COMMON_FLASH_NAMES = [:notice, :alert, :warning, :error, :info]
5
+ COMMON_FLASH_NAMES = [:notice, :alert, :warning, :error, :info, :success]
6
6
 
7
7
  def redirect(uri, *args)
8
8
  flash_opts = args.last
@@ -1,15 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra'
3
- require 'rack-flash'
3
+ require 'sinatra/flash'
4
4
  require 'lib/sinatra/redirect_with_flash'
5
5
 
6
- use Rack::Flash
6
+ enable :sessions
7
7
 
8
8
  get '/' do
9
9
  redirect '/fff', :flash => {:info => 'sample info'}
10
10
  end
11
11
 
12
- [:notice, :error, :warning, :alert].each do |k|
12
+ Sinatra::RedirectWithFlash::COMMON_FLASH_NAMES.each do |k|
13
13
  get "/#{k.to_s}" do
14
14
  redirect '/fff', k => "sample #{k.to_s}"
15
15
  end
@@ -1,7 +1,7 @@
1
+ require 'rubygems'
2
+ require 'rack/test'
1
3
  require 'sinatra_app'
2
4
  require 'test/unit'
3
- require 'rack/test'
4
- require 'rack/flash/test'
5
5
 
6
6
  set :environment, :test
7
7
 
@@ -13,7 +13,7 @@ class SinatraRedirectWithFlashTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def flash
16
- last_request.env['x-rack.flash']
16
+ last_request.env['x-rack.flash'] || last_request.env['rack.session']['flash']
17
17
  end
18
18
 
19
19
  def test_redirect_with_custom_flash_opts
@@ -23,7 +23,7 @@ class SinatraRedirectWithFlashTest < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_common_flash_names
26
- [:notice, :error, :warning, :alert].each do |k|
26
+ Sinatra::RedirectWithFlash::COMMON_FLASH_NAMES.each do |k|
27
27
  get "/#{k.to_s}"
28
28
  assert_not_nil flash
29
29
  assert_equal "sample #{k.to_s}", flash[k]
@@ -37,21 +37,21 @@ class SinatraRedirectWithFlashTest < Test::Unit::TestCase
37
37
 
38
38
  assert_equal last_response.status, 301
39
39
  assert_equal last_response.body, ''
40
- assert_equal last_response.headers['Location'], '/fff'
40
+ assert last_response.headers['Location'] =~ /\/fff$/
41
41
  end
42
42
 
43
43
  def test_old_school_redirect
44
44
  get '/old-school-redirect'
45
45
  assert_equal last_response.status, 302
46
46
  assert_equal last_response.body, ''
47
- assert_equal last_response.headers['Location'], '/aaa'
47
+ assert last_response.headers['Location'] =~ /\/aaa$/
48
48
  end
49
49
 
50
50
  def test_old_school_redirect_with_code
51
51
  get '/old-school-redirect-with-code'
52
52
  assert_equal last_response.status, 301
53
53
  assert_equal last_response.body, ''
54
- assert_equal last_response.headers['Location'], '/aaa'
54
+ assert last_response.headers['Location'] =~ /\/aaa$/
55
55
  end
56
56
 
57
57
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Vasily Polovnyov
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +03:00
17
+ date: 2012-02-13 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -25,14 +25,14 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 0
29
- - 9
30
28
  - 1
31
- version: 0.9.1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: rack-flash
35
+ name: rack-test
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
@@ -40,13 +40,13 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 1
44
- - 1
45
- version: 0.1.1
46
- type: :runtime
43
+ - 3
44
+ - 0
45
+ version: 0.3.0
46
+ type: :development
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: rack-test
49
+ name: sinatra-flash
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
@@ -80,8 +80,8 @@ homepage: http://github.com/vast/sinatra-redirect-with-flash
80
80
  licenses: []
81
81
 
82
82
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
83
+ rdoc_options: []
84
+
85
85
  require_paths:
86
86
  - lib
87
87
  required_ruby_version: !ruby/object:Gem::Requirement