SrBuj 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDg3NWQxYWZjNWM3MTgyMWFhNjY1ZWZmNGRiYzFkOTZjNGE5ZGI1Yg==
5
- data.tar.gz: !binary |-
6
- MjBiY2Y3ZDY3MTNhMmUzYzkxYjczZjVkMzg0MmM3ZWZiODU2ZGU4Nw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MzQ3N2Q1MDg4YTY1YTNlNzkxOWU5YmFkNjI4YTI2YTYwOGUyZTQyY2UyMTVk
10
- NGQ0NmJhYzUyYzBmZmY4MGNkMmIwMDgwNGI5MDc3YjUzZDdjYjM5OTI4YjM2
11
- OGE2ODQ3NjdhMjMwZTc1YmRmZTFhNDFhYmRjYWE3YzE1YjIxMzE=
12
- data.tar.gz: !binary |-
13
- MjZmMWMyZjFjZGMxMmM2ZTA2Zjk0ZTE3MzVkOTM4YTg3OGZiN2M0OTgxODBk
14
- YmFlYzRmMTM1ZDAxMGI0YmUyNjQzMmJmMDEyY2M2YWRkZWIzY2EyZDVmMTZm
15
- MjYyN2I0ZDMzYWU2NjFhMGJmMDc0NGE0ZDZlNmMwNjdlYTczNDY=
2
+ SHA1:
3
+ metadata.gz: d57d1efa04c6824dc15dc61ae92b3e972111019c
4
+ data.tar.gz: bddf430716cf06249b94d97b44ec99602bd57d69
5
+ SHA512:
6
+ metadata.gz: b5249af11986231029f9dad485c67fed25661a32d931e79c57869d0f69484c65a281d85a744568f0c8e79d26c9905928a14f75f58e031171a7c6ac80a60d1430
7
+ data.tar.gz: 5cf71ac75514f968ddbad7e39dc9caf3a2c3fe78cd1878916c6438b67bd2eee6ff6aa06f199bd1b5d429daabf671cbc071fba854118943272133c5c5d4eea96a
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  SrBuj
2
2
  =
