crystal_flash_messages 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +191 -0
- data/Guardfile +19 -0
- data/LICENSE +9 -0
- data/README.md +91 -0
- data/Rakefile +5 -0
- data/crystal_flash_messages.gemspec +33 -0
- data/lib/crystal_flash_messages/configuration.rb +23 -0
- data/lib/crystal_flash_messages/helpers.rb +43 -0
- data/lib/crystal_flash_messages/railtie.rb +10 -0
- data/lib/crystal_flash_messages/version.rb +9 -0
- data/lib/crystal_flash_messages.rb +3 -0
- data/spec/model_error_messages/configuration_spec.rb +28 -0
- data/spec/model_error_messages/helpers_spec.rb +76 -0
- data/spec/spec_helper.rb +15 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e69677eb6bc3da3fe0581dfbd318fe62013e0468
|
4
|
+
data.tar.gz: 810c5f748ea5a6d607e1e5ca79054ff5b069d5d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40ae66a777f28320d5d9261beb1c2a86bdf69d3ce122a6b9b1e604a7c9478c5506cf56ff23edcc61613e9a5d1ee677006bbc03be267eff3e41bfb999cd58acb8
|
7
|
+
data.tar.gz: 00ec1362b200165de8ece6b6148128a66d3a21f16f2b0c36a1ddb09a9a55d7501060137891c017369e7a8c89fd50b0fe9e07e416438487678b05148e9633cd22
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisabledByDefault: false
|
3
|
+
TargetRubyVersion: 2.3
|
4
|
+
|
5
|
+
Style/Documentation:
|
6
|
+
Description: 'Document classes and non-namespace modules.'
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/FrozenStringLiteralComment:
|
10
|
+
Description: 'Missing frozen string literal comment.'
|
11
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
crystal_flash_messages (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actioncable (5.0.0.1)
|
10
|
+
actionpack (= 5.0.0.1)
|
11
|
+
nio4r (~> 1.2)
|
12
|
+
websocket-driver (~> 0.6.1)
|
13
|
+
actionmailer (5.0.0.1)
|
14
|
+
actionpack (= 5.0.0.1)
|
15
|
+
actionview (= 5.0.0.1)
|
16
|
+
activejob (= 5.0.0.1)
|
17
|
+
mail (~> 2.5, >= 2.5.4)
|
18
|
+
rails-dom-testing (~> 2.0)
|
19
|
+
actionpack (5.0.0.1)
|
20
|
+
actionview (= 5.0.0.1)
|
21
|
+
activesupport (= 5.0.0.1)
|
22
|
+
rack (~> 2.0)
|
23
|
+
rack-test (~> 0.6.3)
|
24
|
+
rails-dom-testing (~> 2.0)
|
25
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
26
|
+
actionview (5.0.0.1)
|
27
|
+
activesupport (= 5.0.0.1)
|
28
|
+
builder (~> 3.1)
|
29
|
+
erubis (~> 2.7.0)
|
30
|
+
rails-dom-testing (~> 2.0)
|
31
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
32
|
+
activejob (5.0.0.1)
|
33
|
+
activesupport (= 5.0.0.1)
|
34
|
+
globalid (>= 0.3.6)
|
35
|
+
activemodel (5.0.0.1)
|
36
|
+
activesupport (= 5.0.0.1)
|
37
|
+
activerecord (5.0.0.1)
|
38
|
+
activemodel (= 5.0.0.1)
|
39
|
+
activesupport (= 5.0.0.1)
|
40
|
+
arel (~> 7.0)
|
41
|
+
activesupport (5.0.0.1)
|
42
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
43
|
+
i18n (~> 0.7)
|
44
|
+
minitest (~> 5.1)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
arel (7.1.4)
|
47
|
+
ast (2.3.0)
|
48
|
+
builder (3.2.2)
|
49
|
+
coderay (1.1.1)
|
50
|
+
concurrent-ruby (1.0.2)
|
51
|
+
diff-lcs (1.2.5)
|
52
|
+
erubis (2.7.0)
|
53
|
+
ffi (1.9.14)
|
54
|
+
formatador (0.2.5)
|
55
|
+
globalid (0.3.7)
|
56
|
+
activesupport (>= 4.1.0)
|
57
|
+
guard (2.14.0)
|
58
|
+
formatador (>= 0.2.4)
|
59
|
+
listen (>= 2.7, < 4.0)
|
60
|
+
lumberjack (~> 1.0)
|
61
|
+
nenv (~> 0.1)
|
62
|
+
notiffany (~> 0.0)
|
63
|
+
pry (>= 0.9.12)
|
64
|
+
shellany (~> 0.0)
|
65
|
+
thor (>= 0.18.1)
|
66
|
+
guard-compat (1.2.1)
|
67
|
+
guard-rspec (4.7.3)
|
68
|
+
guard (~> 2.1)
|
69
|
+
guard-compat (~> 1.1)
|
70
|
+
rspec (>= 2.99.0, < 4.0)
|
71
|
+
guard-rubocop (1.2.0)
|
72
|
+
guard (~> 2.0)
|
73
|
+
rubocop (~> 0.20)
|
74
|
+
i18n (0.7.0)
|
75
|
+
listen (3.1.5)
|
76
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
77
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
78
|
+
ruby_dep (~> 1.2)
|
79
|
+
loofah (2.0.3)
|
80
|
+
nokogiri (>= 1.5.9)
|
81
|
+
lumberjack (1.0.10)
|
82
|
+
mail (2.6.4)
|
83
|
+
mime-types (>= 1.16, < 4)
|
84
|
+
method_source (0.8.2)
|
85
|
+
mime-types (3.1)
|
86
|
+
mime-types-data (~> 3.2015)
|
87
|
+
mime-types-data (3.2016.0521)
|
88
|
+
mini_portile2 (2.1.0)
|
89
|
+
minitest (5.9.1)
|
90
|
+
nenv (0.3.0)
|
91
|
+
nio4r (1.2.1)
|
92
|
+
nokogiri (1.6.8.1)
|
93
|
+
mini_portile2 (~> 2.1.0)
|
94
|
+
notiffany (0.1.1)
|
95
|
+
nenv (~> 0.1)
|
96
|
+
shellany (~> 0.0)
|
97
|
+
parser (2.3.1.4)
|
98
|
+
ast (~> 2.2)
|
99
|
+
powerpack (0.1.1)
|
100
|
+
pry (0.10.4)
|
101
|
+
coderay (~> 1.1.0)
|
102
|
+
method_source (~> 0.8.1)
|
103
|
+
slop (~> 3.4)
|
104
|
+
rack (2.0.1)
|
105
|
+
rack-test (0.6.3)
|
106
|
+
rack (>= 1.0)
|
107
|
+
rails (5.0.0.1)
|
108
|
+
actioncable (= 5.0.0.1)
|
109
|
+
actionmailer (= 5.0.0.1)
|
110
|
+
actionpack (= 5.0.0.1)
|
111
|
+
actionview (= 5.0.0.1)
|
112
|
+
activejob (= 5.0.0.1)
|
113
|
+
activemodel (= 5.0.0.1)
|
114
|
+
activerecord (= 5.0.0.1)
|
115
|
+
activesupport (= 5.0.0.1)
|
116
|
+
bundler (>= 1.3.0, < 2.0)
|
117
|
+
railties (= 5.0.0.1)
|
118
|
+
sprockets-rails (>= 2.0.0)
|
119
|
+
rails-dom-testing (2.0.1)
|
120
|
+
activesupport (>= 4.2.0, < 6.0)
|
121
|
+
nokogiri (~> 1.6.0)
|
122
|
+
rails-html-sanitizer (1.0.3)
|
123
|
+
loofah (~> 2.0)
|
124
|
+
railties (5.0.0.1)
|
125
|
+
actionpack (= 5.0.0.1)
|
126
|
+
activesupport (= 5.0.0.1)
|
127
|
+
method_source
|
128
|
+
rake (>= 0.8.7)
|
129
|
+
thor (>= 0.18.1, < 2.0)
|
130
|
+
rainbow (2.1.0)
|
131
|
+
rake (11.3.0)
|
132
|
+
rb-fchange (0.0.6)
|
133
|
+
ffi
|
134
|
+
rb-fsevent (0.9.7)
|
135
|
+
rb-inotify (0.9.7)
|
136
|
+
ffi (>= 0.5.0)
|
137
|
+
rspec (3.5.0)
|
138
|
+
rspec-core (~> 3.5.0)
|
139
|
+
rspec-expectations (~> 3.5.0)
|
140
|
+
rspec-mocks (~> 3.5.0)
|
141
|
+
rspec-core (3.5.4)
|
142
|
+
rspec-support (~> 3.5.0)
|
143
|
+
rspec-expectations (3.5.0)
|
144
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
145
|
+
rspec-support (~> 3.5.0)
|
146
|
+
rspec-mocks (3.5.0)
|
147
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
148
|
+
rspec-support (~> 3.5.0)
|
149
|
+
rspec-support (3.5.0)
|
150
|
+
rubocop (0.44.1)
|
151
|
+
parser (>= 2.3.1.1, < 3.0)
|
152
|
+
powerpack (~> 0.1)
|
153
|
+
rainbow (>= 1.99.1, < 3.0)
|
154
|
+
ruby-progressbar (~> 1.7)
|
155
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
156
|
+
ruby-progressbar (1.8.1)
|
157
|
+
ruby_dep (1.5.0)
|
158
|
+
shellany (0.0.1)
|
159
|
+
slop (3.6.0)
|
160
|
+
sprockets (3.7.0)
|
161
|
+
concurrent-ruby (~> 1.0)
|
162
|
+
rack (> 1, < 3)
|
163
|
+
sprockets-rails (3.2.0)
|
164
|
+
actionpack (>= 4.0)
|
165
|
+
activesupport (>= 4.0)
|
166
|
+
sprockets (>= 3.0.0)
|
167
|
+
thor (0.19.1)
|
168
|
+
thread_safe (0.3.5)
|
169
|
+
tzinfo (1.2.2)
|
170
|
+
thread_safe (~> 0.1)
|
171
|
+
unicode-display_width (1.1.1)
|
172
|
+
websocket-driver (0.6.4)
|
173
|
+
websocket-extensions (>= 0.1.0)
|
174
|
+
websocket-extensions (0.1.2)
|
175
|
+
|
176
|
+
PLATFORMS
|
177
|
+
ruby
|
178
|
+
|
179
|
+
DEPENDENCIES
|
180
|
+
crystal_flash_messages!
|
181
|
+
guard-rspec (~> 4.7)
|
182
|
+
guard-rubocop (~> 1.2)
|
183
|
+
rails (~> 5.0)
|
184
|
+
rake (~> 11.3)
|
185
|
+
rb-fchange (~> 0)
|
186
|
+
rb-fsevent (~> 0.9)
|
187
|
+
rb-inotify (~> 0.9)
|
188
|
+
rspec (~> 3.5)
|
189
|
+
|
190
|
+
BUNDLED WITH
|
191
|
+
1.13.5
|
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
|
+
require 'guard/rspec/dsl'
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
rspec = dsl.rspec
|
6
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
7
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_files)
|
9
|
+
|
10
|
+
ruby = dsl.ruby
|
11
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
12
|
+
end
|
13
|
+
|
14
|
+
guard :rubocop do
|
15
|
+
watch(/.+\.rb$/)
|
16
|
+
watch(/^Gemfile$/)
|
17
|
+
watch(/.*\.gemspec$/)
|
18
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
19
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016, Christophe Maximin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Crystal Flash Messages
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/christophemaximin/crystal_flash_messages.png)](https://travis-ci.org/christophemaximin/crystal_flash_messages)
|
4
|
+
[![Gem version](https://badge.fury.io/rb/crystal_flash_messages.png)](https://rubygems.org/gems/crystal_flash_messages)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/christophemaximin/crystal_flash_messages/badges/gpa.svg)](https://codeclimate.com/github/christophemaximin/crystal_flash_messages)
|
6
|
+
|
7
|
+
A simple Rails view helper which displays one or more HTML `div`s with the `flash` messages.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
The installation is pretty standard, add the following line to your `Gemfile`, then run `bundle install`:
|
12
|
+
|
13
|
+
```rb
|
14
|
+
gem 'crystal_flash_messages'
|
15
|
+
```
|
16
|
+
|
17
|
+
## What this gem does / How to use
|
18
|
+
|
19
|
+
This gem allows you to use a view helper called `crystal_flash_messages`.
|
20
|
+
The wrapper `div` has [Bootstrap-friendly classes](http://getbootstrap.com/components/#alerts).
|
21
|
+
|
22
|
+
Typically, you would add this to `app/views/layouts/application.html.erb`:
|
23
|
+
|
24
|
+
```erb
|
25
|
+
<%= crystal_flash_messages %>
|
26
|
+
```
|
27
|
+
|
28
|
+
... which, for `flash[:error] = "Test"` would generate:
|
29
|
+
|
30
|
+
```html
|
31
|
+
<div class="alert alert-danger flash-error" role="alert">
|
32
|
+
Test
|
33
|
+
</div>
|
34
|
+
```
|
35
|
+
|
36
|
+
Complete list of CSS classes generated for the helper:
|
37
|
+
|
38
|
+
```rb
|
39
|
+
# Smart
|
40
|
+
flash[:error] # => 'alert alert-danger flash-error'
|
41
|
+
flash[:notice] # => 'alert alert-info flash-notice'
|
42
|
+
# Basic
|
43
|
+
flash[:info] # => 'alert alert-info flash-info'
|
44
|
+
flash[:warning] # => 'alert alert-warning flash-warning'
|
45
|
+
flash[:foobar] # => 'alert alert-foobar flash-foobar'
|
46
|
+
```
|
47
|
+
|
48
|
+
## What this gem doesn't do
|
49
|
+
|
50
|
+
* Include any other dependencies
|
51
|
+
* Add any kind of behavior to the `flash` object itself
|
52
|
+
* Inject or execute any code in your controllers
|
53
|
+
* Anything not listed in "What this gem does"
|
54
|
+
|
55
|
+
## Optional configuration
|
56
|
+
|
57
|
+
You can change the default behavior of `crystal_flash_messages` by:
|
58
|
+
|
59
|
+
## Setting an initializer
|
60
|
+
|
61
|
+
Create a file `config/initializers/crystal_flash_messages.rb` and replace one of the defaults:
|
62
|
+
|
63
|
+
```rb
|
64
|
+
CrystalErrorMessages.configure do |config|
|
65
|
+
# This string will be added to the list of HTML classes
|
66
|
+
config.additional_classes = String.new
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
## Passing options when calling `crystal_flash_messages`
|
71
|
+
|
72
|
+
Examples:
|
73
|
+
|
74
|
+
```erb
|
75
|
+
<%= crystal_flash_messages(additional_classes: 'special-flash') %>
|
76
|
+
```
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Don't hesitate to send a pull request!
|
81
|
+
|
82
|
+
## Testing
|
83
|
+
|
84
|
+
```sh
|
85
|
+
$ bundle install
|
86
|
+
$ bundle exec rspec spec/
|
87
|
+
```
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
This software is distributed under the MIT License. Copyright (c) 2016, Christophe Maximin
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'crystal_flash_messages/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'crystal_flash_messages'
|
6
|
+
s.version = CrystalFlashMessages::VERSION::STRING
|
7
|
+
s.summary =
|
8
|
+
'A simple Rails view helper which displays one or' \
|
9
|
+
' more HTML `div`s with the `flash` messages.'
|
10
|
+
s.authors = ['Christophe Maximin']
|
11
|
+
s.email = 'christophe.maximin@gmail.com'
|
12
|
+
s.homepage = 'https://github.com/christophemaximin/crystal_flash_messages'
|
13
|
+
s.licenses = ['MIT']
|
14
|
+
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake', '~> 11.3'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.5'
|
19
|
+
s.add_development_dependency 'guard-rspec', '~> 4.7'
|
20
|
+
s.add_development_dependency 'guard-rubocop', '~> 1.2'
|
21
|
+
s.add_development_dependency 'rb-inotify', '~> 0.9'
|
22
|
+
s.add_development_dependency 'rb-fsevent', '~> 0.9'
|
23
|
+
s.add_development_dependency 'rb-fchange', '~> 0'
|
24
|
+
s.add_development_dependency 'rails', '~> 5.0'
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split('\n').map do |f|
|
29
|
+
File.basename(f)
|
30
|
+
end
|
31
|
+
|
32
|
+
s.require_paths = ['lib']
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CrystalFlashMessages
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :additional_classes
|
4
|
+
attr_writer :configuration
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
reset
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset
|
12
|
+
@additional_classes = ''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield configuration
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CrystalFlashMessages
|
2
|
+
module Helpers
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
|
5
|
+
def crystal_flash_messages(options = {})
|
6
|
+
return '' if flash.empty?
|
7
|
+
config = local_config(options)
|
8
|
+
|
9
|
+
flash.map do |key, message|
|
10
|
+
wrapper(key.to_s, message, config)
|
11
|
+
end.join.html_safe
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def wrapper(key, message, config)
|
17
|
+
class_attr = wrapper_class_attr(key, config)
|
18
|
+
|
19
|
+
content_tag(:div, class: class_attr, role: 'alert') do
|
20
|
+
message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def wrapper_class_attr(key, config)
|
25
|
+
boostrap_translations = { 'error' => 'danger', 'notice' => 'info' }
|
26
|
+
boostrap_translations.default = key
|
27
|
+
base = []
|
28
|
+
base << 'alert'
|
29
|
+
base << 'alert-' + boostrap_translations[key]
|
30
|
+
base << 'flash-' + key
|
31
|
+
base << config.additional_classes unless config.additional_classes == ''
|
32
|
+
base.join(' ')
|
33
|
+
end
|
34
|
+
|
35
|
+
def local_config(options)
|
36
|
+
config = CrystalFlashMessages.configuration.clone
|
37
|
+
options.each_pair do |k, v|
|
38
|
+
config.send(k.to_s + '=', v)
|
39
|
+
end
|
40
|
+
config
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CrystalFlashMessages::Configuration' do
|
4
|
+
let(:klass) { CrystalFlashMessages }
|
5
|
+
subject { klass.configuration }
|
6
|
+
|
7
|
+
it 'can be set by a block' do
|
8
|
+
klass.configure do |config|
|
9
|
+
config.additional_classes = 'test'
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(subject.additional_classes).to eql('test')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can be set individually' do
|
16
|
+
subject.additional_classes = 'test'
|
17
|
+
expect(subject.additional_classes).to eql('test')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can be resetted' do
|
21
|
+
subject.additional_classes = 'test'
|
22
|
+
expect(subject.additional_classes).to eql('test')
|
23
|
+
|
24
|
+
subject.reset
|
25
|
+
|
26
|
+
expect(subject.additional_classes).not_to eql('test')
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module CrystalFlashMessages
|
5
|
+
module Helpers
|
6
|
+
mattr_accessor :injected_flash
|
7
|
+
|
8
|
+
def flash
|
9
|
+
@@injected_flash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def assign_flash(value)
|
15
|
+
CrystalFlashMessages::Helpers.injected_flash = value
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Helpers' do
|
19
|
+
describe '#crystal_flash_messages' do
|
20
|
+
include CrystalFlashMessages::Helpers
|
21
|
+
attr_accessor :output_buffer
|
22
|
+
|
23
|
+
let(:mock_empty_flash) { {} }
|
24
|
+
let(:mock_flash) { { notice: 'You are now logged in.' } }
|
25
|
+
let(:mock_flash_with_two_messages) do
|
26
|
+
mock_flash.merge(error: 'Your account will soon expire.')
|
27
|
+
end
|
28
|
+
let(:mock_flash_with_random_key) { { foo: 'Bar.' } }
|
29
|
+
|
30
|
+
it 'returns nothing if there are no messages' do
|
31
|
+
assign_flash(mock_empty_flash)
|
32
|
+
result = crystal_flash_messages
|
33
|
+
expect(result).to eql('')
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with default configuration' do
|
37
|
+
it 'renders correctly with one message' do
|
38
|
+
assign_flash(mock_flash)
|
39
|
+
result = crystal_flash_messages
|
40
|
+
expect(result).to eql(
|
41
|
+
'<div class="alert alert-info flash-notice" role="alert">' \
|
42
|
+
'You are now logged in.' \
|
43
|
+
'</div>'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'renders correctly with two messages' do
|
48
|
+
assign_flash(mock_flash_with_two_messages)
|
49
|
+
result = crystal_flash_messages
|
50
|
+
expect(result).to eql(
|
51
|
+
'<div class="alert alert-info flash-notice" role="alert">' \
|
52
|
+
'You are now logged in.' \
|
53
|
+
'</div>' \
|
54
|
+
'<div class="alert alert-danger flash-error" role="alert">' \
|
55
|
+
'Your account will soon expire.' \
|
56
|
+
'</div>'
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with a custom configuration' do
|
62
|
+
let(:configuration) { CrystalFlashMessages.configuration }
|
63
|
+
let(:options) { { additional_classes: 'xxx' } }
|
64
|
+
let(:result) { crystal_flash_messages(options) }
|
65
|
+
|
66
|
+
it 'renders correctly' do
|
67
|
+
assign_flash(mock_flash_with_random_key)
|
68
|
+
expect(result).to eql(
|
69
|
+
'<div class="alert alert-foo flash-foo xxx" role="alert">' \
|
70
|
+
'Bar.' \
|
71
|
+
'</div>'
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_view/helpers'
|
4
|
+
require 'crystal_flash_messages'
|
5
|
+
require 'crystal_flash_messages/helpers'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.order = :random
|
9
|
+
config.filter_run focus: true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
|
12
|
+
config.before(:each) do
|
13
|
+
CrystalFlashMessages.configuration.reset
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crystal_flash_messages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christophe Maximin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rb-inotify
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rb-fsevent
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rb-fchange
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.0'
|
125
|
+
description:
|
126
|
+
email: christophe.maximin@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- ".gitignore"
|
132
|
+
- ".rspec"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- Guardfile
|
138
|
+
- LICENSE
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- crystal_flash_messages.gemspec
|
142
|
+
- lib/crystal_flash_messages.rb
|
143
|
+
- lib/crystal_flash_messages/configuration.rb
|
144
|
+
- lib/crystal_flash_messages/helpers.rb
|
145
|
+
- lib/crystal_flash_messages/railtie.rb
|
146
|
+
- lib/crystal_flash_messages/version.rb
|
147
|
+
- spec/model_error_messages/configuration_spec.rb
|
148
|
+
- spec/model_error_messages/helpers_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
homepage: https://github.com/christophemaximin/crystal_flash_messages
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.5.1
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: A simple Rails view helper which displays one or more HTML `div`s with the
|
174
|
+
`flash` messages.
|
175
|
+
test_files:
|
176
|
+
- spec/model_error_messages/configuration_spec.rb
|
177
|
+
- spec/model_error_messages/helpers_spec.rb
|
178
|
+
- spec/spec_helper.rb
|