unobtrusive_flash 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcf558cc6c7773077a8b0e9b02a16d747785424c
4
- data.tar.gz: 572d0ec1cddc18f14f601738a12e62b17a012d30
3
+ metadata.gz: 2eb8a0a2384eecefacf6fd3aff7dc0799567aca4
4
+ data.tar.gz: c4d0f68f87e5fc0f7b4b39725ad12b1b384e90e3
5
5
  SHA512:
6
- metadata.gz: a158ce2b5636919e08e3bbfcb9c0bb1070c3064416353b84edca1f3ac42cb8fab19ad24ab3354ba3b2fc59180fdb8515905d50c2e7cf8d67aa1f0263b7a6ce72
7
- data.tar.gz: 75aa65125e9e74ab6dc6785a61f8b14f31acb28bde4cba869f1642303e738a8250b77e109707a206141869d48a515d72b8c430c81780b4cf7b8c251e9cb62393
6
+ metadata.gz: b7ed858fbdb382db5a0823e3677a6f4609062710d9789fbd2924f86fd47bf1a0843ba90f9e2edd31297f9ae413a5281cf393c01940fbb910c02296fab3c00e95
7
+ data.tar.gz: ea0a2251c0366a6a81aae1f230d4a3982da82148d86cca0bc4ed0ee120fdecb9d2e6d7e9858602c37a7bd23da0d3fd4f980c1814a24c1d5e40168e538d3617ab
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9
4
+ - 2.0
5
+ - 2.1
6
+ script: "rspec"
@@ -1,3 +1,10 @@
1
+ ## 2014-06-23 3.1.0
2
+
3
+ * Extracted default flash options to `UnobtrusiveFlash.flashOptions` so you can set the message timeout.
4
+ * Use `hostname` when nuking cookies by @zeppelin [#14]
5
+ * Check $flashContainer dynamically by @nfedyashev [#15].
6
+ * Fixed issues with applications on the .herokuapp.com domain [#16].
7
+
1
8
  ## 2014-03-07 3.0.0
2
9
 
3
10
  * Moved Javascript methods to an `UnobtrusiveFlash` module. This breaks calling `$.showFlashMessage`, hence another major release [#11]
@@ -1,6 +1,4 @@
1
- # Unobtrusive flash messages for Rails
2
-
3
- **Version 1 users:** this gem got a major redesign in version 2, please read the documentation
1
+ # Unobtrusive flash messages for Rails [![Build Status](https://travis-ci.org/leonid-shevtsov/unobtrusive_flash.svg?branch=master)](https://travis-ci.org/leonid-shevtsov/unobtrusive_flash)
4
2
 
5
3
  Ever got tired of pages that can't be cached because they contain flash messages?
6
4
 
@@ -52,10 +50,18 @@ Also `require unobtrusive_flash_bootstrap` in your `application.js`. This file c
52
50
 
53
51
  Either declare a `.unobtrusive-flash-container` element somewhere on the page to contain the alerts, or Unobtrusive flash will choose the first `.container` or `.container-fluid` element on the page, or fall back to the `body`.
54
52
 
53
+ If you want the flash messages to disappear automatically, set this in your Javascript:
54
+
55
+ UnobtrusiveFlash.flashOptions['timeout'] = 2000; // milliseconds
56
+
55
57
  ### Option 2: For non-Bootstrap projects
56
58
 
57
59
  Also `require unobtrusive_flash_ui` in your `application.js` and `require unobtrusive_flash_ui` in your `application.css`. These files contain a no-frills flash message UI that works out of the box.
58
60
 
61
+ If you want the flash messages to disappear automatically, set this in your Javascript:
62
+
63
+ UnobtrusiveFlash.flashOptions['timeout'] = 2000; // milliseconds
64
+
59
65
  ### Option 3: Roll your own
60
66
 
61
67
  Unobtrusive Flash triggers jQuery events when flash is received. If you want to integrate it with your own UI, implement and bind a handler:
@@ -66,7 +72,6 @@ Unobtrusive Flash triggers jQuery events when flash is received. If you want to
66
72
 
67
73
  $(window).bind('rails:flash', flashHandler);
68
74
 
69
-
70
75
  ## Using UnobtrusiveFlash with a frontend framework that doesn't use jQuery for AJAX
71
76
 
72
77
  Call `UnobtrusiveFlash.showFlashFromCookies()` in your Javascript after a completed request.
@@ -82,4 +87,4 @@ Both Bootstrap and non-Bootstrap versions contain a function to display flash me
82
87
 
83
88
  * * *
84
89
 
85
- © 2010-2014 Leonid Shevtsov, released under the MIT license
90
+ © 2010-2014 [Leonid Shevtsov](http://leonid.shevtsov.me) and [contributors](https://github.com/leonid-shevtsov/unobtrusive_flash/graphs/contributors), released under the MIT license
@@ -1,12 +1,13 @@
1
+ window.UnobtrusiveFlash = {}
2
+
1
3
  $(function() {
2
4
  // Delete the cookie regardless of the domain it was set from
3
5
  // Partial credit to http://stackoverflow.com/a/2959110/6678
4
6
  function nukeCookie(cookieName) {
5
7
  var yesterday = new Date();
6
8
  yesterday.setDate(yesterday.getDate() - 1);
7
- var hostParts = window.location.host.split('.').reverse();
9
+ var hostParts = window.location.hostname.split('.').reverse();
8
10
  var expireHost = hostParts.shift();
9
- expireHost = expireHost.replace(/^([a-z]{1,})\:[0-9]{1,5}/, '$1');
10
11
  $.each(hostParts, function(i,part) {
11
12
  expireHost = part + '.' + expireHost;
12
13
  document.cookie = cookieName+'=; path=/;expires='+yesterday+'; domain='+expireHost;
@@ -43,7 +44,6 @@ $(function() {
43
44
  }
44
45
 
45
46
  // Reads flash messages from cookies and fires corresponding events
46
- window.UnobtrusiveFlash = {}
47
47
  window.UnobtrusiveFlash['showFlashFromCookies'] = function() {
48
48
  var flashMessages = extractFlashFromCookies();
49
49
  if (flashMessages !== null) {
@@ -3,11 +3,12 @@
3
3
  //
4
4
  // Declare a .unobtrusive-flash-container wherever you want the messages to appear
5
5
  // Defaults to .container, .container-fluid (core Bootstrap classes), or just the body tag, whichever is present
6
- $(function() {
7
- var $flashContainer = $($('.unobtrusive-flash-container')[0] || $('.container')[0] || $('.container-fluid')[0] || $('body')[0]);
8
6
 
7
+ window.UnobtrusiveFlash.flashOptions = {type: 'notice', timeout: 0};
8
+
9
+ $(function() {
9
10
  UnobtrusiveFlash.showFlashMessage = function(message, options) {
10
- options = $.extend({type: 'notice', timeout: 0}, options);
11
+ options = $.extend(UnobtrusiveFlash.flashOptions, options);
11
12
 
12
13
  // Workaround for common Rails flash type to match common Bootstrap alert type
13
14
  if (options.type=='notice') {
@@ -20,6 +21,7 @@ $(function() {
20
21
 
21
22
  var $flash = $('<div class="alert alert-'+options.type+'"><button type="button" class="close" data-dismiss="alert">&times;</button>'+message+'</div>');
22
23
 
24
+ var $flashContainer = $($('.unobtrusive-flash-container')[0] || $('.container')[0] || $('.container-fluid')[0] || $('body')[0]);
23
25
  $flashContainer.prepend($flash);
24
26
 
25
27
  $flash.hide().delay(300).slideDown(100);
@@ -38,4 +40,4 @@ $(function() {
38
40
  };
39
41
 
40
42
  $(window).bind('rails:flash', flashHandler);
41
- });
43
+ });
@@ -2,6 +2,8 @@
2
2
  // Remember to link unobtrusive_flash_ui.css as well
3
3
  //
4
4
  // Shows flash messages as translucent bars on top of the page
5
+ window.UnobtrusiveFlash.flashOptions = {type: 'notice', timeout: 0};
6
+
5
7
  $(function() {
6
8
  $('<div id="unobtrusive-flash-messages"></div>').prependTo('body');
7
9
 
@@ -12,7 +14,7 @@ $(function() {
12
14
  }
13
15
 
14
16
  UnobtrusiveFlash.showFlashMessage = function(message, options) {
15
- options = $.extend({type: 'notice', timeout: 0}, options);
17
+ options = $.extend(UnobtrusiveFlash.flashOptions, options);
16
18
 
17
19
  var $flash = $('<div class="unobtrusive-flash-message-wrapper unobtrusive-flash-'+options.type+'"><div class="unobtrusive-flash-message">'+message+'</div></div>');
18
20
 
@@ -13,11 +13,22 @@ module UnobtrusiveFlash
13
13
  end
14
14
 
15
15
  cookie_flash += UnobtrusiveFlash::ControllerMixin.sanitize_flash(flash)
16
- cookies[:flash] = {:value => cookie_flash.to_json, :domain => :all}
16
+ cookies[:flash] = {:value => cookie_flash.to_json, :domain => unobtrusive_flash_domain}
17
17
  flash.discard
18
18
  end
19
19
  end
20
20
 
21
+ # Setting cookies for :all domains is broken for Heroku apps, read this article for details
22
+ # https://devcenter.heroku.com/articles/cookies-and-herokuapp-com
23
+ # You can also override this method in your controller if you need to customize the cookie domain
24
+ def unobtrusive_flash_domain
25
+ if request.host =~ /\.herokuapp\.com$/
26
+ request.host
27
+ else
28
+ :all
29
+ end
30
+ end
31
+
21
32
  class << self
22
33
  def sanitize_flash(flash)
23
34
  flash.to_a.map do |key, value|
@@ -1,3 +1,3 @@
1
1
  module UnobtrusiveFlash
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe UnobtrusiveFlash::ControllerMixin do
4
+ describe '#unobtrusive_flash_domain' do
5
+ let(:controller_class) { Struct.new(:request) }
6
+ before(:each) { controller_class.send(:include, UnobtrusiveFlash::ControllerMixin) }
7
+ subject { controller_class.new( double('request', host: host) ) }
8
+
9
+ context 'not on Heroku' do
10
+ let(:host) { 'microsoft.com' }
11
+
12
+ it 'should use :all' do
13
+ expect(subject.send(:unobtrusive_flash_domain)).to eq(:all)
14
+ end
15
+ end
16
+
17
+ context 'on Heroku' do
18
+ let(:host) { 'myapp.herokuapp.com' }
19
+
20
+ it 'should use the host' do
21
+ expect(subject.send(:unobtrusive_flash_domain)).to eq('myapp.herokuapp.com')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe UnobtrusiveFlash::ControllerMixin do
4
4
  describe '.sanitize_flash' do
5
5
  it 'should escape messages that are not html safe' do
6
- described_class.sanitize_flash({:foo => '<bar>'}).should == [[:foo, '&lt;bar&gt;']]
6
+ expect(described_class.sanitize_flash({:foo => '<bar>'})).to eq([[:foo, '&lt;bar&gt;']])
7
7
  end
8
8
 
9
9
  it 'should not escape messages that are html safe' do
10
- described_class.sanitize_flash({:foo => '<bar>'.html_safe}).should == [[:foo, '<bar>']]
10
+ expect(described_class.sanitize_flash({:foo => '<bar>'.html_safe})).to eq([[:foo, '<bar>']])
11
11
  end
12
12
  end
13
13
  end
@@ -25,5 +25,6 @@ EOT
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec", '>=3'
29
+ spec.add_development_dependency "rspec-mocks", '>=3'
29
30
  end
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtrusive_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Shevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
69
83
  description: |
70
84
  unobtrusive_flash takes your flash messages for the backend and automagically passes them to the frontend via HTTP cookies.
71
85
  This works with both regular page loads and AJAX requests, does not tamper with the page body and requires about 3 extra
@@ -76,7 +90,8 @@ executables: []
76
90
  extensions: []
77
91
  extra_rdoc_files: []
78
92
  files:
79
- - .gitignore
93
+ - ".gitignore"
94
+ - ".travis.yml"
80
95
  - CHANGELOG.md
81
96
  - Gemfile
82
97
  - README.markdown
@@ -89,6 +104,7 @@ files:
89
104
  - lib/unobtrusive_flash/controller_mixin.rb
90
105
  - lib/unobtrusive_flash/engine.rb
91
106
  - lib/unobtrusive_flash/version.rb
107
+ - spec/domain_spec.rb
92
108
  - spec/sanitize_flash_spec.rb
93
109
  - spec/spec_helper.rb
94
110
  - unobtrusive_flash.gemspec
@@ -101,20 +117,21 @@ require_paths:
101
117
  - lib
102
118
  required_ruby_version: !ruby/object:Gem::Requirement
103
119
  requirements:
104
- - - '>='
120
+ - - ">="
105
121
  - !ruby/object:Gem::Version
106
122
  version: '0'
107
123
  required_rubygems_version: !ruby/object:Gem::Requirement
108
124
  requirements:
109
- - - '>='
125
+ - - ">="
110
126
  - !ruby/object:Gem::Version
111
127
  version: '0'
112
128
  requirements: []
113
129
  rubyforge_project:
114
- rubygems_version: 2.1.11
130
+ rubygems_version: 2.2.2
115
131
  signing_key:
116
132
  specification_version: 4
117
133
  summary: Unobtrusive flash messages for Rails
118
134
  test_files:
135
+ - spec/domain_spec.rb
119
136
  - spec/sanitize_flash_spec.rb
120
137
  - spec/spec_helper.rb