3
-
4
- [![Gem Version](https://badge.fury.io/rb/SrBuj.png)](https://rubygems.org/gems/SrBuj)[![Dependency Status](https://gemnasium.com/gagoar/SrBuj.png)](https://gemnasium.com/gagoar/SrBuj) [![Code Climate](https://codeclimate.com/github/gagoar/SrBuj.png)](https://codeclimate.com/github/gagoar/SrBuj.png)
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/SrBuj.png)](https://rubygems.org/gems/SrBuj)[![Dependency Status](https://gemnasium.com/gagoar/SrBuj.png)](https://gemnasium.com/gagoar/SrBuj) [![Code Climate](https://codeclimate.com/github/gagoar/SrBuj.png)](https://codeclimate.com/github/gagoar/SrBuj)[![Travis-CI](https://travis-ci.org/gagoar/SrBuj.png)](https://travis-ci.org/gagoar/SrBuj)[![endorse](https://api.coderwall.com/gagoar/endorsecount.png)](https://coderwall.com/gagoar)
5
5
 
6
6
  Better Unobtrusive JavaScript Respond (for Rails and jquery_ujs, twitter/bootstrap modal.js)
7
7
 
8
8
  SrBuj comes to cure a common illness in a life of every Rails developer (maybe other kind too):
9
+
9
10
  - write the same code to rise up a modal
10
11
  - render a partial on it.
11
12
  - change an element in a view without reload the entire web page
@@ -15,11 +16,11 @@ SrBuj comes to cure a common illness in a life of every Rails developer (maybe o
15
16
  - replace an specific element (PUT/PATCH)
16
17
  - bind a callback to run specific js function.
17
18
 
18
- every time, we end up with a lot of code, ugly code, messy code or at best with an old and known .js.rb file with the same 4 lines... Well enough it's enough!
19
+ Every time, we end up with a lot of code, ugly code, messy code or at best with an old and known .js.rb file with the same 4 lines... Well enough it's enough!
19
20
  This is the cure...and comes with a simple treatment too!
20
21
 
21
22
  Steps:
22
- -
23
+ =
23
24
 
24
25
  1. bundle the gem
25
26
  2. required in your manifest
@@ -30,8 +31,9 @@ This unobtrusive scripting support file is developed for the Ruby on Rails frame
30
31
 
31
32
  These features are achieved by adding certain ["data" attributes][data] to your HTML markup. In Rails, they are added by the framework's template helpers.
32
33
 
34
+
33
35
  Requirements
34
- ------------
36
+ =
35
37
 
36
38
  - [jQuery 1.7.x or higher](http://jquery.com/);
37
39
  - [jquery_ujs](https://github.com/rails/jquery-ujs)
@@ -41,7 +43,7 @@ Requirements
41
43
  If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail [W3C markup validation][validator]. However, this shouldn't create any issues for web browsers or other user agents.
42
44
 
43
45
  Installation
44
- ------------
46
+ =
45
47
 
46
48
  For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile:
47
49
 
@@ -53,9 +55,14 @@ And run:
53
55
 
54
56
  $ bundle install
55
57
 
56
- This next step depends on your version of Rails.
58
+ use the generator:
57
59
 
58
- a. For Rails 3.1, add these lines to the top of your app/assets/javascripts/application.js file:
60
+ $ bundle exec rails g sr_buj:install
61
+
62
+
63
+ or the manual way:
64
+
65
+ For Rails 3.1 and higher, add `//= require SrBuj` in your `app/assets/javascripts/application.js` file like this:
59
66
 
60
67
  ```javascript
61
68
  //= require jquery
@@ -63,22 +70,43 @@ a. For Rails 3.1, add these lines to the top of your app/assets/javascripts/appl
63
70
  //= require SrBuj
64
71
  ```
65
72
 
73
+ and add `*= require SrBuj` in your `app/assets/stylesheets/application.css` file:
74
+
75
+ ```css
76
+ /*
77
+ *= require_self
78
+ *= require SrBuj
79
+ *= require_tree .
80
+ */
81
+ ```
82
+
66
83
  Use and Options
67
- ---
68
- - target( data[target] ): depending on the type of request(GET/PUT/POST/DELETE) is used to alter the Dom. it represent the element that we want to alter in the view after an succceded request (needed)
69
- - modal( data[modal] ): if you wish that the response ends up in a modal. value: true|false (default false)
70
- - error (data[error]): id Element In a form data[error] is the holder in witch de form re renders to show the errors
71
- - replace(data[replace]): if you wish to replace de data[target] element with the response content on success. represent the PUT/PATCH action for SrBuj. value: true|false (default false)
72
- - remove (data[method:delete] && data[target]): if these are combined the success response execute a remove() over the data[target] element.
73
- - nochange (data[nochange]): do all but don't change the document in any way.
74
- - callback(data[callback]) = after a successeded request, call this function.
75
- - data[custom] = just proxy the response to my custom function in callback, nothing more.
76
- - jqueryselector(data[jqueryselector]): Change the data[target] & data[error] for selectors in jquery and find the element!
77
- - respond-as(data[respond-as]): We can alter the respond behavior without careing the method used on the request. values: GET/POST/PUT/PATCH/DELETE
78
- You can use it with any element available. (links forms tables divs anything).
84
+ =
85
+
86
+ - `data-target`: Depending on the type of request(`GET`/`PUT`/`POST`/`DELETE`) is used to alter the Dom. it represent the element that we want to alter in the view after an succceded request (needed)
87
+
88
+ - `data-modal`: If you wish that the response ends up in a modal (default: false).
89
+
90
+ - `data-error`: The id element where errors will be rendered if the response received a different state than 200(Ok).
91
+
92
+ - `data-delete`: On a successded response, remove the 'data-target' element from document.
93
+
94
+ - `data-nochange`: Don't alter the Document.(ignore the verb).
95
+
96
+ - `data-callback`: After a succeeded response, call this function.
97
+
98
+ - `data-custom`: Just proxy the response to `data-callback` function. (default: false).
99
+
100
+ - `data-jqueryselector`: Change the `data-target` & `data-error` for selectors in jquery and find the element!
101
+
102
+ - `data-respond-as`: We can alter the respond behavior without careing the method used on the request. values: `GET`/`POST`/`PUT`/`PATCH`/`DELETE`
103
+
104
+ - `data-push`: if there is a href or action in the element, replace the url.(default: false)
105
+
106
+ You can use it with any html element available. (links forms tables divs...Anything).
79
107
 
80
108
  Example
81
- =======
109
+ =
82
110
 
83
111
  modal
84
112
  ----
@@ -104,8 +132,28 @@ fine.
104
132
 
105
133
  that's it.
106
134
 
135
+ Testing
136
+ =
137
+
138
+ You need [Node](http://nodejs.org) and [Testem](https://github.com/airportyh/testem) to run the tests.
139
+
140
+ 1. Install
141
+
142
+ ````
143
+ npm install testem -g
144
+ ````
145
+
146
+ 2. Run
147
+
148
+ ````bash
149
+ testem ci # For test with all launchers
150
+ #### or  ####
151
+ testem # and enter in http://localhost:7357
152
+ ````
153
+
154
+
107
155
  Contributing
108
- ------------
156
+ =
109
157
 
110
158
  1. Fork it
111
159
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -114,8 +162,12 @@ Contributing
114
162
  5. Create new Pull Request
115
163
 
116
164
  Copyright
117
- ---------
165
+ =
118
166
 
119
167
  Copyright (c) 2013 gagoar. See LICENSE.txt for
120
168
  further details.
121
169
 
170
+
171
+
172
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gagoar/srbuj/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
173
+
@@ -1,12 +1,14 @@
1
1
  module SrBuj
2
2
  module ActionController
3
3
  module Helpers
4
- HEADERS = { message: 'X-SRBUJ-MSG',
5
- type: 'X-SRBUJ-TYPE',
6
- side: 'X-SRBUJ-SIDE',
7
- position: 'X-SRBUJ-POS',
8
- time: 'X-SRBUJ-TIME'
9
- }
4
+ HEADERS = {
5
+ message: 'X-SRBUJ-MSG',
6
+ type: 'X-SRBUJ-TYPE',
7
+ side: 'X-SRBUJ-SIDE',
8
+ position: 'X-SRBUJ-POS',
9
+ time: 'X-SRBUJ-TIME',
10
+ raw: 'X-SRBUJ-RAW'
11
+ }
10
12
  #=> helpfull method to return redirect_to in an js way.
11
13
  # use: js_redirect(to: root_path)
12
14
  # use: js_redirect(reload: true)
@@ -32,6 +34,8 @@ module SrBuj
32
34
  HEADERS.each do |value, header|
33
35
  response.headers[header] = options[value].to_s if options[value]
34
36
  end
37
+ else
38
+ response.headers['X-SRBUJ-REMOVE'] = 'true'
35
39
  end
36
40
  end
37
41
  end
@@ -1,3 +1,3 @@
1
1
  module SrBuj
2
- VERSION = '0.9.2'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -19,9 +19,17 @@
19
19
  };
20
20
  var SrBuj;
21
21
  $.SrBuj = SrBuj = {
22
- version: '0.9.2',
22
+ version: '0.10.0',
23
23
  selector: '[data-remote][data-target]',
24
- notifyHeaders: { message: 'X-SRBUJ-MSG', type: 'X-SRBUJ-TYPE', side: 'X-SRBUJ-SIDE', position: 'X-SRBUJ-POS', time: 'X-SRBUJ-TIME' },
24
+ notifyHeaders: {
25
+ message : 'X-SRBUJ-MSG',
26
+ type : 'X-SRBUJ-TYPE',
27
+ side : 'X-SRBUJ-SIDE',
28
+ position : 'X-SRBUJ-POS',
29
+ time : 'X-SRBUJ-TIME',
30
+ remove : 'X-SRBUJ-REMOVE',
31
+ raw : 'X-SRBUJ-RAW'
32
+ },
25
33
  defaults: {
26
34
  '$el': undefined,
27
35
  target: undefined,
@@ -86,10 +94,10 @@
86
94
  return respond_as.toUpperCase();
87
95
  } else
88
96
  if (dataVerb) {
89
- return dataVerb.toUpperCase();
97
+ return dataVerb.toUpperCase();
90
98
  } else {
91
99
  if (proto) {
92
- return replace ? 'PUT' : proto.toUpperCase();
100
+ return replace ? 'PUT' : proto.toUpperCase();
93
101
  }
94
102
  }
95
103
  },
@@ -115,7 +123,7 @@
115
123
  };
116
124
  user_options = user_options || {};
117
125
  for ( var attr in this.defaults ) {
118
- if ( this.defaults.hasOwnProperty( attr ) ) {
126
+ if ( this.defaults.hasOwnProperty(attr) ) {
119
127
  options[attr] = user_options[attr] || el_options[attr] || this.defaults[attr];
120
128
  }
121
129
  }
@@ -125,10 +133,11 @@
125
133
  if ( xhr ){
126
134
  var notify = {};
127
135
  for ( var attr in $.SrBuj.notifyHeaders )
128
- if ( $.SrBuj.notifyHeaders.hasOwnProperty( attr ) ) {
129
- notify[attr] = xhr.getResponseHeader( $.SrBuj.notifyHeaders[attr] );
136
+ if ( $.SrBuj.notifyHeaders.hasOwnProperty(attr) ) {
137
+ notify[attr] = xhr.getResponseHeader($.SrBuj.notifyHeaders[attr]);
130
138
  }
131
- if ( notify.message ){ $.SrBuj.Util.notify(notify) }
139
+ if (notify.message){ $.SrBuj.Util.notify(notify) }
140
+ if (notify.remove){ $.SrBuj.Util.removeNotify() }
132
141
  if ( (/javascript/).test( xhr.getResponseHeader('Content-Type') )){
133
142
  return true;
134
143
  }
@@ -172,11 +181,11 @@
172
181
  if (error) {
173
182
  $.SrBuj.changeDom('ERROR', $error, data.responseText);
174
183
  var notify = {};
175
- for ( var attr in $.SrBuj.notifyHeaders )
176
- if ( $.SrBuj.notifyHeaders.hasOwnProperty( attr ) ) {
177
- notify[attr] = data.getResponseHeader( $.SrBuj.notifyHeaders[attr] );
184
+ for (var attr in $.SrBuj.notifyHeaders)
185
+ if ($.SrBuj.notifyHeaders.hasOwnProperty(attr)) {
186
+ notify[attr] = data.getResponseHeader($.SrBuj.notifyHeaders[attr]);
178
187
  }
179
- if ( notify.message ){ $.SrBuj.Util.notify(notify) }
188
+ if (notify.message){ $.SrBuj.Util.notify(notify) }
180
189
  }else {
181
190
  throw 'cant find data-error on element ' + e.target + ' maybe content_type missing on response?';
182
191
  }
@@ -203,15 +212,25 @@
203
212
  }else{
204
213
  gMsg.className = 'alert-info';
205
214
  }
206
- gMsg.textContent = options.message;
215
+ gMsg.innerHTML = options.raw ? options.message
216
+ : $.SrBuj.Util.decodeUTF8(options.message);
207
217
  $('body').append(gMsg);
208
218
  gMsg.className += [' alert', options.side || 'right', options.position || 'bottom', 'srbuj-notify' ].join(' ').toLowerCase();
209
- options.time = Number( options.time ) > 0 ? options.time : 2000;
210
- $.SrBuj.gMsg_interval = window.setInterval( $.SrBuj.Util.removeNotify, options.time );
219
+ if (options.time != -1) {
220
+ options.time = Number(options.time) > 0 ? options.time : 2000;
221
+ $.SrBuj.gMsg_interval = window.setInterval( $.SrBuj.Util.removeNotify, options.time );
222
+ }
211
223
  },
212
224
  removeNotify: function(){
213
225
  $('#_growlingMsg').removeClass('srbuj-notify');
214
226
  },
227
+ randomCode: function(size) {
228
+ var size = !isNaN(size) && size < 12 ? size : 12
229
+ return Math.random().toString(36).substring(4).substring(0, size)
230
+ },
231
+ decodeUTF8: function(message) {
232
+ return decodeURIComponent(escape(message))
233
+ },
215
234
  link: function (user_options){
216
235
  /* This function will create a link with options, trigger it and remove the link afterwards
217
236
  * user_options must be a hash (Obj) with key: value without the data word
@@ -226,8 +245,20 @@
226
245
  var user_options = user_options || {};
227
246
  $.extend(user_options, {remote: true, srbuj: true});
228
247
  if(user_options.target && user_options.href){
229
- var _srbujLink = document.createElement('a');
230
- _srbujLink.id = '_srbujLink';
248
+ var _srbujLink = document.createElement('a'),
249
+ randomKey = $.SrBuj.Util.randomCode(6);
250
+
251
+ _srbujLink.id = ['_srbujLink', randomKey].join('_');
252
+ if (user_options.force_refresh) {
253
+ var params = { key: randomKey }
254
+ , urlParams = $.param(params)
255
+ , splitedUrl = user_options.href.split(/\?.+/)
256
+ , joinChar = (splitedUrl.length > 1) ? '&'
257
+ : splitedUrl[0].match(/\?$/) ? ''
258
+ : '?';
259
+
260
+ user_options.href += joinChar + urlParams;
261
+ }
231
262
  _srbujLink.href = user_options.href;
232
263
  delete user_options.href;
233
264
  for (var attr in user_options) {
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SrBuj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gagoar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jquery-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Better Unobtrusive JavaScript Respond
@@ -93,19 +93,18 @@ require_paths:
93
93
  - lib
94
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ! '>='
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.0.3
106
+ rubygems_version: 2.1.11
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: http://github.com/gagoar/SrBuj/
110
110
  test_files: []
111
- has_rdoc: