wiselinks 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +10 -4
- data/LICENSE.txt +1 -1
- data/README.md +74 -0
- data/VERSION +1 -1
- data/lib/assets/javascripts/wiselinks.js.coffee +9 -9
- data/lib/headers.rb +34 -0
- data/lib/wiselinks.rb +2 -2
- data/wiselinks.gemspec +5 -5
- metadata +6 -6
- data/README.rdoc +0 -19
- data/lib/layout.rb +0 -20
data/Gemfile.lock
CHANGED
@@ -4,6 +4,8 @@ GEM
|
|
4
4
|
activesupport (3.2.9)
|
5
5
|
i18n (~> 0.6)
|
6
6
|
multi_json (~> 1.0)
|
7
|
+
bourne (1.1.2)
|
8
|
+
mocha (= 0.10.5)
|
7
9
|
git (1.2.5)
|
8
10
|
i18n (0.6.1)
|
9
11
|
jeweler (1.8.4)
|
@@ -12,16 +14,20 @@ GEM
|
|
12
14
|
rake
|
13
15
|
rdoc
|
14
16
|
json (1.7.5)
|
15
|
-
|
16
|
-
|
17
|
+
metaclass (0.0.1)
|
18
|
+
mocha (0.10.5)
|
19
|
+
metaclass (~> 0.0.1)
|
20
|
+
multi_json (1.5.0)
|
21
|
+
rake (10.0.3)
|
17
22
|
rdoc (3.12)
|
18
23
|
json (~> 1.4)
|
19
24
|
shoulda (3.3.2)
|
20
25
|
shoulda-context (~> 1.0.1)
|
21
26
|
shoulda-matchers (~> 1.4.1)
|
22
|
-
shoulda-context (1.0.
|
23
|
-
shoulda-matchers (1.4.
|
27
|
+
shoulda-context (1.0.2)
|
28
|
+
shoulda-matchers (1.4.2)
|
24
29
|
activesupport (>= 3.0.0)
|
30
|
+
bourne (~> 1.1.2)
|
25
31
|
|
26
32
|
PLATFORMS
|
27
33
|
ruby
|
data/LICENSE.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#Wiselinks
|
2
|
+
Wiselinks makes following links and submitting some forms in your web application faster.
|
3
|
+
|
4
|
+
You may find Wiselinks similar to [Turbolinks](https://github.com/rails/turbolinks) or [Pjax](https://github.com/defunkt/jquery-pjax), but Wiselinks have several rather important differences from both projects. We tried to make Wiselinks as easy to use as Turbolinks are but also as configurable as Pjax.
|
5
|
+
|
6
|
+
##Compatibility
|
7
|
+
Wiselinks should work in all major browsers including browsers that do not support HTML History API out of the box.
|
8
|
+
|
9
|
+
##Installation
|
10
|
+
|
11
|
+
Add this to your Gemfile:
|
12
|
+
|
13
|
+
gem 'wiselinks'
|
14
|
+
|
15
|
+
Then do:
|
16
|
+
|
17
|
+
bundle
|
18
|
+
|
19
|
+
Then modify your `application.js` or `application.js.coffee` file to use Wiselinks object:
|
20
|
+
|
21
|
+
#= require jquery
|
22
|
+
#= require wiselinks
|
23
|
+
|
24
|
+
$(document).ready ->
|
25
|
+
window.wiselinks = new Wiselinks()
|
26
|
+
|
27
|
+
##Events
|
28
|
+
|
29
|
+
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:
|
30
|
+
|
31
|
+
#### `page:loading (url, target, render = 'template')`
|
32
|
+
Event is triggered before the `XMLHttpRequest` is initialized and performed.
|
33
|
+
* *url* - URL of the request that will be performed;
|
34
|
+
|
35
|
+
* *target* – element of the page where result of the request will be loaded into;
|
36
|
+
|
37
|
+
* *render = 'template'* – what should be rendered; can be 'template' or 'partial';
|
38
|
+
|
39
|
+
#### `page:success (data, status)`
|
40
|
+
Event is triggered if the request succeeds.
|
41
|
+
* *data* – the data returned from the server;
|
42
|
+
|
43
|
+
* *status* – a string describing the status;
|
44
|
+
|
45
|
+
#### `page:error (status, error)`
|
46
|
+
|
47
|
+
Event is triggered if the request fails.
|
48
|
+
|
49
|
+
* *status* – a string describing the type of error that occurred;
|
50
|
+
* *error* – optional exception object, if one occurred;
|
51
|
+
|
52
|
+
##Example
|
53
|
+
|
54
|
+
We crafted small example application that uses Wiselinks so you can see it in action.
|
55
|
+
|
56
|
+
* GitHub Repository: [https://github.com/igor-alexandrov/wiselinks_example](https://github.com/igor-alexandrov/wiselinks_example)
|
57
|
+
|
58
|
+
* Live Example: [http://wiselinks.herokuapp.com/](http://wiselinks.herokuapp.com/)
|
59
|
+
|
60
|
+
## Note on Patches / Pull Requests
|
61
|
+
|
62
|
+
* Fork the project.
|
63
|
+
* Make your feature addition or bug fix.
|
64
|
+
* Add tests for it. This is important so I don't break it in a
|
65
|
+
future version unintentionally.
|
66
|
+
* Commit, do not mess with rakefile, version, or history.
|
67
|
+
(if you want to have your own version, that is fine but
|
68
|
+
bump version in a commit by itself I can ignore when I pull)
|
69
|
+
* Send me a pull request. Bonus points for topic branches.
|
70
|
+
|
71
|
+
## Copyright
|
72
|
+
|
73
|
+
Copyright (c) 2012 [Igor Alexandrov](http://igor-alexandrov.github.com/), [Alexey Solilin](https://github.com/solilin) and [Julia Egorova](https://github.com/vankiru). See LICENSE for details.
|
74
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -17,7 +17,7 @@ class Wiselinks
|
|
17
17
|
return if (!History.ready)
|
18
18
|
|
19
19
|
state = History.getState()
|
20
|
-
self._call(state.url, state.data.target, state.data.
|
20
|
+
self._call(state.url, state.data.target, state.data.render)
|
21
21
|
|
22
22
|
return false
|
23
23
|
)
|
@@ -43,31 +43,31 @@ class Wiselinks
|
|
43
43
|
return false
|
44
44
|
)
|
45
45
|
|
46
|
-
load: (url, target,
|
46
|
+
load: (url, target, render = 'template') ->
|
47
47
|
History.ready = true
|
48
|
-
History.pushState({ timestamp: (new Date().getTime()),
|
48
|
+
History.pushState({ timestamp: (new Date().getTime()), render: render, target: target }, document.title, decodeURI(url) )
|
49
49
|
|
50
50
|
reload: () ->
|
51
51
|
History.ready = true
|
52
|
-
History.replaceState({ timestamp: (new Date().getTime()),
|
52
|
+
History.replaceState({ timestamp: (new Date().getTime()), render: 'template' }, document.title, decodeURI(History.getState().url) )
|
53
53
|
|
54
|
-
_call: (url, target,
|
54
|
+
_call: (url, target, render = 'template') ->
|
55
55
|
self = this
|
56
|
-
$(document).trigger('
|
56
|
+
$(document).trigger('page:loading', url, target, render)
|
57
57
|
|
58
58
|
$.ajax(
|
59
59
|
url: url
|
60
60
|
headers:
|
61
|
-
'X-
|
61
|
+
'X-Render': render
|
62
62
|
success: (data, status, xhr) ->
|
63
63
|
document.title = xhr.getResponseHeader('X-Title')
|
64
64
|
|
65
65
|
$target = if target? then $(target) else self.$target
|
66
66
|
$target.html(data)
|
67
67
|
|
68
|
-
$(document).trigger('
|
68
|
+
$(document).trigger('page:success', data, status)
|
69
69
|
error: (xhr, status, error)->
|
70
|
-
$(document).trigger('
|
70
|
+
$(document).trigger('page:error', status, error)
|
71
71
|
dataType: "html"
|
72
72
|
)
|
73
73
|
|
data/lib/headers.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Wiselinks
|
2
|
+
module Headers
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def wiselinks_layout
|
7
|
+
'wiselinks'
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(options = {}, *args, &block)
|
11
|
+
if self.wiselinks_request?
|
12
|
+
if self.wiselinks_partial_request?
|
13
|
+
options[:partial] ||= action_name
|
14
|
+
else
|
15
|
+
options[:layout] = self.wiselinks_layout
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def wiselinks_request?
|
23
|
+
request.headers['X-Render'].present?
|
24
|
+
end
|
25
|
+
|
26
|
+
def wiselinks_template_request?
|
27
|
+
self.wiselinks_request? && request.headers['X-Render'] != 'partial'
|
28
|
+
end
|
29
|
+
|
30
|
+
def wiselinks_partial_request?
|
31
|
+
self.wiselinks_request? && request.headers['X-Render'] == 'partial'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/wiselinks.rb
CHANGED
data/wiselinks.gemspec
CHANGED
@@ -5,28 +5,28 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wiselinks"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
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
|
+
s.date = "2012-12-19"
|
13
13
|
s.email = "igor.alexandrov@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
|
-
"README.
|
16
|
+
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".document",
|
20
20
|
"Gemfile",
|
21
21
|
"Gemfile.lock",
|
22
22
|
"LICENSE.txt",
|
23
|
-
"README.
|
23
|
+
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"app/views/layouts/wiselinks.html.erb",
|
27
27
|
"lib/assets/javascripts/_history.js",
|
28
28
|
"lib/assets/javascripts/wiselinks.js.coffee",
|
29
|
-
"lib/
|
29
|
+
"lib/headers.rb",
|
30
30
|
"lib/wiselinks.rb",
|
31
31
|
"test/helper.rb",
|
32
32
|
"test/test_wiselinks.rb",
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
14
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: shoulda
|
@@ -83,19 +83,19 @@ executables: []
|
|
83
83
|
extensions: []
|
84
84
|
extra_rdoc_files:
|
85
85
|
- LICENSE.txt
|
86
|
-
- README.
|
86
|
+
- README.md
|
87
87
|
files:
|
88
88
|
- .document
|
89
89
|
- Gemfile
|
90
90
|
- Gemfile.lock
|
91
91
|
- LICENSE.txt
|
92
|
-
- README.
|
92
|
+
- README.md
|
93
93
|
- Rakefile
|
94
94
|
- VERSION
|
95
95
|
- app/views/layouts/wiselinks.html.erb
|
96
96
|
- lib/assets/javascripts/_history.js
|
97
97
|
- lib/assets/javascripts/wiselinks.js.coffee
|
98
|
-
- lib/
|
98
|
+
- lib/headers.rb
|
99
99
|
- lib/wiselinks.rb
|
100
100
|
- test/helper.rb
|
101
101
|
- test/test_wiselinks.rb
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash: -
|
118
|
+
hash: -2438141941057179076
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
none: false
|
121
121
|
requirements:
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= wiselinks
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to wiselinks
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2012 Igor Alexandrov. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
data/lib/layout.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Wiselinks
|
2
|
-
module Layout
|
3
|
-
|
4
|
-
def wiselinks_layout
|
5
|
-
'wiselinks'
|
6
|
-
end
|
7
|
-
|
8
|
-
def render(options = {}, *args, &block)
|
9
|
-
if request.headers['X-Slide'].present?
|
10
|
-
if request.headers['X-Slide'] == 'partial'
|
11
|
-
options[:partial] ||= action_name
|
12
|
-
else
|
13
|
-
options[:layout] = self.wiselinks_layout
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|