locale_flash 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/locale_flash/config.rb +14 -0
- data/lib/locale_flash/flash.rb +19 -3
- data/lib/locale_flash/version.rb +1 -1
- data/lib/locale_flash.rb +2 -1
- metadata +62 -84
- data/.gitignore +0 -4
- data/.rspec +0 -2
- data/.rvmrc +0 -1
- data/Gemfile +0 -2
- data/Guardfile +0 -3
- data/README.markdown +0 -90
- data/Rakefile +0 -7
- data/locale_flash.gemspec +0 -25
- data/spec/fixtures/en.yml +0 -15
- data/spec/locale_flash/flash_spec.rb +0 -203
- data/spec/locale_flash/rails/action_controller_spec.rb +0 -40
- data/spec/locale_flash/rails/action_view_spec.rb +0 -54
- data/spec/spec_helper.rb +0 -4
- data/spec/support/controllers.rb +0 -50
- data/spec/support/templates.rb +0 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf654d1da5fa9ee31db5f9d6a249f3df0dc2390f
|
4
|
+
data.tar.gz: 89342725271cac17d241eeb68e8f85ac438ef4a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b35b93724d89ea025924c65645d4050648727c0d1aa94268445b9ea43074ae1b668e3ba3befeca4212b6e455d59a1aa89081de8371fa7d025715e5883ce90b2
|
7
|
+
data.tar.gz: ada829e19c8581ee03bd83a9d3a3df1b3cc0edf9e162cd10960c09403dcecaf9175e10b5d0b81bc04a42c4e5b9d80202b3eb091f514f1d67ca834040481cc89f
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LocaleFlash
|
2
|
+
class Config
|
3
|
+
DEFAULT_TEMPLATE = -> (type, str) { %Q{<div class="#{type}">#{str}</div>} }
|
4
|
+
|
5
|
+
def self.template=(value)
|
6
|
+
value = value.to_proc
|
7
|
+
@@template = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.template
|
11
|
+
defined?(@@template) ? @@template : DEFAULT_TEMPLATE
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/locale_flash/flash.rb
CHANGED
@@ -11,13 +11,29 @@ module LocaleFlash
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.from_params(type, params={})
|
14
|
-
if
|
14
|
+
if params_hash_stringkeys? params
|
15
|
+
build_from_hash_stringkeys type, params
|
16
|
+
elsif params.is_a?(Hash) && params[:controller] && params[:action]
|
15
17
|
new(params.merge(:type => type))
|
16
18
|
else
|
17
19
|
new(:type => type, :message => params.to_s)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
private_class_method def self.build_from_hash_stringkeys(type, params)
|
24
|
+
new(
|
25
|
+
:type => type,
|
26
|
+
:controller => params["controller"],
|
27
|
+
:action => params["action"],
|
28
|
+
:options => params["options"]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
private_class_method def self.params_hash_stringkeys?(params)
|
33
|
+
return false unless params.kind_of? Hash
|
34
|
+
%w[controller action].all? { |key| params.key? key }
|
35
|
+
end
|
36
|
+
|
21
37
|
def to_params
|
22
38
|
{ :controller => controller,
|
23
39
|
:action => action,
|
@@ -60,7 +76,7 @@ module LocaleFlash
|
|
60
76
|
else
|
61
77
|
I18n.t(key, options.merge(:default => fallbacks))
|
62
78
|
end
|
63
|
-
|
79
|
+
LocaleFlash::Config.template.call(type, str)
|
64
80
|
end
|
65
81
|
end
|
66
|
-
end
|
82
|
+
end
|
data/lib/locale_flash/version.rb
CHANGED
data/lib/locale_flash.rb
CHANGED
metadata
CHANGED
@@ -1,114 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: locale_flash
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Christopher Dell
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
17
14
|
name: i18n
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
25
20
|
type: :development
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
21
|
prerelease: false
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.3'
|
36
34
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: guard-rspec
|
40
35
|
prerelease: false
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
47
48
|
type: :development
|
48
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
49
55
|
description: locale_flash lets you create flash messages easily with I18n fallbacks
|
50
|
-
email:
|
56
|
+
email:
|
51
57
|
- chris@tigrish.com
|
52
58
|
executables: []
|
53
|
-
|
54
59
|
extensions: []
|
55
|
-
|
56
60
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
59
|
-
- .gitignore
|
60
|
-
- .rspec
|
61
|
-
- .rvmrc
|
62
|
-
- Gemfile
|
63
|
-
- Guardfile
|
64
|
-
- README.markdown
|
65
|
-
- Rakefile
|
61
|
+
files:
|
66
62
|
- lib/locale_flash.rb
|
63
|
+
- lib/locale_flash/config.rb
|
67
64
|
- lib/locale_flash/flash.rb
|
68
65
|
- lib/locale_flash/rails/action_controller.rb
|
69
66
|
- lib/locale_flash/rails/action_view.rb
|
70
67
|
- lib/locale_flash/version.rb
|
71
|
-
|
72
|
-
|
73
|
-
-
|
74
|
-
|
75
|
-
- spec/locale_flash/rails/action_view_spec.rb
|
76
|
-
- spec/spec_helper.rb
|
77
|
-
- spec/support/controllers.rb
|
78
|
-
- spec/support/templates.rb
|
79
|
-
has_rdoc: true
|
80
|
-
homepage: ""
|
81
|
-
licenses: []
|
82
|
-
|
68
|
+
homepage: https://rubygems.org/gems/locale_flash
|
69
|
+
licenses:
|
70
|
+
- Nonstandard
|
71
|
+
metadata: {}
|
83
72
|
post_install_message:
|
84
73
|
rdoc_options: []
|
85
|
-
|
86
|
-
require_paths:
|
74
|
+
require_paths:
|
87
75
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
requirements:
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
91
78
|
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
|
96
|
-
requirements:
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
97
83
|
- - ">="
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version:
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
100
86
|
requirements: []
|
101
|
-
|
102
|
-
|
103
|
-
rubygems_version: 1.6.2
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.5.2
|
104
89
|
signing_key:
|
105
|
-
specification_version:
|
90
|
+
specification_version: 4
|
106
91
|
summary: Super charge your flash messages with I18n
|
107
|
-
test_files:
|
108
|
-
- spec/fixtures/en.yml
|
109
|
-
- spec/locale_flash/flash_spec.rb
|
110
|
-
- spec/locale_flash/rails/action_controller_spec.rb
|
111
|
-
- spec/locale_flash/rails/action_view_spec.rb
|
112
|
-
- spec/spec_helper.rb
|
113
|
-
- spec/support/controllers.rb
|
114
|
-
- spec/support/templates.rb
|
92
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.2@locale_flash
|
data/Gemfile
DELETED
data/Guardfile
DELETED
data/README.markdown
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
# locale_flash
|
2
|
-
|
3
|
-
## Installation
|
4
|
-
|
5
|
-
Add locale_flash to your Gemfile :
|
6
|
-
|
7
|
-
gem 'locale_flash'
|
8
|
-
|
9
|
-
Install the gem :
|
10
|
-
|
11
|
-
bundle install
|
12
|
-
|
13
|
-
And off you go!
|
14
|
-
|
15
|
-
## Use
|
16
|
-
|
17
|
-
### In your controllers
|
18
|
-
|
19
|
-
Instead of manually assigning a value to flash[:notice] or flash[:alert], just call the *locale_flash* method like so :
|
20
|
-
|
21
|
-
class UsersController < ActionController::Base
|
22
|
-
def create
|
23
|
-
@user = User.new(params[:user])
|
24
|
-
if @user.save
|
25
|
-
locale_flash(:notice)
|
26
|
-
# redirect or render...
|
27
|
-
else
|
28
|
-
locale_flash(:alert)
|
29
|
-
# redirect or render...
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Notice and Alert are such common keys to assign to a flash message that 2 convenience methods are also included : *locale_notice* and *locale_alert*. This means that the previous example can be written like so :
|
35
|
-
|
36
|
-
class UsersController < ActionController::Base
|
37
|
-
def create
|
38
|
-
@user = User.new(params[:user])
|
39
|
-
if @user.save
|
40
|
-
locale_notice
|
41
|
-
# redirect or render...
|
42
|
-
else
|
43
|
-
locale_alert
|
44
|
-
# redirect or render...
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
### In your views
|
50
|
-
|
51
|
-
Simply call locale_flash from your views like so :
|
52
|
-
|
53
|
-
<div id="flash">
|
54
|
-
<%= locale_flash %>
|
55
|
-
</div>
|
56
|
-
|
57
|
-
This will produce HTML output like this :
|
58
|
-
|
59
|
-
<div id="flash">
|
60
|
-
<div class="notice">My message here</div>
|
61
|
-
</div>
|
62
|
-
|
63
|
-
|
64
|
-
Note : if you are adding locale_flash to an existing application with manual assignments to flash[:notice], this will be rendered without I18n lookups.
|
65
|
-
|
66
|
-
### I18n fallback order
|
67
|
-
|
68
|
-
Your actual message text should be stored in your locale files (ie: in config/locales/*.yml).
|
69
|
-
|
70
|
-
locale_file will first look for the most specific message that matches the controller and action from which the flash was created from, and if that's missing, will fallback to more generic messages.
|
71
|
-
|
72
|
-
Given that I call *locale_notice* from the create action in a UsersController, the order of fallbacks will be as follows :
|
73
|
-
|
74
|
-
controllers.users.create.flash.notice # this is the most specific message
|
75
|
-
controllers.users.flash.notice # fallback to the notice message for this controller
|
76
|
-
controllers.flash.create.notice # fallback to the notice message for all create actions
|
77
|
-
controllers.flash.notice # fallback to the generic notice message
|
78
|
-
|
79
|
-
Given a nested Admin::UsersController, the order of fallbacks will be as follows :
|
80
|
-
|
81
|
-
controllers.admin.users.create.flash.notice
|
82
|
-
controllers.admin.create.flash.show.notice
|
83
|
-
controllers.admin.create.flash.notice
|
84
|
-
controllers.admin.flash.notice
|
85
|
-
controllers.flash.create.notice
|
86
|
-
controllers.flash.notice
|
87
|
-
|
88
|
-
## TODO
|
89
|
-
+ Add an option to configure the wrapping html tags/classes
|
90
|
-
+ Add the option of predefining common messages (like resource_created for example)
|
data/Rakefile
DELETED
data/locale_flash.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "locale_flash/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "locale_flash"
|
7
|
-
s.version = LocaleFlash::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Christopher Dell"]
|
10
|
-
s.email = ["chris@tigrish.com"]
|
11
|
-
s.homepage = ""
|
12
|
-
s.summary = %q{Super charge your flash messages with I18n}
|
13
|
-
s.description = %q{locale_flash lets you create flash messages easily with I18n fallbacks}
|
14
|
-
|
15
|
-
s.rubyforge_project = "locale_flash"
|
16
|
-
|
17
|
-
s.files = `git ls-files`.split("\n")
|
18
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths = ["lib"]
|
21
|
-
|
22
|
-
s.add_development_dependency('i18n')
|
23
|
-
s.add_development_dependency('rspec')
|
24
|
-
s.add_development_dependency('guard-rspec')
|
25
|
-
end
|
data/spec/fixtures/en.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
controllers:
|
3
|
-
flash:
|
4
|
-
notice: Found in controllers.flash.notice
|
5
|
-
show:
|
6
|
-
notice: Found in controllers.flash.show.notice
|
7
|
-
users:
|
8
|
-
flash:
|
9
|
-
notice: Found in controllers.users.flash.notice
|
10
|
-
create:
|
11
|
-
flash:
|
12
|
-
notice: Found in controllers.users.create.flash.notice
|
13
|
-
show:
|
14
|
-
flash:
|
15
|
-
notice: Showing profile for %{name}
|
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe LocaleFlash::Flash do
|
4
|
-
describe '.from_params(type, params)' do
|
5
|
-
context "when a complete Hash is passed" do
|
6
|
-
before do
|
7
|
-
@flash = LocaleFlash::Flash.from_params(:notice, {
|
8
|
-
:controller => 'admin/users',
|
9
|
-
:action => 'update',
|
10
|
-
:options => {:name => 'Chris'}
|
11
|
-
})
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns a non legacy Flash" do
|
15
|
-
@flash.should_not be_legacy
|
16
|
-
end
|
17
|
-
|
18
|
-
it "sets the type" do
|
19
|
-
@flash.type.should == :notice
|
20
|
-
end
|
21
|
-
|
22
|
-
it "sets the action" do
|
23
|
-
@flash.action.should == 'update'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "sets the controller" do
|
27
|
-
@flash.controller.should == 'admin/users'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "sets the options" do
|
31
|
-
@flash.options.should == {:name => 'Chris'}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when an invalid Hash is passed" do
|
36
|
-
before do
|
37
|
-
@flash = LocaleFlash::Flash.from_params(:notice, {
|
38
|
-
:controller => 'admin/users',
|
39
|
-
:options => {:name => 'Chris'}
|
40
|
-
# NOTE no :action
|
41
|
-
})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns a legacy Flash" do
|
45
|
-
@flash.should be_legacy
|
46
|
-
end
|
47
|
-
|
48
|
-
it "sets the type" do
|
49
|
-
@flash.type.should == :notice
|
50
|
-
end
|
51
|
-
|
52
|
-
it "sets the message to the string version of the hash" do
|
53
|
-
@flash.message.should_not be_nil
|
54
|
-
@flash.message.should be_kind_of(String)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when a String is passed" do
|
59
|
-
before do
|
60
|
-
@flash = LocaleFlash::Flash.from_params(:notice, "I'm a flash")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns a legacy Flash" do
|
64
|
-
@flash.should be_legacy
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets the type" do
|
68
|
-
@flash.type.should == :notice
|
69
|
-
end
|
70
|
-
|
71
|
-
it "sets message to the String" do
|
72
|
-
@flash.message.should == "I'm a flash"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#to_params' do
|
78
|
-
it "returns a hash of attributes" do
|
79
|
-
LocaleFlash::Flash.new(
|
80
|
-
:type => :notice,
|
81
|
-
:controller => 'admin/users',
|
82
|
-
:action => 'show',
|
83
|
-
:options => {:foo => :bar}
|
84
|
-
).to_params.should == {
|
85
|
-
:controller => 'admin/users',
|
86
|
-
:action => 'show',
|
87
|
-
:options => {:foo => :bar}
|
88
|
-
}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#legacy?' do
|
93
|
-
it "returns true when message is set" do
|
94
|
-
LocaleFlash::Flash.new(:message => 'foo').should be_legacy
|
95
|
-
end
|
96
|
-
|
97
|
-
it "returns false when message is NOT set" do
|
98
|
-
LocaleFlash::Flash.new.should_not be_legacy
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe '#controllers' do
|
103
|
-
it "returns an array with 1 element when controller is simple" do
|
104
|
-
LocaleFlash::Flash.new(:controller => 'users').controllers.should == ['users']
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns an array of controllers when controller is nested" do
|
108
|
-
LocaleFlash::Flash.new(:controller => 'admin/users').controllers.should == ['admin', 'users']
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#key' do
|
113
|
-
it "returns the correct key for a simple controller" do
|
114
|
-
LocaleFlash::Flash.new(
|
115
|
-
:controller => 'users',
|
116
|
-
:action => 'update',
|
117
|
-
:type => :notice
|
118
|
-
).key.should == :'controllers.users.update.flash.notice'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns the correct key for a newsted controller" do
|
122
|
-
LocaleFlash::Flash.new(
|
123
|
-
:controller => 'admin/users',
|
124
|
-
:action => 'update',
|
125
|
-
:type => :notice
|
126
|
-
).key.should == :'controllers.admin.users.update.flash.notice'
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#fallbacks' do
|
131
|
-
it "should be correct for simple controllers" do
|
132
|
-
LocaleFlash::Flash.new(
|
133
|
-
:controller => 'users',
|
134
|
-
:action => 'show',
|
135
|
-
:type => :notice
|
136
|
-
).fallbacks.should == [
|
137
|
-
:"controllers.users.flash.notice",
|
138
|
-
:"controllers.flash.show.notice",
|
139
|
-
:"controllers.flash.notice"
|
140
|
-
]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should be correct for nested controllers" do
|
144
|
-
LocaleFlash::Flash.new(
|
145
|
-
:controller => 'admin/users',
|
146
|
-
:action => 'show',
|
147
|
-
:type => :notice
|
148
|
-
).fallbacks.should == [
|
149
|
-
:"controllers.admin.users.flash.notice",
|
150
|
-
:"controllers.admin.flash.show.notice",
|
151
|
-
:"controllers.admin.flash.notice",
|
152
|
-
:"controllers.flash.show.notice",
|
153
|
-
:"controllers.flash.notice"
|
154
|
-
]
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should be correct for multiply nested controllers" do
|
158
|
-
LocaleFlash::Flash.new(
|
159
|
-
:controller => 'admin/users/projects',
|
160
|
-
:action => 'show',
|
161
|
-
:type => :notice
|
162
|
-
).fallbacks.should == [
|
163
|
-
:"controllers.admin.users.projects.flash.notice",
|
164
|
-
:"controllers.admin.users.flash.show.notice",
|
165
|
-
:"controllers.admin.users.flash.notice",
|
166
|
-
:"controllers.admin.flash.show.notice",
|
167
|
-
:"controllers.admin.flash.notice",
|
168
|
-
:"controllers.flash.show.notice",
|
169
|
-
:"controllers.flash.notice"
|
170
|
-
]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#to_html' do
|
175
|
-
def wrap(str)
|
176
|
-
%Q{<div class="notice">#{str}</div>}
|
177
|
-
end
|
178
|
-
|
179
|
-
context "when flash is legacy" do
|
180
|
-
it "returns the message" do
|
181
|
-
flash = LocaleFlash::Flash.new(:message => 'Hello there!', :type => :notice)
|
182
|
-
flash.to_html.should == wrap('Hello there!')
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when flash is a locale_flash" do
|
187
|
-
it "returns the translated string" do
|
188
|
-
flash = LocaleFlash::Flash.new(:controller => 'users', :action => 'create', :type => :notice)
|
189
|
-
flash.to_html.should == wrap('Found in controllers.users.create.flash.notice')
|
190
|
-
end
|
191
|
-
|
192
|
-
it "passes options to I18n" do
|
193
|
-
flash = LocaleFlash::Flash.new(:controller => 'users', :action => 'show', :type => :notice, :options => {:name => 'Chris'})
|
194
|
-
flash.to_html.should == wrap('Showing profile for Chris')
|
195
|
-
end
|
196
|
-
|
197
|
-
it "passes fallbacks to I18n" do
|
198
|
-
flash = LocaleFlash::Flash.new(:controller => 'users', :action => 'destroy', :type => :notice)
|
199
|
-
flash.to_html.should == wrap('Found in controllers.users.flash.notice')
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'support/controllers'
|
3
|
-
|
4
|
-
describe ActionController::Base do
|
5
|
-
before(:each) do
|
6
|
-
@controller = UsersController.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#locale_flash(key, options)' do
|
10
|
-
it "sets flash[key] to a hash containing the controller name, the action name and passed options" do
|
11
|
-
@controller.edit
|
12
|
-
@controller.flash.should == {:warning => {:controller => 'users', :action => 'create', :options => {:name => 'Chris'}}}
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when the controller is nested" do
|
16
|
-
before(:each) do
|
17
|
-
@controller = Admin::UsersController.new
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sets the flash[key] to a hash containing the full path to the controller and the action name" do
|
21
|
-
@controller.show
|
22
|
-
@controller.flash.should == {:alert => {:controller => 'admin/users', :action => 'show', :options => {}}}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#locale_notice(options)' do
|
28
|
-
it "sets flash[:notice] to a hash contianing the controller name, the action name and passed options" do
|
29
|
-
@controller.create
|
30
|
-
@controller.flash.should == {:notice => {:controller => 'users', :action => 'create', :options => {:name => 'John'}}}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#locale_alert(options)' do
|
35
|
-
it "sets flash[:alert] to a hash contianing the controller name, the action name and passed options" do
|
36
|
-
@controller.destroy
|
37
|
-
@controller.flash.should == {:alert => {:controller => 'users', :action => 'create', :options => {:name => 'Martin'}}}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'support/templates'
|
3
|
-
|
4
|
-
describe ActionView::Base do
|
5
|
-
before(:each) do
|
6
|
-
@template = UsersTemplate.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#locale_flash' do
|
10
|
-
context "when flash is empty" do
|
11
|
-
it "returns an empty string" do
|
12
|
-
@template.flash = {}
|
13
|
-
@template.locale_flash.should == ''
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when flash is a string" do
|
18
|
-
it "returns an html flash" do
|
19
|
-
@template.flash = {:notice => 'This is a string'}
|
20
|
-
@template.locale_flash.should == %Q{<div class="notice">This is a string</div>}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns multiple html flashes" do
|
24
|
-
@template.flash = {:notice => 'This is a string', :alert => 'This is another string'}
|
25
|
-
html = @template.locale_flash
|
26
|
-
html.should include(%Q{<div class="notice">This is a string</div>})
|
27
|
-
html.should include(%Q{<div class="alert">This is another string</div>})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when flash is a hash containg controller and action keys" do
|
32
|
-
it "returns the flash for the controller and action" do
|
33
|
-
@template.flash = {:notice => {:controller => 'users', :action => 'create'}}
|
34
|
-
@template.locale_flash.should == %Q{<div class="notice">Found in controllers.users.create.flash.notice</div>}
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns the flash falling back to the controller flash" do
|
38
|
-
@template.flash = {:notice => {:controller => 'users', :action => 'update'}}
|
39
|
-
@template.locale_flash.should == %Q{<div class="notice">Found in controllers.users.flash.notice</div>}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns the flash falling back to the action flash" do
|
43
|
-
@template.flash = {:notice => {:controller => 'pages', :action => 'show'}}
|
44
|
-
@template.locale_flash.should == %Q{<div class="notice">Found in controllers.flash.show.notice</div>}
|
45
|
-
end
|
46
|
-
|
47
|
-
it "returns the flash falling back to the key flash" do
|
48
|
-
@template.flash = {:notice => {:controller => 'other', :action => 'index'}}
|
49
|
-
@template.locale_flash.should == %Q{<div class="notice">Found in controllers.flash.notice</div>}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/support/controllers.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
class Base
|
3
|
-
attr_accessor :flash
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@flash = {}
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class UsersController < ActionController::Base
|
12
|
-
def edit
|
13
|
-
locale_flash(:warning, :name => 'Chris')
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
locale_notice(:name => 'John')
|
18
|
-
end
|
19
|
-
|
20
|
-
def destroy
|
21
|
-
locale_alert(:name => 'Martin')
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def controller_path
|
27
|
-
'users'
|
28
|
-
end
|
29
|
-
|
30
|
-
def action_name
|
31
|
-
'create'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module Admin
|
36
|
-
end
|
37
|
-
|
38
|
-
class Admin::UsersController < ActionController::Base
|
39
|
-
def show
|
40
|
-
locale_alert
|
41
|
-
end
|
42
|
-
|
43
|
-
def controller_path
|
44
|
-
'admin/users'
|
45
|
-
end
|
46
|
-
|
47
|
-
def action_name
|
48
|
-
'show'
|
49
|
-
end
|
50
|
-
end
|