turboboost 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fbdb36ff6054cee71ee37b77fa106f9b581da49
4
- data.tar.gz: c7cd477b42b90defe122a8003d026da47a8463f8
3
+ metadata.gz: 342cf6bee532936cb72f690d7687fc636653d85f
4
+ data.tar.gz: 65b2adc80aa8836788c46ed5726d07e3c201cca9
5
5
  SHA512:
6
- metadata.gz: 4dad87536b15bcd6f9f7a5f882b4fd5257683371d9a3bb78ca837172d16efc9643671ecfd2797cd78f553cdbbaacf193bd3ab0f703861adeff09a08f628b8d82
7
- data.tar.gz: 56a37fa040c88c52e94d3ca4e3894fcd39602594c933708abe67f8541b424032868af6b1dee44bb4f39c9712bf7111c34d1a3aae601cad35cb19f40c001d4ad6
6
+ metadata.gz: 1ee7efb5e37ca4d706fbaea72ec214e1f14b4fe2df6c924ba97802947f7268f72e0090920236833f0324c6d53acc5e68d51f1de7e4e4bb03c2e1761895b4ce8e
7
+ data.tar.gz: 79e898afea4fc256f11815661f0635a6eb37d02adcd0f971c3d5601429eaa3b565aa2774e9b78983409d454e0c5fa8d6fdc16ddf38aa7099e79e6ec503394302
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  /*.gem
2
+ /TAGS
data/Appraisals ADDED
@@ -0,0 +1,17 @@
1
+ appraise 'rails-3-2' do
2
+ gem 'rails', '~> 3.2.21'
3
+ gem 'strong_parameters'
4
+ end
5
+
6
+ appraise 'rails-4-0' do
7
+ gem 'rails', '~> 4.0.13'
8
+ end
9
+
10
+ appraise 'rails-4-1' do
11
+ gem 'rails', '~> 4.1.9'
12
+ end
13
+
14
+ appraise 'rails-4-2' do
15
+ gem 'rails', '~> 4.2.0'
16
+ gem 'responders', '~> 2.0'
17
+ end
data/Gemfile CHANGED
@@ -2,8 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '>= 3.2', '< 5'
6
5
  gem 'mocha'
7
6
  gem 'turn'
8
7
  gem 'awesome_print'
9
8
  gem 'sqlite3'
9
+ gem 'appraisal'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turboboost (0.0.10)
4
+ turboboost (0.0.11)
5
5
  coffee-rails
6
6
  jquery-rails
7
7
  railties
@@ -10,10 +10,6 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionmailer (4.1.0)
14
- actionpack (= 4.1.0)
15
- actionview (= 4.1.0)
16
- mail (~> 2.5.4)
17
13
  actionpack (4.1.0)
18
14
  actionview (= 4.1.0)
19
15
  activesupport (= 4.1.0)
@@ -23,13 +19,6 @@ GEM
23
19
  activesupport (= 4.1.0)
24
20
  builder (~> 3.1)
25
21
  erubis (~> 2.7.0)
26
- activemodel (4.1.0)
27
- activesupport (= 4.1.0)
28
- builder (~> 3.1)
29
- activerecord (4.1.0)
30
- activemodel (= 4.1.0)
31
- activesupport (= 4.1.0)
32
- arel (~> 5.0.0)
33
22
  activesupport (4.1.0)
34
23
  i18n (~> 0.6, >= 0.6.9)
35
24
  json (~> 1.7, >= 1.7.7)
@@ -37,7 +26,10 @@ GEM
37
26
  thread_safe (~> 0.1)
38
27
  tzinfo (~> 1.1)
39
28
  ansi (1.4.3)
40
- arel (5.0.1.20140414130214)
29
+ appraisal (1.0.2)
30
+ bundler
31
+ rake
32
+ thor (>= 0.14.0)
41
33
  awesome_print (1.2.0)
42
34
  builder (3.2.2)
43
35
  coffee-rails (4.1.0)
@@ -49,57 +41,27 @@ GEM
49
41
  coffee-script-source (1.8.0)
50
42
  erubis (2.7.0)
51
43
  execjs (2.2.2)
52
- hike (1.2.3)
53
44
  i18n (0.6.9)
54
45
  jquery-rails (3.1.2)
55
46
  railties (>= 3.0, < 5.0)
56
47
  thor (>= 0.14, < 2.0)
57
48
  json (1.8.1)
58
- mail (2.5.4)
59
- mime-types (~> 1.16)
60
- treetop (~> 1.4.8)
61
49
  metaclass (0.0.1)
62
- mime-types (1.25.1)
63
50
  minitest (5.3.3)
64
51
  mocha (0.14.0)
65
52
  metaclass (~> 0.0.1)
66
- multi_json (1.9.2)
67
- polyglot (0.3.4)
68
53
  rack (1.5.2)
69
54
  rack-test (0.6.2)
70
55
  rack (>= 1.0)
71
- rails (4.1.0)
72
- actionmailer (= 4.1.0)
73
- actionpack (= 4.1.0)
74
- actionview (= 4.1.0)
75
- activemodel (= 4.1.0)
76
- activerecord (= 4.1.0)
77
- activesupport (= 4.1.0)
78
- bundler (>= 1.3.0, < 2.0)
79
- railties (= 4.1.0)
80
- sprockets-rails (~> 2.0)
81
56
  railties (4.1.0)
82
57
  actionpack (= 4.1.0)
83
58
  activesupport (= 4.1.0)
84
59
  rake (>= 0.8.7)
85
60
  thor (>= 0.18.1, < 2.0)
86
61
  rake (0.9.6)
87
- sprockets (2.12.1)
88
- hike (~> 1.2)
89
- multi_json (~> 1.0)
90
- rack (~> 1.0)
91
- tilt (~> 1.1, != 1.3.0)
92
- sprockets-rails (2.1.3)
93
- actionpack (>= 3.0)
94
- activesupport (>= 3.0)
95
- sprockets (~> 2.8)
96
62
  sqlite3 (1.3.10)
97
63
  thor (0.19.1)
98
64
  thread_safe (0.3.3)
99
- tilt (1.4.1)
100
- treetop (1.4.15)
101
- polyglot
102
- polyglot (>= 0.3.1)
103
65
  turbolinks (2.5.2)
104
66
  coffee-rails
105
67
  turn (0.9.6)
@@ -111,10 +73,10 @@ PLATFORMS
111
73
  ruby
112
74
 
113
75
  DEPENDENCIES
76
+ appraisal
114
77
  awesome_print
115
78
  bundler (~> 1.3)
116
79
  mocha
117
- rails (>= 3.2, < 5)
118
80
  rake (~> 0)
119
81
  sqlite3
120
82
  turboboost!
data/README.md CHANGED
@@ -1,17 +1,17 @@
1
- ## Turboboost
1
+ ## Turboboost ##
2
2
 
3
- Turboboost extends the power of Turbolinks into the forms of your Rails app and provides additional convenient AJAX handlers for forms and links. It aims to be a seemless and logical addition to any Turbolinks-rocking Rails 3.2+/4+ app. Currently it depends on jQuery. The main features are:
3
+ Turboboost extends the power of Turbolinks into the forms of your Rails app and provides additional convenient AJAX handlers for forms and links. It aims to be a seemless and logical addition to any Turbolinks-rocking Rails 3.2/4+ app. Currently it depends on jQuery. The main features are:
4
4
 
5
5
  * Form response redirection is handled by Turbolinks.
6
6
  * Customizable success and error handling through registered JavaScript, with support for Rails' Flash and optional error rendering built-in.
7
7
  * Responses can also be rendered within a scoped DOM target using jQuery selectors.
8
8
 
9
- ### Installation
9
+ ### Installation ###
10
10
 
11
11
  In your `Gemfile`:
12
12
 
13
13
  ``` ruby
14
- gem "turboboost"
14
+ gem 'turboboost'
15
15
  ```
16
16
 
17
17
  In your `application.js`:
@@ -29,10 +29,10 @@ Then in your view files, add `turboboost: true` to your form helpers:
29
29
  or add the data attribute manually:
30
30
 
31
31
  ```
32
- <form data-turboboost> ...
32
+ <form data-remote data-turboboost> ...
33
33
  ```
34
34
 
35
- ### Redirection with Turbolinks
35
+ ### Redirection with Turbolinks ###
36
36
 
37
37
  In its simplest server-side implementation, a basic Turboboost controller action with redirection might look like this:
38
38
 
@@ -43,11 +43,21 @@ def create
43
43
  end
44
44
  ```
45
45
 
46
- If the post is successfully created through a Turboboost-ed form, the app will visit the post's URL with Turbolinks. Otherwise, the redirect will happen like normal.
46
+ If the post is successfully created through a Turboboost-ed form, the app will visit the post's URL with Turbolinks. Otherwise, the redirect will happen like normal. You can opt out of redirecting through Turboboost with the attribute flag `data-no-turboboost-redirect`.
47
47
 
48
- If a Turboboost form makes a GET request, it will serialize the form's data and then visit its action URL with the data serialized as parameters with Turbolinks.
48
+ ### Form GET requests ###
49
49
 
50
- ### Error handling
50
+ If a Turboboost form makes a GET request, it will serialize the form's data and then visit its action URL with the data serialized as parameters with Turbolinks. This allows Turbolinks-powered cached push/popState history navigation of controller actions with different parameter values (like a search form).
51
+
52
+ ### Automatic form disabling handling ###
53
+
54
+ To prevent double-clicks on submit buttons from firing the form's action twice, Turboboost comes with automatic form disabling/enabling by default. When you restore a page from Turbolinks' cache, it will re-enable any submit buttons that it had disabled. You can disable this behavior and control your form's submittable state manually with:
55
+
56
+ ``` coffeescript
57
+ Turboboost.handleFormDisabling = false
58
+ ```
59
+
60
+ ### Error handling ###
51
61
 
52
62
  If the post in our example above is invalid, no redirect will happen and a `rescue_from` handler will pass the errors to JavaScript through the `turboboost:error` event:
53
63
 
@@ -73,7 +83,9 @@ def create
73
83
  end
74
84
  ```
75
85
 
76
- #### Automatic error message insertion
86
+ Check out the [test controllers](https://github.com/waymondo/turboboost/tree/master/test/controllers) for more examples of controller syntax.
87
+
88
+ #### Automatic error message insertion ####
77
89
 
78
90
  Optionally, Turboboost can render returned errors with the same HTML structure used in the default Rails generators and prepend it to the form. The HTML structure looks like this:
79
91
 
@@ -90,18 +102,18 @@ Optionally, Turboboost can render returned errors with the same HTML structure u
90
102
  To turn it on:
91
103
 
92
104
  ``` coffeescript
93
- Turboboost.insertErrors = true
94
- ```
95
-
96
- By default, this will prepend the error message to the form. Other values can be "append", "beforeSubmit", "afterSubmit", or any jQuery selector within the form:
97
-
98
- ``` coffeescript
99
- Turboboost.insertErrors = '.error-wrap'
105
+ Turboboost.insertErrors = true # same as 'prepend'
106
+ # other possible values:
107
+ # Turboboost.insertErrors = 'append'
108
+ # Turboboost.insertErrors = 'beforeSubmit'
109
+ # Turboboost.insertErrors = 'afterSubmit'
110
+ # can also be a jQuery selector:
111
+ # Turboboost.insertErrors = '.error-wrap'
100
112
  ```
101
113
 
102
- #### Error internationalization
114
+ #### Error internationalization ####
103
115
 
104
- Currently Turboboost will handle invalid `ActiveRecord` and `ActiveModel` error messages as well as basic HTTP error messages. For ActiveRecord validations, it will use [Rails' I18n lookup](http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models) to retrieve the message wording. For other raised exceptions, you can customize the basic wording using the I18n namespace format `turboboost.errors.#{error.class.name}`:
116
+ Turboboost will handle invalid `ActiveRecord` and `ActiveModel` error messages as well as basic HTTP error messages. For ActiveRecord validations, it will use [Rails' I18n lookup](http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models) to retrieve the message wording. For other raised exceptions, you can customize the basic wording using the I18n namespace format `turboboost.errors.#{error.class.name}`:
105
117
 
106
118
  ``` yaml
107
119
  en:
@@ -110,16 +122,16 @@ en:
110
122
  "ActiveRecord::RecordNotFound": "Shoot, didn't find anything."
111
123
  ```
112
124
 
113
- ### Ajax flash message handling
125
+ ### Ajax flash message handling ###
114
126
 
115
- There is also a `turboboost:success` event that is triggered and passed a hash of all current flash messages if they are present:
127
+ There is also a `turboboost:success` event that is triggered and passed all current flash messages if they are present:
116
128
 
117
129
  ``` coffeescript
118
130
  $(document).on "turboboost:success", (e, flash) ->
119
131
  console.log(flash) # -> {'notice': 'Post was successfully created.'}
120
132
  ```
121
133
 
122
- ### Scoped response rendering
134
+ ### Scoped response rendering ###
123
135
 
124
136
  Turboboost also provides some options for rendering AJAX responses at specific locations in the DOM:
125
137
 
@@ -129,6 +141,8 @@ Turboboost also provides some options for rendering AJAX responses at specific l
129
141
  |`:replace` |`replaceWith()` |
130
142
  |`:prepend` |`prepend()` |
131
143
  |`:append` |`append()` |
144
+ |`:before` |`before()` |
145
+ |`:after` |`after()` |
132
146
 
133
147
  The value can be any jQuery selector. Example usage:
134
148
 
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler/setup'
2
4
 
3
5
  require 'bundler/gem_tasks'
4
6
  require 'rake/testtask'
@@ -4,6 +4,7 @@
4
4
 
5
5
  @Turboboost =
6
6
  insertErrors: false
7
+ handleFormDisabling: true
7
8
  defaultError: "Sorry, there was an error."
8
9
 
9
10
  turboboostable = "[data-turboboost]"
@@ -12,10 +13,10 @@ errTemplate = (errors) ->
12
13
  "<ul><li>#{$.makeArray(errors).join('</li><li>')}</li></ul>"
13
14
 
14
15
  enableForm = ($form) ->
15
- $form.find("[type='submit']").removeAttr('disabled')
16
+ $form.find("[type='submit']").removeAttr('disabled').data('turboboostDisabled', false)
16
17
 
17
18
  disableForm = ($form) ->
18
- $form.find("[type='submit']").attr('disabled', 'disabled')
19
+ $form.find("[type='submit']").attr('disabled', 'disabled').data('turboboostDisabled', true)
19
20
 
20
21
  tryJSONParse = (str) ->
21
22
  try
@@ -53,11 +54,11 @@ turboboostComplete = (e, resp) ->
53
54
  if (location = resp.getResponseHeader('Location')) and !$el.attr('data-no-turboboost-redirect')
54
55
  Turbolinks.visit(location)
55
56
  else
56
- enableForm $el if isForm
57
+ enableForm $el if isForm and Turboboost.handleFormDisabling
57
58
  maybeInsertSuccessResponseBody(resp)
58
59
 
59
60
  if resp.status in [400..599]
60
- enableForm $el if isForm
61
+ enableForm $el if isForm and Turboboost.handleFormDisabling
61
62
  $el.trigger "turboboost:error", resp.responseText
62
63
 
63
64
  $el.trigger "turboboost:complete"
@@ -66,9 +67,10 @@ turboboostBeforeSend = (e, xhr, settings) ->
66
67
  xhr.setRequestHeader('X-Turboboost', '1')
67
68
  isForm = @nodeName is "FORM"
68
69
  return e.stopPropagation() unless isForm
69
- disableForm $(@)
70
- if settings.type is "GET"
71
- Turbolinks.visit [@action, $(@).serialize()].join("?")
70
+ $el = $(@)
71
+ disableForm $el if Turboboost.handleFormDisabling
72
+ if settings.type is "GET" and !$el.attr('data-no-turboboost-redirect')
73
+ Turbolinks.visit [@action, $el.serialize()].join("?")
72
74
  return false
73
75
 
74
76
  maybeInsertSuccessResponseBody = (resp) ->
@@ -80,8 +82,18 @@ maybeInsertSuccessResponseBody = (resp) ->
80
82
  $(scope).append(resp.responseText)
81
83
  else if (scope = resp.getResponseHeader('X-Prepend'))
82
84
  $(scope).prepend(resp.responseText)
85
+ else if (scope = resp.getResponseHeader('X-Before'))
86
+ $(scope).before(resp.responseText)
87
+ else if (scope = resp.getResponseHeader('X-After'))
88
+ $(scope).after(resp.responseText)
89
+
90
+ maybeReenableForms = ->
91
+ return unless Turboboost.handleFormDisabling
92
+ $("form#{turboboostable} input[type='submit']").each ->
93
+ enableForm $(@).closest('form') if $(@).data('turboboostDisabled')
83
94
 
84
95
  $(document)
85
96
  .on("ajax:beforeSend", turboboostable, turboboostBeforeSend)
86
97
  .on("ajax:complete", turboboostable, turboboostComplete)
87
98
  .on("turboboost:error", "form#{turboboostable}", turboboostFormError)
99
+ .on("page:restore", maybeReenableForms)
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mocha"
6
+ gem "turn"
7
+ gem "awesome_print"
8
+ gem "sqlite3"
9
+ gem "appraisal"
10
+ gem "rails", "~> 3.2.21"
11
+ gem "strong_parameters"
12
+
13
+ gemspec :path => "../"
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ turboboost (0.0.11)
5
+ coffee-rails
6
+ jquery-rails
7
+ railties
8
+ turbolinks
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.21)
14
+ actionpack (= 3.2.21)
15
+ mail (~> 2.5.4)
16
+ actionpack (3.2.21)
17
+ activemodel (= 3.2.21)
18
+ activesupport (= 3.2.21)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ journey (~> 1.0.4)
22
+ rack (~> 1.4.5)
23
+ rack-cache (~> 1.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.2.1)
26
+ activemodel (3.2.21)
27
+ activesupport (= 3.2.21)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.21)
30
+ activemodel (= 3.2.21)
31
+ activesupport (= 3.2.21)
32
+ arel (~> 3.0.2)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.21)
35
+ activemodel (= 3.2.21)
36
+ activesupport (= 3.2.21)
37
+ activesupport (3.2.21)
38
+ i18n (~> 0.6, >= 0.6.4)
39
+ multi_json (~> 1.0)
40
+ ansi (1.5.0)
41
+ appraisal (1.0.2)
42
+ bundler
43
+ rake
44
+ thor (>= 0.14.0)
45
+ arel (3.0.3)
46
+ awesome_print (1.6.1)
47
+ builder (3.0.4)
48
+ coffee-rails (3.2.2)
49
+ coffee-script (>= 2.2.0)
50
+ railties (~> 3.2.0)
51
+ coffee-script (2.3.0)
52
+ coffee-script-source
53
+ execjs
54
+ coffee-script-source (1.8.0)
55
+ erubis (2.7.0)
56
+ execjs (2.2.2)
57
+ hike (1.2.3)
58
+ i18n (0.7.0)
59
+ journey (1.0.4)
60
+ jquery-rails (3.1.2)
61
+ railties (>= 3.0, < 5.0)
62
+ thor (>= 0.14, < 2.0)
63
+ json (1.8.2)
64
+ mail (2.5.4)
65
+ mime-types (~> 1.16)
66
+ treetop (~> 1.4.8)
67
+ metaclass (0.0.4)
68
+ mime-types (1.25.1)
69
+ minitest (4.7.5)
70
+ mocha (1.1.0)
71
+ metaclass (~> 0.0.1)
72
+ multi_json (1.10.1)
73
+ polyglot (0.3.5)
74
+ rack (1.4.5)
75
+ rack-cache (1.2)
76
+ rack (>= 0.4)
77
+ rack-ssl (1.3.4)
78
+ rack
79
+ rack-test (0.6.3)
80
+ rack (>= 1.0)
81
+ rails (3.2.21)
82
+ actionmailer (= 3.2.21)
83
+ actionpack (= 3.2.21)
84
+ activerecord (= 3.2.21)
85
+ activeresource (= 3.2.21)
86
+ activesupport (= 3.2.21)
87
+ bundler (~> 1.0)
88
+ railties (= 3.2.21)
89
+ railties (3.2.21)
90
+ actionpack (= 3.2.21)
91
+ activesupport (= 3.2.21)
92
+ rack-ssl (~> 1.3.2)
93
+ rake (>= 0.8.7)
94
+ rdoc (~> 3.4)
95
+ thor (>= 0.14.6, < 2.0)
96
+ rake (0.9.6)
97
+ rdoc (3.12.2)
98
+ json (~> 1.4)
99
+ sprockets (2.2.3)
100
+ hike (~> 1.2)
101
+ multi_json (~> 1.0)
102
+ rack (~> 1.0)
103
+ tilt (~> 1.1, != 1.3.0)
104
+ sqlite3 (1.3.10)
105
+ strong_parameters (0.2.3)
106
+ actionpack (~> 3.0)
107
+ activemodel (~> 3.0)
108
+ activesupport (~> 3.0)
109
+ railties (~> 3.0)
110
+ thor (0.19.1)
111
+ tilt (1.4.1)
112
+ treetop (1.4.15)
113
+ polyglot
114
+ polyglot (>= 0.3.1)
115
+ turbolinks (2.5.3)
116
+ coffee-rails
117
+ turn (0.9.7)
118
+ ansi
119
+ minitest (~> 4)
120
+ tzinfo (0.3.42)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ appraisal
127
+ awesome_print
128
+ bundler (~> 1.3)
129
+ mocha
130
+ rails (~> 3.2.21)
131
+ rake (~> 0)
132
+ sqlite3
133
+ strong_parameters
134
+ turboboost!
135
+ turn