wiselinks 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +62 -56
- data/VERSION +1 -1
- data/lib/assets/javascripts/wiselinks.js.coffee +6 -6
- data/lib/wiselinks/headers.rb +5 -2
- data/wiselinks.gemspec +2 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -74,6 +74,8 @@ Restart your server and you're now using wiselinks!
|
|
74
74
|
|
75
75
|
## How does it work?
|
76
76
|
|
77
|
+
### CoffeeScript
|
78
|
+
|
77
79
|
Modify your `application.js.coffee` file to use Wiselinks object:
|
78
80
|
|
79
81
|
```coffeescript
|
@@ -84,9 +86,52 @@ $(document).ready ->
|
|
84
86
|
window.wiselinks = new Wiselinks()
|
85
87
|
```
|
86
88
|
|
87
|
-
|
89
|
+
You can add some options, if you want:
|
88
90
|
|
89
|
-
|
91
|
+
```coffeescript
|
92
|
+
#= require jquery
|
93
|
+
#= require jquery.role
|
94
|
+
#= require wiselinks
|
95
|
+
|
96
|
+
$(document).ready ->
|
97
|
+
# DOM element with role = "content" will be replaced after data load.
|
98
|
+
window.wiselinks = new Wiselinks($('@content'))
|
99
|
+
|
100
|
+
# Of course you can use more traditional jQuery selectors.
|
101
|
+
# window.wiselinks = new Wiselinks($('#content'))
|
102
|
+
# window.wiselinks = new Wiselinks($('.content:first'))
|
103
|
+
|
104
|
+
$(document).off('page:loading').on(
|
105
|
+
'page:loading'
|
106
|
+
(event, url, target, render) ->
|
107
|
+
console.log("Wiselinks loading: #{url} to #{target} within '#{render}'")
|
108
|
+
# start loading animation
|
109
|
+
)
|
110
|
+
|
111
|
+
$(document).off('page:complete').on(
|
112
|
+
'page:complete'
|
113
|
+
(event, xhr, settings) ->
|
114
|
+
console.log("Wiselinks page loading completed")
|
115
|
+
# stop loading animation
|
116
|
+
)
|
117
|
+
|
118
|
+
$(document).off('page:success').on(
|
119
|
+
'page:success'
|
120
|
+
(event, data, status) ->
|
121
|
+
console.log("Wiselinks status: '#{status}'")
|
122
|
+
)
|
123
|
+
|
124
|
+
$(document).off('page:error').on(
|
125
|
+
'page:error'
|
126
|
+
(event, data, status) ->
|
127
|
+
console.log("Wiselinks status: '#{status}'")
|
128
|
+
# show error message
|
129
|
+
)
|
130
|
+
```
|
131
|
+
|
132
|
+
### HTML templates
|
133
|
+
|
134
|
+
Links with `data-push` attribute will fire History.pushState() event.
|
90
135
|
Data from the request will replace content of the container that was passed to Wiselinks (default is "body")
|
91
136
|
|
92
137
|
|
@@ -166,56 +211,17 @@ Data from the request will be pasted into `<div role="catalog">`. This configura
|
|
166
211
|
<!-- the list of your items -->
|
167
212
|
...
|
168
213
|
</div>
|
169
|
-
```
|
170
|
-
|
171
|
-
You can add some options, if you want:
|
172
|
-
|
173
|
-
```coffeescript
|
174
|
-
#= require jquery
|
175
|
-
#= require jquery.role
|
176
|
-
#= require wiselinks
|
177
|
-
|
178
|
-
$(document).ready ->
|
179
|
-
# DOM element with role = "content" will be replaced after data load.
|
180
|
-
window.wiselinks = new Wiselinks($('@content'))
|
181
|
-
|
182
|
-
# Of course you can use more traditional jQuery selectors.
|
183
|
-
# window.wiselinks = new Wiselinks($('#content'))
|
184
|
-
# window.wiselinks = new Wiselinks($('.content:first'))
|
185
|
-
|
186
|
-
$(document).off('page:loading').on(
|
187
|
-
'page:loading'
|
188
|
-
(event, url, target, render) ->
|
189
|
-
console.log("Wiselinks loading: #{url} to #{target} within '#{render}'")
|
190
|
-
# start loading animation
|
191
|
-
)
|
192
|
-
|
193
|
-
$(document).off('page:complete').on(
|
194
|
-
'page:complete'
|
195
|
-
(event, xhr, settings) ->
|
196
|
-
console.log("Wiselinks page loading completed")
|
197
|
-
# stop loading animation
|
198
|
-
)
|
214
|
+
```
|
199
215
|
|
200
|
-
|
201
|
-
'page:success'
|
202
|
-
(event, data, status) ->
|
203
|
-
console.log("Wiselinks status: '#{status}'")
|
204
|
-
)
|
216
|
+
### Rendering
|
205
217
|
|
206
|
-
|
207
|
-
'page:error'
|
208
|
-
(event, data, status) ->
|
209
|
-
console.log("Wiselinks status: '#{status}'")
|
210
|
-
# show error message
|
211
|
-
)
|
212
|
-
```
|
218
|
+
The idea of Wiselinks is that you should render only content that you need in current request. Usually you don't need to reload your stylesheets and javascripts on every request.
|
213
219
|
|
214
|
-
|
220
|
+
### Javascript Events
|
215
221
|
|
216
222
|
While using Wiselinks you **can rely** on `DOMContentLoaded` or `jQuery.ready()` to trigger your JavaScript code, but Wiselinks gives you some additional useful event to deal with the lifecycle of the page:
|
217
223
|
|
218
|
-
|
224
|
+
#### page:loading (url, target, render = 'template')
|
219
225
|
|
220
226
|
Event is triggered before the `XMLHttpRequest` is initialised and performed.
|
221
227
|
* *url* - URL of the request that will be performed;
|
@@ -224,14 +230,14 @@ Event is triggered before the `XMLHttpRequest` is initialised and performed.
|
|
224
230
|
|
225
231
|
* *render = 'template'* – what should be rendered; can be 'template' or 'partial';
|
226
232
|
|
227
|
-
|
233
|
+
#### page:success (data, status) ###
|
228
234
|
|
229
235
|
Event is triggered if the request succeeds.
|
230
236
|
* *data* – the data returned from the server;
|
231
237
|
|
232
238
|
* *status* – a string describing the status;
|
233
239
|
|
234
|
-
|
240
|
+
#### page:error (status, error) ###
|
235
241
|
|
236
242
|
Event is triggered if the request fails.
|
237
243
|
|
@@ -240,20 +246,20 @@ Event is triggered if the request fails.
|
|
240
246
|
|
241
247
|
So if you wanted to have a client-side spinner, you could listen for `page:loading` to start it and `page:success` or `page:error` to stop it.
|
242
248
|
|
243
|
-
|
249
|
+
### ActionDispatch::Request extensions
|
244
250
|
|
245
251
|
Wiselinks adds a couple of methods to `ActionDispatch::Request`. These methods are mostly syntax sugar and don't have any complex logic, so you can use them or not.
|
246
252
|
|
247
|
-
|
253
|
+
#### #wiselinks? ###
|
248
254
|
Method returns `true` if current request is initiated by Wiselinks, `false` otherwise.
|
249
255
|
|
250
|
-
|
256
|
+
#### #wiselinks_template? ###
|
251
257
|
Method returns `true` if current request is initiated by Wiselinks and client want to render template, `false` otherwise.
|
252
258
|
|
253
|
-
|
259
|
+
#### #wiselinks_partial? ###
|
254
260
|
Method returns `true` if current request is initiated by Wiselinks and client want to render partial, `false` otherwise.
|
255
261
|
|
256
|
-
|
262
|
+
### Assets change detection
|
257
263
|
|
258
264
|
You can enable assets change detection with Wiselinks. To do this you have to enable assets digests by adding this to you environment file:
|
259
265
|
|
@@ -269,7 +275,7 @@ Then you should append your layout by adding this to head section:
|
|
269
275
|
|
270
276
|
Now Wiselinks will track changes of your assets and if anything will change, your page will be reloaded completely.
|
271
277
|
|
272
|
-
|
278
|
+
### Title handling
|
273
279
|
|
274
280
|
Wiselinks handles page titles by passing `X-Title` header with response. To do this you can use `wiselinks_title` helper.
|
275
281
|
|
@@ -284,7 +290,7 @@ Wiselinks handles page titles by passing `X-Title` header with response. To do t
|
|
284
290
|
|
285
291
|
Of course you can use `wiselinks_title` helper in your own helpers too.
|
286
292
|
|
287
|
-
##Example
|
293
|
+
## Example
|
288
294
|
|
289
295
|
We crafted example application that uses nearly all features of Wiselinks so you can see it in action.
|
290
296
|
|
@@ -307,7 +313,7 @@ We crafted example application that uses nearly all features of Wiselinks so you
|
|
307
313
|
|
308
314
|
![JetRockets](http://www.jetrockets.ru/images/logo.png)
|
309
315
|
|
310
|
-
Wiselinks is maintained by [JetRockets](http://www.jetrockets.ru).
|
316
|
+
Wiselinks is maintained by [JetRockets](http://www.jetrockets.ru/en).
|
311
317
|
|
312
318
|
Contributors:
|
313
319
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
@@ -75,10 +75,9 @@ class Wiselinks
|
|
75
75
|
url: url
|
76
76
|
headers:
|
77
77
|
'X-Render': render
|
78
|
-
complete: (
|
79
|
-
$document.trigger('page:complete', [
|
80
|
-
|
81
|
-
success: (data, status, xhr) ->
|
78
|
+
complete: (xhr, status) ->
|
79
|
+
$document.trigger('page:complete', [xhr, status])
|
80
|
+
success: (data, status, xhr) ->
|
82
81
|
if self._assets_changed(xhr.getResponseHeader('X-Assets-Digest'))
|
83
82
|
window.location.reload(true)
|
84
83
|
else
|
@@ -88,7 +87,8 @@ class Wiselinks
|
|
88
87
|
|
89
88
|
$document.trigger('page:success', [data, status])
|
90
89
|
error: (xhr, status, error)->
|
91
|
-
$document.trigger('page:error', [status, error])
|
90
|
+
$document.trigger('page:error', [status, error])
|
91
|
+
|
92
92
|
dataType: "html"
|
93
93
|
)
|
94
94
|
|
@@ -145,6 +145,6 @@ class Wiselinks
|
|
145
145
|
|
146
146
|
_set_title: (xhr) ->
|
147
147
|
value = xhr.getResponseHeader('X-Title')
|
148
|
-
document.title = value if value?
|
148
|
+
document.title = decodeURI(value) if value?
|
149
149
|
|
150
150
|
window.Wiselinks = Wiselinks
|
data/lib/wiselinks/headers.rb
CHANGED
@@ -18,7 +18,10 @@ module Wiselinks
|
|
18
18
|
options[:partial] ||= action_name
|
19
19
|
else
|
20
20
|
Wiselinks.log("processing template request")
|
21
|
-
|
21
|
+
|
22
|
+
if Wiselinks.options[:layout] != false
|
23
|
+
options[:layout] = self.wiselinks_layout
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
if Wiselinks.options[:assets_digest].present?
|
@@ -34,7 +37,7 @@ module Wiselinks
|
|
34
37
|
def wiselinks_title(value)
|
35
38
|
if self.request.wiselinks?
|
36
39
|
Wiselinks.log("title: #{value}")
|
37
|
-
response.headers['X-Title'] = value
|
40
|
+
response.headers['X-Title'] = URI.encode(value)
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
data/wiselinks.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wiselinks"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Igor Alexandrov", "Alexey Solilin", "Julia Egorova"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-27"
|
13
13
|
s.email = "igor.alexandrov@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiselinks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-12-
|
14
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: shoulda
|
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
segments:
|
170
170
|
- 0
|
171
|
-
hash:
|
171
|
+
hash: -1318426175759826539
|
172
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
173
|
none: false
|
174
174
|
requirements:
|