rails_cacheable_flash 0.0.2
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/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/cacheable_flash.gemspec +17 -0
- data/lib/rails_cacheable_flash/engine.rb +41 -0
- data/lib/rails_cacheable_flash/version.rb +3 -0
- data/lib/rails_cacheable_flash.rb +2 -0
- data/vendor/assets/javascripts/cacheable_flash.js +4 -0
- data/vendor/assets/javascripts/flash/cookie.js +49 -0
- data/vendor/assets/javascripts/flash/flash.js +29 -0
- data/vendor/assets/javascripts/flash/json.js +139 -0
- data/vendor/assets/javascripts/flash/notice.js +14 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andrey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
rails_cacheable_flash
|
2
|
+
===============
|
3
|
+
|
4
|
+
Кэшируемый флеш. Позволяет отрабатывать флеш-нотисы на кэшируемых страницах.
|
5
|
+
|
6
|
+
Может использоваться совместно со Spree.
|
7
|
+
|
8
|
+
Подключение:
|
9
|
+
|
10
|
+
1. В нужном контроллере подключаете джем (фактически там, где потенциально могут появляться флеш-нотисы)
|
11
|
+
|
12
|
+
include RailsCacheableFlash
|
13
|
+
|
14
|
+
2. В йаваскрипте подключаете js-библиотеку джема и даете указания выводить флеш нотисы перед определенным контейнером
|
15
|
+
|
16
|
+
//= require cacheable_flah
|
17
|
+
|
18
|
+
...
|
19
|
+
|
20
|
+
$(document).ready(function() {
|
21
|
+
|
22
|
+
...
|
23
|
+
|
24
|
+
Flash.transferFromCookies();
|
25
|
+
|
26
|
+
Flash.writeDataFrom('notice', '#container980');
|
27
|
+
|
28
|
+
Flash.writeDataFrom('error', '#container980');
|
29
|
+
|
30
|
+
});
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rails_cacheable_flash/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Andrey"]
|
6
|
+
gem.email = ["railscode@gmail.com"]
|
7
|
+
gem.description = "Кэшируемый флеш"
|
8
|
+
gem.summary = "Суммари"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rails_cacheable_flash"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RailsCacheableFlash::VERSION
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module RailsCacheableFlash
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MAJOR >= 1
|
5
|
+
isolate_namespace RailsCacheableFlash
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.after_filter :write_flash_to_cookie
|
11
|
+
end
|
12
|
+
|
13
|
+
def write_flash_to_cookie
|
14
|
+
cookie_flash = JSON.parse(cookies['flash']) rescue {}
|
15
|
+
flash.each do |key, value|
|
16
|
+
cookie_flash[key.to_s] = value
|
17
|
+
end
|
18
|
+
cookies['flash'] = cookie_flash.to_json
|
19
|
+
flash.clear
|
20
|
+
|
21
|
+
if defined?(Spree::Core)
|
22
|
+
set_customizer_cookies
|
23
|
+
# save_referrer_to_order
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# TODO: реализовать и проверить save_referrer_to_order на кэшируемых страницах
|
28
|
+
# def save_referrer_to_order
|
29
|
+
# session[:referrer] = nil # request.env['HTTP_REFERER'] if !session[:referrer]
|
30
|
+
# puts "===================="
|
31
|
+
# puts "current_order: #{current_order}"
|
32
|
+
# puts "request.env['HTTP_REFERER']: #{request.env['HTTP_REFERER']}"
|
33
|
+
# puts "session[:referrer]: #{session[:referrer]}"
|
34
|
+
# puts "===================="
|
35
|
+
# end
|
36
|
+
|
37
|
+
def set_customizer_cookies
|
38
|
+
cookies[:authenticity_token] = session[:_csrf_token] ||= SecureRandom.base64(32)
|
39
|
+
cookies[:current_user_id] = current_user.try(:id)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// From http://wiki.script.aculo.us/scriptaculous/show/Cookie
|
2
|
+
var Cookie = {
|
3
|
+
set: function(name, value, daysToExpire) {
|
4
|
+
var expire = '';
|
5
|
+
if(!daysToExpire) daysToExpire = 365;
|
6
|
+
var d = new Date();
|
7
|
+
d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
|
8
|
+
expire = 'expires=' + d.toGMTString();
|
9
|
+
var path = "path=/"
|
10
|
+
var cookieValue = escape(name) + '=' + escape(value || '') + '; ' + path + '; ' + expire + ';';
|
11
|
+
return document.cookie = cookieValue;
|
12
|
+
},
|
13
|
+
get: function(name) {
|
14
|
+
var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]+)'));
|
15
|
+
return (cookie ? unescape(cookie[2]) : null);
|
16
|
+
},
|
17
|
+
erase: function(name) {
|
18
|
+
var cookie = Cookie.get(name) || true;
|
19
|
+
Cookie.set(name, '', -1);
|
20
|
+
return cookie;
|
21
|
+
},
|
22
|
+
eraseAll: function() {
|
23
|
+
// Get cookie string and separate into individual cookie phrases:
|
24
|
+
var cookieString = "" + document.cookie;
|
25
|
+
var cookieArray = cookieString.split("; ");
|
26
|
+
|
27
|
+
// Try to delete each cookie:
|
28
|
+
for(var i = 0; i < cookieArray.length; ++ i)
|
29
|
+
{
|
30
|
+
var singleCookie = cookieArray[i].split("=");
|
31
|
+
if(singleCookie.length != 2)
|
32
|
+
continue;
|
33
|
+
var name = unescape(singleCookie[0]);
|
34
|
+
Cookie.erase(name);
|
35
|
+
}
|
36
|
+
},
|
37
|
+
accept: function() {
|
38
|
+
if (typeof navigator.cookieEnabled == 'boolean') {
|
39
|
+
return navigator.cookieEnabled;
|
40
|
+
}
|
41
|
+
Cookie.set('_test', '1');
|
42
|
+
return (Cookie.erase('_test') === '1');
|
43
|
+
},
|
44
|
+
exists: function(cookieName) {
|
45
|
+
var cookieValue = Cookie.get(cookieName);
|
46
|
+
if(!cookieValue) return false;
|
47
|
+
return cookieValue.toString() != "";
|
48
|
+
}
|
49
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
var Flash = new Object();
|
2
|
+
|
3
|
+
Flash.data = {};
|
4
|
+
|
5
|
+
Flash.transferFromCookies = function() {
|
6
|
+
var data = JSON.parse(unescape(Cookie.get("flash")));
|
7
|
+
if(!data) data = {};
|
8
|
+
Flash.data = data;
|
9
|
+
Cookie.erase("flash");
|
10
|
+
};
|
11
|
+
|
12
|
+
Flash.writeDataTo = function(name, element) {
|
13
|
+
element = $(element);
|
14
|
+
var content = "";
|
15
|
+
if(Flash.data[name]) {
|
16
|
+
content = Flash.data[name].toString().replace(/\+/g, ' ');
|
17
|
+
}
|
18
|
+
element.html(unescape(content));
|
19
|
+
};
|
20
|
+
|
21
|
+
Flash.writeDataFrom = function(name, before_selector) {
|
22
|
+
var content = "";
|
23
|
+
if(Flash.data[name]) {
|
24
|
+
content = Flash.data[name].toString().replace(/\+/g, ' ');
|
25
|
+
}
|
26
|
+
if (content != ""){
|
27
|
+
$('<div id="flash" class="flash flash-'+name+'"><div class="closer" id="closer">x</div><div class="message">'+unescape(content)+'</div></div>').insertBefore(before_selector);
|
28
|
+
}
|
29
|
+
};
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2005 JSON.org
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The Software shall be used for Good, not Evil.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
/*
|
23
|
+
The global object JSON contains two methods.
|
24
|
+
|
25
|
+
JSON.stringify(value) takes a JavaScript value and produces a JSON text.
|
26
|
+
The value must not be cyclical.
|
27
|
+
|
28
|
+
JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
|
29
|
+
return false if there is an error.
|
30
|
+
*/
|
31
|
+
var JSON = function () {
|
32
|
+
var m = {
|
33
|
+
'\b': '\\b',
|
34
|
+
'\t': '\\t',
|
35
|
+
'\n': '\\n',
|
36
|
+
'\f': '\\f',
|
37
|
+
'\r': '\\r',
|
38
|
+
'"' : '\\"',
|
39
|
+
'\\': '\\\\'
|
40
|
+
},
|
41
|
+
s = {
|
42
|
+
'boolean': function (x) {
|
43
|
+
return String(x);
|
44
|
+
},
|
45
|
+
number: function (x) {
|
46
|
+
return isFinite(x) ? String(x) : 'null';
|
47
|
+
},
|
48
|
+
string: function (x) {
|
49
|
+
if (/["\\\x00-\x1f]/.test(x)) {
|
50
|
+
x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
|
51
|
+
var c = m[b];
|
52
|
+
if (c) {
|
53
|
+
return c;
|
54
|
+
}
|
55
|
+
c = b.charCodeAt();
|
56
|
+
return '\\u00' +
|
57
|
+
Math.floor(c / 16).toString(16) +
|
58
|
+
(c % 16).toString(16);
|
59
|
+
});
|
60
|
+
}
|
61
|
+
return '"' + x + '"';
|
62
|
+
},
|
63
|
+
object: function (x) {
|
64
|
+
if (x) {
|
65
|
+
var a = [], b, f, i, l, v;
|
66
|
+
if (x instanceof Array) {
|
67
|
+
a[0] = '[';
|
68
|
+
l = x.length;
|
69
|
+
for (i = 0; i < l; i += 1) {
|
70
|
+
v = x[i];
|
71
|
+
f = s[typeof v];
|
72
|
+
if (f) {
|
73
|
+
v = f(v);
|
74
|
+
if (typeof v == 'string') {
|
75
|
+
if (b) {
|
76
|
+
a[a.length] = ',';
|
77
|
+
}
|
78
|
+
a[a.length] = v;
|
79
|
+
b = true;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
a[a.length] = ']';
|
84
|
+
} else if (x instanceof Object) {
|
85
|
+
a[0] = '{';
|
86
|
+
for (i in x) {
|
87
|
+
v = x[i];
|
88
|
+
f = s[typeof v];
|
89
|
+
if (f) {
|
90
|
+
v = f(v);
|
91
|
+
if (typeof v == 'string') {
|
92
|
+
if (b) {
|
93
|
+
a[a.length] = ',';
|
94
|
+
}
|
95
|
+
a.push(s.string(i), ':', v);
|
96
|
+
b = true;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
a[a.length] = '}';
|
101
|
+
} else {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
return a.join('');
|
105
|
+
}
|
106
|
+
return 'null';
|
107
|
+
}
|
108
|
+
};
|
109
|
+
return {
|
110
|
+
copyright: '(c)2005 JSON.org',
|
111
|
+
license: 'http://www.JSON.org/license.html',
|
112
|
+
/*
|
113
|
+
Stringify a JavaScript value, producing a JSON text.
|
114
|
+
*/
|
115
|
+
stringify: function (v) {
|
116
|
+
var f = s[typeof v];
|
117
|
+
if (f) {
|
118
|
+
v = f(v);
|
119
|
+
if (typeof v == 'string') {
|
120
|
+
return v;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
return null;
|
124
|
+
},
|
125
|
+
/*
|
126
|
+
Parse a JSON text, producing a JavaScript value.
|
127
|
+
It returns false if there is a syntax error.
|
128
|
+
*/
|
129
|
+
parse: function (text) {
|
130
|
+
try {
|
131
|
+
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
|
132
|
+
text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
|
133
|
+
eval('(' + text + ')');
|
134
|
+
} catch (e) {
|
135
|
+
return false;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
};
|
139
|
+
}();
|
@@ -0,0 +1,14 @@
|
|
1
|
+
function close_flash() {
|
2
|
+
$("#closer").live('click', function(){
|
3
|
+
var flash = $(this).parents('div:first');
|
4
|
+
flash.animate({opacity: 1.0, top: '+=20'});
|
5
|
+
flash.animate({opacity: 0.75, top: '-=500'}, 300, function() {
|
6
|
+
flash.remove();
|
7
|
+
});
|
8
|
+
return false;
|
9
|
+
});
|
10
|
+
};
|
11
|
+
|
12
|
+
$(document).ready(function() {
|
13
|
+
close_flash();
|
14
|
+
});
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_cacheable_flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Кэшируемый флеш
|
15
|
+
email:
|
16
|
+
- railscode@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- cacheable_flash.gemspec
|
27
|
+
- lib/rails_cacheable_flash.rb
|
28
|
+
- lib/rails_cacheable_flash/engine.rb
|
29
|
+
- lib/rails_cacheable_flash/version.rb
|
30
|
+
- vendor/assets/javascripts/cacheable_flash.js
|
31
|
+
- vendor/assets/javascripts/flash/cookie.js
|
32
|
+
- vendor/assets/javascripts/flash/flash.js
|
33
|
+
- vendor/assets/javascripts/flash/json.js
|
34
|
+
- vendor/assets/javascripts/flash/notice.js
|
35
|
+
homepage: ''
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.23
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Суммари
|
59
|
+
test_files: []
|