js_application_reloader 0.0.1 → 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.
- checksums.yaml +8 -8
- data/README.md +28 -4
- data/lib/js_application_reloader.rb +7 -1
- data/lib/js_application_reloader/controller_extensions.rb +11 -1
- data/lib/js_application_reloader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjM0ZmRjY2VlNWM1OWI2NGFmNjliNWY3NTZiYzI1OGUyZDE1YTdjZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGIxZGNkNTAxYzFkMjdkNDJkNjhjODBkMjBkYjdkMGIzOTJkY2NlMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2VlYjMxMDllNjg5ZDRlMWRkNGFkNDhkYzkyM2IxMWMzZGZlNjJlODg5MzRl
|
10
|
+
OGIxYzRlZjlmMmE2MDkwMjZmZDk5ODBhMzk5ZWM4ZTg1NTIzNmFkMGZjMzlh
|
11
|
+
NTQxMWQ1MmM4ZWEyNDIxZGNjZTVhNzY2OTVhOWFiNDZkMzNhNzA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDI3MWVkYjZmMGI2NmQ0NjMzNjNhODZjM2QwMzRlMDgxZDUwYWIxZGQ1MzI3
|
14
|
+
MjkwYTgwODk0M2JlOTE5ZmY5ZWZkYzNiYTZhNWMyYjFkODc1Yzc1ZTFlMWFl
|
15
|
+
Nzc3MDg1MjE4ZTIzY2JhOWNhZjU1YTMwODdlZDVkZWJmYWVhOGY=
|
data/README.md
CHANGED
@@ -122,10 +122,19 @@ MVC framework you are using.
|
|
122
122
|
|
123
123
|
In BackboneJS you would insert this into the application's startup code, for example in application.js file. The only requirement is that Backbone is initialised.
|
124
124
|
|
125
|
-
// -- Override Backbone sync() to handle expiration
|
125
|
+
// -- Override Backbone sync() to handle expiration on success or error
|
126
126
|
// -- Do the equivalent for your chosen framework
|
127
127
|
var oldSyncMethod = Backbone.sync;
|
128
128
|
Backbone.sync = function(method, model, options) {
|
129
|
+
var oldSuccess = options.success;
|
130
|
+
options.success = function(data, textStatus, xhr) {
|
131
|
+
if (JsApplicationReloader.isTokenExpired(xhr)) {
|
132
|
+
return JsApplicationReloader.handleTokenExpiration(xhr);
|
133
|
+
} else if (oldSuccess) {
|
134
|
+
oldSuccess(data, textStatus, xhr);
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
129
138
|
var oldError = options.error;
|
130
139
|
options.error = function(xhr, textStatus, errorThrown) {
|
131
140
|
// These are the important 3 lines
|
@@ -183,7 +192,17 @@ You can skip the before filter that JsApplicationReloader uses via
|
|
183
192
|
# The reload_required_http_status, application_name, redirect_url attributes
|
184
193
|
# are available to you on the JsApplicationReloader object.
|
185
194
|
def render_js_application_reloader_expiration
|
186
|
-
|
195
|
+
message = "A new version of #{JsApplicationReloader.application_name} is available. " +
|
196
|
+
"Please click <a href='#{JsApplicationReloader.redirect_url}'>here</a> to load it."
|
197
|
+
|
198
|
+
respond_to do |format|
|
199
|
+
format.html {
|
200
|
+
render :text => message, :status => JsApplicationReloader.reload_required_http_status
|
201
|
+
}
|
202
|
+
format.json {
|
203
|
+
render :json => {:message => message}, :status => JsApplicationReloader.reload_required_http_status
|
204
|
+
}
|
205
|
+
end
|
187
206
|
end
|
188
207
|
|
189
208
|
## Override how the client handles the reloading of the application
|
@@ -193,8 +212,13 @@ config/initializers/js_application_reloader.rb (outside of the 'config' block).
|
|
193
212
|
def JsApplicationReloader.handle_reloader_token_expiration_on_client
|
194
213
|
<<-EOF
|
195
214
|
JsApplicationReloader.handleTokenExpiration = function(xhr) {
|
196
|
-
|
197
|
-
|
215
|
+
var contentType = xhr.getResponseHeader("content-type") || "";
|
216
|
+
if (contentType.indexOf('html') > -1) {
|
217
|
+
alert(xhr.responseText); // Changed to use an alert box
|
218
|
+
}
|
219
|
+
if (contentType.indexOf('json') > -1) {
|
220
|
+
alert(xhr.responseJSON.message); // Changed to use an alert box
|
221
|
+
}
|
198
222
|
return false;
|
199
223
|
};
|
200
224
|
EOF
|
@@ -58,7 +58,13 @@ module JsApplicationReloader
|
|
58
58
|
def self.handle_reloader_token_expiration_on_client
|
59
59
|
<<-EOF
|
60
60
|
JsApplicationReloader.handleTokenExpiration = function(xhr) {
|
61
|
-
|
61
|
+
var contentType = xhr.getResponseHeader("content-type") || "";
|
62
|
+
if (contentType.indexOf('html') > -1) {
|
63
|
+
$('body').html(xhr.responseText); // Display the HTML returned by xhr.responseText as you see fit
|
64
|
+
}
|
65
|
+
if (contentType.indexOf('json') > -1) {
|
66
|
+
$('body').html(xhr.responseJSON.message); // Display the HTML returned by xhr.responseJSON.message as you see fit
|
67
|
+
}
|
62
68
|
return false;
|
63
69
|
};
|
64
70
|
EOF
|
@@ -16,7 +16,17 @@ module JsApplicationReloader
|
|
16
16
|
# override me in your ApplicationController to customize what gets
|
17
17
|
# sent back to the client on token expiration
|
18
18
|
def render_js_application_reloader_expiration
|
19
|
-
|
19
|
+
message = "A new version of #{JsApplicationReloader.application_name} is available. " +
|
20
|
+
"Please click <a href='#{JsApplicationReloader.redirect_url}'>here</a> to load it."
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html {
|
24
|
+
render :text => message, :status => JsApplicationReloader.reload_required_http_status
|
25
|
+
}
|
26
|
+
format.json {
|
27
|
+
render :json => {:message => message}, :status => JsApplicationReloader.reload_required_http_status
|
28
|
+
}
|
29
|
+
end
|
20
30
|
end
|
21
31
|
|
22
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_application_reloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Declan McGrath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|