Skip to content
This repository was archived by the owner on Nov 15, 2020. It is now read-only.

Commit a3702db

Browse files
committedFeb 6, 2017
Moved to jquery.cookie, minor version bump
1 parent 7f7dbf8 commit a3702db

File tree

12 files changed

+217
-92
lines changed

12 files changed

+217
-92
lines changed
 

‎CHANGELOG

+49-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
0.3.4 - SEP.28.2015
1+
### 0.3.6 - FEB.06.2017
2+
* Moved from jquery.cookie to js.cookie
3+
4+
5+
### 0.3.5 - AUG.18.2016
6+
* `around_filter` is deprecated in Rails 5 and will be removed in Rails 5.1. Uses `around_action` if available and falls back to `around_filter` otherwise.
7+
8+
9+
### 0.3.4 - SEP.28.2015
210
* Maintenance release with minor changes and a security fix
311
* fix JS error when flash cookie is not set (new version of jquery.cookie returns undefined when a cookie does not exist) [nickurban]
412
* Reflected XSS vulnerability fix [rubyconvict]
513
* If domain is not set, do not force as empty string. Breaks IE. [ndreckshage]
614
* Update CacheableFlash::RspecMatchers and rspec test suite for latest Rspec v3.3 [Peter Boling]
715

8-
0.3.3 - SEP.13.2013
16+
17+
### 0.3.3 - SEP.13.2013
918
* Maintenance release with lots of minor changes and fixes.
1019
* Main gem should be API compatible.
1120
* Small changes to test helpers which will require updating tests using them.
1221

13-
0.3.2 - AUG.23.2012
22+
23+
### 0.3.2 - AUG.23.2012
1424
* Properly handles stacked flash in cookie flash according to config :append_as option [Peter Boling]
1525

16-
0.3.1 - AUG.22.2012
26+
27+
### 0.3.1 - AUG.22.2012
1728
* Add specs for non stacking use [Peter Boling]
1829
* Use stackable_flash/test_helpers instead of reinventing the wheel [Peter Boling]
1930
* Config now works! [Peter Boling]
2031
* Update to stackable_flash 0.0.7 (working config) [Peter Boling]
2132
* default to non stacking [Peter Boling]
2233

