wiselinks 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,24 +6,64 @@ You may find Wiselinks similar to [Turbolinks](https://github.com/rails/turbolin
6
6
 
7
7
  ##Compatibility
8
8
 
9
- Wiselinks uses awesome [History.js](https://github.com/balupton/History.js/) library to perform requests.
10
-
11
- Wiselinks should work in all major browsers including browsers that do not support HTML History API out of the box.
12
-
9
+ Wiselinks uses [History.js](https://github.com/balupton/History.js/) library to perform requests.
10
+
11
+ Wiselinks works in all major browsers including browsers that do not support HTML History API out of the box.
12
+
13
+ ## In Comparison to Turbolinks
14
+
15
+ <table>
16
+ <thead>
17
+ <tr>
18
+ <th></th>
19
+ <th>Turbolinks</th>
20
+ <th>Wiselinks</th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <tr>
25
+ <td>Browsers with History API</td>
26
+ <td>Yes</td>
27
+ <td><strong>Yes</strong></td>
28
+ </tr>
29
+ <tr>
30
+ <td>Browsers without History API</td>
31
+ <td>No, degrades to normal request processing.</td>
32
+ <td><strong>Yes</strong></td>
33
+ </tr>
34
+ <tr>
35
+ <td>No JavaScript</td>
36
+ <td>No, degrades to normal request processing.</td>
37
+ <td>No, degrades to normal request processing.</td>
38
+ </tr>
39
+ <tr>
40
+ <td>Form processing</td>
41
+ <td>No</td>
42
+ <td><strong>Yes</strong></td>
43
+ </tr>
44
+ <tr>
45
+ <td>Form parameters optimization</td>
46
+ <td>No</td>
47
+ <td><strong>Yes</strong></td>
48
+ </tr>
49
+ </tbody>
50
+ </table>
13
51
 
14
52
  ##Installation
15
53
 
16
54
  Add this to your Gemfile:
17
-
18
- gem 'wiselinks'
55
+
56
+ ```ruby
57
+ gem 'wiselinks'
58
+ ```
19
59
 
20
60
  Then do:
21
61
 
22
- bundle
62
+ bundle install
23
63
 
24
64
  ## How does it work?
25
65
 
26
- Modify your `application.js` or `application.js.coffee` file to use Wiselinks object:
66
+ Modify your `application.js.coffee` file to use Wiselinks object:
27
67
 
28
68
  ```coffeescript
29
69
  #= require jquery
@@ -36,7 +76,7 @@ $(document).ready ->
36
76
  And finally you should tell Wiselinks to process your links or forms.
37
77
 
38
78
  Links will fire History.pushState() event.
39
- Data from the request will replace content of the container that was passed to Wiselinks (default is 'body')
79
+ Data from the request will replace content of the container that was passed to Wiselinks (default is "body")
40
80
 
41
81
 
42
82
  ```html
@@ -51,7 +91,7 @@ Data from the request will replace content of the container that was passed to W
51
91
  ```
52
92
 
53
93
  Link will fire History.replaceState() event.
54
- Data from the request will replace content of the container that was passed to Wiselinks (default is 'body')
94
+ Data from the request will replace content of the container that was passed to Wiselinks (default is "body")
55
95
 
56
96
  ```html
57
97
  <div class="dialog">
@@ -60,7 +100,7 @@ Data from the request will replace content of the container that was passed to W
60
100
  ```
61
101
 
62
102
  Links will fire History.pushState() event.
63
- Data from the request will be pasted into `<div role='catalog'>`. This configuration is widely when you have list of items that are paginated, sorted or maybe grouped by some attributes and you want to update only these items and nothing more on page.
103
+ Data from the request will be pasted into `<div role="catalog">`. This configuration is widely when you have list of items that are paginated, sorted or maybe grouped by some attributes and you want to update only these items and nothing more on page.
64
104
 
65
105
  ```html
66
106
  <ul class="pagination">
@@ -89,13 +129,13 @@ Data from the request will be pasted into `<div role='catalog'>`. This configura
89
129
  <div role="catalog">
90
130
  <!-- the list of your items -->
91
131
  ...
92
- </div
132
+ </div>
93
133
  ```
94
134
 
95
- **You can use Wiselinks with forms**! As easy and clear as with links. After submit button is clicked, Wiselinks will perform a request to "/" with serialized form attributes. The result of this request will be pasted into `<div role='catalog'>`.
135
+ **You can use Wiselinks with forms**! As easy and clear as with links. After submit button is clicked, Wiselinks will perform a request to "/" with serialized form attributes. The result of this request will be pasted into `<div role="catalog">`.
96
136
 
97
137
  ```html
98
- <div class='filter'>
138
+ <div class="filter">
99
139
  <form action="/" method="get" data-push="true" data-target="@catalog">
100
140
  <input type="text" size="30" name="title" id="title">
101
141
 
@@ -111,10 +151,10 @@ Data from the request will be pasted into `<div role='catalog'>`. This configura
111
151
  </form>
112
152
  </div>
113
153
 
114
- <div role='catalog'>
154
+ <div role="catalog">
115
155
  <!-- the list of your items -->
116
156
  ...
117
- </div
157
+ </div>
118
158
  ```
119
159
 
120
160
  You can add some options, if you want:
@@ -125,7 +165,7 @@ You can add some options, if you want:
125
165
  #= require wiselinks
126
166
 
127
167
  $(document).ready ->
128
- # DOM element with role = 'content' will be replaced after data load.
168
+ # DOM element with role = "content" will be replaced after data load.
129
169
  window.wiselinks = new Wiselinks($('@content'))
130
170
 
131
171
  # Of course you can use more traditional jQuery selectors.
@@ -160,7 +200,7 @@ While using Wiselinks you **can rely** on `DOMContentLoaded` or `jQuery.ready()`
160
200
 
161
201
  ### page:loading (url, target, render = 'template')
162
202
 
163
- Event is triggered before the `XMLHttpRequest` is initialized and performed.
203
+ Event is triggered before the `XMLHttpRequest` is initialised and performed.
164
204
  * *url* - URL of the request that will be performed;
165
205
 
166
206
  * *target* – element of the page where result of the request will be loaded into;
@@ -181,17 +221,17 @@ Event is triggered if the request fails.
181
221
  * *status* – a string describing the type of error that occurred;
182
222
  * *error* – optional exception object, if one occurred;
183
223
 
184
- ## ActionController::Base Methods
224
+ ## Request methods
185
225
 
186
- Wiselinks adds a couple of methods to your controller. These methods are mostly syntax sugar and don't have any complex logic, so you can use them or not.
226
+ 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.
187
227
 
188
- ### #wiselinks_request? ###
228
+ ### #wiselinks? ###
189
229
  Method returns `true` if current request is initiated by Wiselinks, `false` otherwise.
190
230
 
191
- ### #wiselinks\_template\_request? ###
231
+ ### #wiselinks_template? ###
192
232
  Method returns `true` if current request is initiated by Wiselinks and client want to render template, `false` otherwise.
193
233
 
194
- ### #wiselinks\_partial\_request? ###
234
+ ### #wiselinks_partial? ###
195
235
  Method returns `true` if current request is initiated by Wiselinks and client want to render partial, `false` otherwise.
196
236
 
197
237
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -0,0 +1,40 @@
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.request.wiselinks?
12
+ if self.request.wiselinks_partial?
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
+ Wiselinks::Logger.log "DEPRECATION WARNING: Method `wiselinks_request?` is deprecated. Please use `request.wiselinks?` instead."
24
+
25
+ self.request.wiselinks?
26
+ end
27
+
28
+ def wiselinks_template_request?
29
+ Wiselinks::Logger.log "DEPRECATION WARNING: Method `wiselinks_template_request?` is deprecated. Please use `request.wiselinks_template?` instead."
30
+
31
+ self.request.wiselinks_template?
32
+ end
33
+
34
+ def wiselinks_partial_request?
35
+ Wiselinks::Logger.log "DEPRECATION WARNING: Method `wiselinks_partial_request?` is deprecated. Please use `request.wiselinks_partial?` instead."
36
+
37
+ self.request.wiselinks_partial?
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Wiselinks
2
+ module Logger
3
+ extend self
4
+
5
+ def self.logger
6
+ @logger ||= ::Logger.new(STDOUT)
7
+ end
8
+
9
+ def logger=(logger)
10
+ @logger = logger
11
+ end
12
+
13
+ def log(message)
14
+ logger.info("[wiselinks] #{message}")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Wiselinks
2
+ module Request
3
+ def wiselinks?
4
+ self.headers['X-Render'].present?
5
+ end
6
+
7
+ def wiselinks_template?
8
+ self.wiselinks? && self.headers['X-Render'] != 'partial'
9
+ end
10
+
11
+ def wiselinks_partial?
12
+ self.wiselinks? && self.headers['X-Render'] == 'partial'
13
+ end
14
+ end
15
+ end
16
+
data/lib/wiselinks.rb CHANGED
@@ -1,11 +1,16 @@
1
- require 'headers'
1
+ require 'wiselinks/headers'
2
+ require 'wiselinks/request'
3
+ require 'wiselinks/logger'
2
4
 
3
5
  module Wiselinks
4
6
  class Engine < ::Rails::Engine
7
+ initializer 'wiselinks.setup_logger' do
8
+ Wiselinks::Logger.logger = Rails.logger
9
+ end
5
10
 
6
11
  initializer "wiselinks.register" do
7
12
  ActionController::Base.send :include, Headers
8
- end
9
-
13
+ ActionDispatch::Request.send :include, Request
14
+ end
10
15
  end
11
16
  end
data/wiselinks.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wiselinks"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.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"]
@@ -26,8 +26,10 @@ Gem::Specification.new do |s|
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/headers.rb",
30
29
  "lib/wiselinks.rb",
30
+ "lib/wiselinks/headers.rb",
31
+ "lib/wiselinks/logger.rb",
32
+ "lib/wiselinks/request.rb",
31
33
  "test/helper.rb",
32
34
  "test/test_wiselinks.rb",
33
35
  "wiselinks.gemspec"
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.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -95,8 +95,10 @@ files:
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/headers.rb
99
98
  - lib/wiselinks.rb
99
+ - lib/wiselinks/headers.rb
100
+ - lib/wiselinks/logger.rb
101
+ - lib/wiselinks/request.rb
100
102
  - test/helper.rb
101
103
  - test/test_wiselinks.rb
102
104
  - wiselinks.gemspec
@@ -115,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
117
  version: '0'
116
118
  segments:
117
119
  - 0
118
- hash: -4399132269606173208
120
+ hash: 2214557094717960689
119
121
  required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  none: false
121
123
  requirements:
data/lib/headers.rb DELETED
@@ -1,34 +0,0 @@
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