23-
0.3.0 - AUG.21.2012
34+
35+
### 0.3.0 - AUG.21.2012
2436
- Completed integration with stackable_flash (http://github.com/pboling/stackable_flash)
2537
- Test::Unit helpers and Rspec Matchers updated to be stackable
2638
- Expanded test suite
@@ -32,7 +44,8 @@
3244
- (v0.2.X converted everything to string)
3345
- the CacheableFlash::Config class is experimental, and no code uses the config settings yet.
3446

35-
0.2.10 - AUG.13.2012
47+
48+
### 0.2.10 - AUG.13.2012
3649
- Split test_helpers from rspec_matchers (test_helpers may be useful in TestUnit
3750
- When using Middleware: Flash Cookies now stay in the cookie until cleared out by the javascript: closer to guaranteed delivery.
3851
- Improved spec suite
@@ -41,44 +54,54 @@
4154
- Added facets runtime dependency
4255
- corrected namespace of CacheableFlash::CookieFlash
4356

44-
0.2.9 - AUG.08.2012
57+
58+
### 0.2.9 - AUG.08.2012
4559
- More rearranging
4660
- Improved integration test of CacheableFlash & CacheableFlash::TestHelpers
4761
- Updated to latest jquery.cookie
4862

49-
0.2.8 - AUG.07.2012
63+
64+
### 0.2.8 - AUG.07.2012
5065
- switch from jeweler to gem-release for bumping and tagging
5166
- bundler update (1.0.24)
5267
- Escape HTML in flash values unless they're html_safe
5368
- Add CacheableFlash rack middleware
5469

55-
0.2.7 - JUN.21.2012
70+
71+
### 0.2.7 - JUN.21.2012
5672
- Note: Does not support flash.now feature of the FlashHash in Rails
5773
- Corrected directory names for controllers/layouts
5874

59-
0.2.6 - unreleased
75+
76+
### 0.2.6 - unreleased
6077
- all specs pass with rspec 2.10
6178

62-
0.2.5 - MAR.01.2012
79+
80+
### 0.2.5 - MAR.01.2012
6381
- Real integration test!
6482

65-
0.2.4 - FEB.27.2012
83+
84+
### 0.2.4 - FEB.27.2012
6685
- Dependency diet! No longer requires all of rails - only railties.
6786

68-
0.2.3 - JAN.13.2012
87+
88+
### 0.2.3 - JAN.13.2012
6989
- Fixed problems loading assets: Sprockets::FileNotFound - thanks jlxw
7090
- reflect move back to pivotal's repo in README.
7191
- Updated specs, to running and passing condition!
7292
- Made rails > 3.0 a dependency, since it is (uses ::Rails::Engine and :Rails::Railtie)
7393

74-
0.2.2 - SEP.10.2011
94+
95+
### 0.2.2 - SEP.10.2011
7596
- Improved deprecation warnings about using the generator (not needed with asset pipeline)
7697
- Improved README setup instructions
7798

78-
0.2.1 - SEP.10.2011
99+
100+
### 0.2.1 - SEP.10.2011
79101
- Fixed bug in generator for those not using asset pipeline, or pre Rails 3.1
80102

81-
0.2.0 - SEP.10.2011 [Peter Boling begins gemification process]
103+
104+
### 0.2.0 - SEP.10.2011 [Peter Boling begins gemification process]
82105
- Converted to a gem
83106
- Updated to improved, patched jquery.cookie from https://github.com/pboling/jquery-cookie
84107
- Merged a few other forks of cacheable-flash
@@ -89,21 +112,26 @@
89112
Unreleased
90113
- Implicitly adding js files to Rails include defaults (Patch from Michael Erb)
91114

92-
0.1.5
115+
116+
### 0.1.5
93117
- Requiring version >= 1.1.2 of the json gem
94118
- Converted tests into specs
95119

96-
0.1.4
120+
121+
### 0.1.4
97122
- Added TestHelpers
98123
- Added flash_cookie method for tests
99124

100-
0.1.3
125+
126+
### 0.1.3
101127
- Require json in init.rb
102128

103-
0.1.2
129+
130+
### 0.1.2
104131
- Flash on the Rails side is cleared when written to the cookie
105132
- Uses existing cookie flash value
106133
- Using Scriptaculous cookie.js library
107134

108-
0.1.1
135+
136+
### 0.1.1
109137
- Added cookies.js

‎README.rdoc

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ So if you have config.assets.enabled = false in application.rb then in your layo
2727
javascript_include_tag :cacheable_flash
2828

2929
Otherwise, in your layout, just source them like normal:
30-
javascript_include_tag 'flash', 'jquery.cookie'
30+
javascript_include_tag 'flash', 'js.cookie'
3131

3232
=== With asset pipeline (requires Rails 3.1)
3333

3434
The asset pipeline should have access to the assets in this gem via your app/assets/javascripts/application.js:
3535
//= require flash
36-
//= require jquery.cookie
36+
//= require js.cookie
3737

3838
== Mailing List
3939

@@ -138,7 +138,7 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
138138

139139
describe TestController, "#index" do
140140
include CacheableFlash::TestHelpers
141-
141+
142142
it "writes to the flash cookie" do
143143
get :index
144144
flash_cookie["notice"].should == "In index"
@@ -157,14 +157,14 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
157157
== Versioning
158158

159159
This library aims to adhere to {Semantic Versioning 2.0.0}[http://semver.org/].
160-
Violations of this scheme should be reported as bugs. Specifically,
161-
if a minor or patch version is released that breaks backward
160+
Violations of this scheme should be reported as bugs. Specifically,
161+
if a minor or patch version is released that breaks backward
162162
compatibility, a new version should be immediately released that
163-
restores compatibility. Breaking changes to the public API will
163+
restores compatibility. Breaking changes to the public API will
164164
only be introduced with new major versions.
165165

166-
As a result of this policy, you can (and should) specify a
167-
dependency on this gem using the {Pessimistic Version Constraint}[http://docs.rubygems.org/read/chapter/16#page74] with two digits of precision.
166+
As a result of this policy, you can (and should) specify a
167+
dependency on this gem using the {Pessimistic Version Constraint}[http://docs.rubygems.org/read/chapter/16#page74] with two digits of precision.
168168

169169
For example:
170170

‎init.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
require "cacheable_flash"
33
#use Rails::VERSION::STRING for rails < 1 somehow -- or perhaps, who cares??
44
if ::Rails::VERSION::MAJOR == 2
5-
ActionView::Helpers::AssetTagHelper.register_javascript_include_default('jquery.cookie','flash')
5+
ActionView::Helpers::AssetTagHelper.register_javascript_include_default('js.cookie','flash')
66
end

‎install.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
puts "copying flash.js to #{rails_javascripts_dir}"
1111
cp "#{dir}/flash.js", rails_javascripts_dir
1212

13-
if File.exists?("#{rails_javascripts_dir}/jquery.cookie.js")
14-
puts "#{rails_javascripts_dir}/jquery.cookie.js already exists"
13+
if File.exists?("#{rails_javascripts_dir}/js.cookie.js")
14+
puts "#{rails_javascripts_dir}/js.cookie.js already exists"
1515
else
16-
puts "copying jquery.cookie.js to #{rails_javascripts_dir}"
17-
cp "#{dir}/jquery.cookie.js", rails_javascripts_dir
16+
puts "copying js.cookie.js to #{rails_javascripts_dir}"
17+
cp "#{dir}/js.cookie.js", rails_javascripts_dir
1818
end

‎lib/cacheable_flash.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ module CacheableFlash
2323
include CacheableFlash::CookieFlash
2424

2525
def self.included(base)
26-
#base must define around_filter, as in Rails
27-
base.around_filter :write_flash_to_cookie
26+
#base must define around_action or around_filter, as in Rails
27+
28+
around_method = if base.respond_to?(:around_action)
29+
:around_action
30+
else
31+
:around_filter
32+
end
33+
34+
base.send around_method, :write_flash_to_cookie
2835
end
2936

3037
def write_flash_to_cookie

‎lib/cacheable_flash/railtie.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Railtie < ::Rails::Railtie
33
# Add cacheable flash JS to defaults for Rails < 3.1 (not needed with asset pipeline)
44
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0
55
config.before_configuration do
6-
config.action_view.javascript_expansions[:cacheable_flash] = %w(jquery.cookie flash)
6+
config.action_view.javascript_expansions[:cacheable_flash] = %w(js.cookie flash)
77
end
88
end
99
end

‎lib/cacheable_flash/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module CacheableFlash
2-
VERSION = "0.3.4"
2+
VERSION = "0.3.6"
33
end

‎lib/generators/cacheable_flash/install/install_generator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# encoding: utf-8
22

33
module CacheableFlash
4-
# Copies javascript libraries flash.js and jquery.cookie.js to public/javascripts/ (Rails 3.0.X only, Rails 3.1 has asset pipeline)
4+
# Copies javascript libraries flash.js and js.cookie.js to public/javascripts/ (Rails 3.0.X only, Rails 3.1 has asset pipeline)
55
#
66
# @example
77
# $ rails generate cacheable_flash:install
@@ -18,7 +18,7 @@ def copy_files
1818
ActiveSupport::Deprecation.warn("Rails 3.1 has the asset pipeline, so you only need to copy javascript files if you aren't using it.")
1919
end
2020
template 'flash.js', 'public/javascripts/flash.js'
21-
template 'jquery.cookie.js', 'public/javascripts/jquery.cookie.js'
21+
template 'js.cookie.js', 'public/javascripts/js.cookie.js'
2222
end
2323
end
2424
end

‎spec/cacheable_flash/cacheable_flash_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
attr_reader :controller_class, :controller, :cookies
55
before do
66
@controller_class = Struct.new(:cookies, :flash)
7-
allow(@controller_class).to receive(:around_filter)
7+
allow(@controller_class).to receive(:around_action)
88
@controller_class.send(:include, CacheableFlash)
99
@controller = @controller_class.new({}, {})
1010
@cookies = {}
@@ -120,8 +120,8 @@ def controller_cookie_flash
120120
end
121121

122122
describe ".included" do
123-
it "sets the around_filter on the controller to call #write_flash_to_cookie" do
124-
expect(@controller_class).to receive(:around_filter).with(:write_flash_to_cookie)
123+
it "sets the around_action on the controller to call #write_flash_to_cookie" do
124+
expect(@controller_class).to receive(:around_action).with(:write_flash_to_cookie)
125125
@controller_class.send(:include, CacheableFlash)
126126
end
127127
end

‎vendor/assets/javascripts/flash.js.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ var Flash = new Object();
44
Flash.data = {};
55

66
Flash.transferFromCookies = function() {
7-
var data = JSON.parse(unescape($.cookie("flash") || '{}'));
7+
var data = JSON.parse(unescape(Cookies.get("flash") || '{}'));
88
if(!data) data = {};
99
Flash.data = data;
10-
$.cookie('flash', null, {path: '/', domain: '<%=CacheableFlash::Config.config[:domain]%>'});
10+
Cookies.set('flash', null, {path: '/', domain: '<%=CacheableFlash::Config.config[:domain]%>'});
1111
};
1212

1313
Flash.writeDataTo = function(name, element, callback) {

‎vendor/assets/javascripts/jquery.cookie.js

-47
This file was deleted.
+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*!
2+
* JavaScript Cookie v2.0.0-beta.1
3+
* https://github.com/js-cookie/js-cookie
4+
*
5+
* Copyright 2006, 2015 Klaus Hartl
6+
* Released under the MIT license
7+
*/
8+
(function (factory) {
9+
if (typeof define === 'function' && define.amd) {
10+
define(factory);
11+
} else if (typeof exports === 'object') {
12+
module.exports = factory();
13+
} else {
14+
var _OldCookies = window.Cookies;
15+
var api = window.Cookies = factory(window.jQuery);
16+
api.noConflict = function () {
17+
window.Cookies = _OldCookies;
18+
return api;
19+
};
20+
}
21+
}(function () {
22+
function extend () {
23+
var i = 0;
24+
var result = {};
25+
for (; i < arguments.length; i++) {
26+
var attributes = arguments[ i ];
27+
for (var key in attributes) {
28+
result[key] = attributes[key];
29+
}
30+
}
31+
return result;
32+
}
33+
34+
function init (converter) {
35+
function api (key, value, attributes) {
36+
var result;
37+
38+
// Write
39+
40+
if (arguments.length > 1) {
41+
attributes = extend({
42+
path: '/'
43+
}, api.defaults, attributes);
44+
45+
if (typeof attributes.expires === 'number') {
46+
var expires = new Date();
47+
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
48+
attributes.expires = expires;
49+
}
50+
51+
try {
52+
result = JSON.stringify(value);
53+
if (/^[\{\[]/.test(result)) {
54+
value = result;
55+
}
56+
} catch (e) {}
57+
58+
value = encodeURIComponent(String(value));
59+
value = value.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
60+
61+
key = encodeURIComponent(String(key));
62+
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
63+
key = key.replace(/[\(\)]/g, escape);
64+
65+
return (document.cookie = [
66+
key, '=', value,
67+
attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
68+
attributes.path && '; path=' + attributes.path,
69+
attributes.domain && '; domain=' + attributes.domain,
70+
attributes.secure && '; secure'
71+
].join(''));
72+
}
73+
74+
// Read
75+
76+
if (!key) {
77+
result = {};
78+
}
79+
80+
// To prevent the for loop in the first place assign an empty array
81+
// in case there are no cookies at all. Also prevents odd result when
82+
// calling "get()"
83+
var cookies = document.cookie ? document.cookie.split('; ') : [];
84+
var rdecode = /(%[0-9A-Z]{2})+/g;
85+
var i = 0;
86+
87+
for (; i < cookies.length; i++) {
88+
var parts = cookies[i].split('=');
89+
var name = parts[0].replace(rdecode, decodeURIComponent);
90+
var cookie = parts.slice(1).join('=');
91+
92+
if (cookie.charAt(0) === '"') {
93+
cookie = cookie.slice(1, -1);
94+
}
95+
96+
cookie = converter && converter(cookie, name) || cookie.replace(rdecode, decodeURIComponent);
97+
98+
if (this.json) {
99+
try {
100+
cookie = JSON.parse(cookie);
101+
} catch (e) {}
102+
}
103+
104+
if (key === name) {
105+
result = cookie;
106+
break;
107+
}
108+
109+
if (!key) {
110+
result[name] = cookie;
111+
}
112+
}
113+
114+
return result;
115+
}
116+
117+
api.get = api.set = api;
118+
api.getJSON = function () {
119+
return api.apply({
120+
json: true
121+
}, [].slice.call(arguments));
122+
};
123+
api.defaults = {};
124+
125+
api.remove = function (key, attributes) {
126+
api(key, '', extend(attributes, {
127+
expires: -1
128+
}));
129+
};
130+
131+
api.withConverter = init;
132+
133+
return api;
134+
}
135+
136+
return init();
137+
}));

0 commit comments

Comments
 (0)
This repository has been archived.