turboboost 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73ee25271c4886c00be8630d4c0d67528d3235f8
4
- data.tar.gz: 9de2982e9a0b21bc5995042389ee3b471b95ee19
3
+ metadata.gz: 0fbdb36ff6054cee71ee37b77fa106f9b581da49
4
+ data.tar.gz: c7cd477b42b90defe122a8003d026da47a8463f8
5
5
  SHA512:
6
- metadata.gz: 9c8e3d5fa568072f870a34570a5825b503076321e3c36c7726a2321012cd2f1ec8f2cf2d0278a53c5ef0d38fb2d4ce119f1d5ded11e096b4f91c0a2df6deb038
7
- data.tar.gz: 9cd1f714801f13e2186752b4608ea1db6f7f38276bf9d30bb6ffdeb9cd11b7dad76bb8b72a4f3b643cb54cbf4f049ec240b27f60ad98d3d58f2fa55237e1a0c5
6
+ metadata.gz: 4dad87536b15bcd6f9f7a5f882b4fd5257683371d9a3bb78ca837172d16efc9643671ecfd2797cd78f553cdbbaacf193bd3ab0f703861adeff09a08f628b8d82
7
+ data.tar.gz: 56a37fa040c88c52e94d3ca4e3894fcd39602594c933708abe67f8541b424032868af6b1dee44bb4f39c9712bf7111c34d1a3aae601cad35cb19f40c001d4ad6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turboboost (0.0.8)
4
+ turboboost (0.0.10)
5
5
  coffee-rails
6
6
  jquery-rails
7
7
  railties
@@ -40,18 +40,18 @@ GEM
40
40
  arel (5.0.1.20140414130214)
41
41
  awesome_print (1.2.0)
42
42
  builder (3.2.2)
43
- coffee-rails (4.0.1)
43
+ coffee-rails (4.1.0)
44
44
  coffee-script (>= 2.2.0)
45
45
  railties (>= 4.0.0, < 5.0)
46
- coffee-script (2.2.0)
46
+ coffee-script (2.3.0)
47
47
  coffee-script-source
48
48
  execjs
49
- coffee-script-source (1.7.0)
49
+ coffee-script-source (1.8.0)
50
50
  erubis (2.7.0)
51
- execjs (2.0.2)
51
+ execjs (2.2.2)
52
52
  hike (1.2.3)
53
53
  i18n (0.6.9)
54
- jquery-rails (3.1.0)
54
+ jquery-rails (3.1.2)
55
55
  railties (>= 3.0, < 5.0)
56
56
  thor (>= 0.14, < 2.0)
57
57
  json (1.8.1)
@@ -83,7 +83,7 @@ GEM
83
83
  activesupport (= 4.1.0)
84
84
  rake (>= 0.8.7)
85
85
  thor (>= 0.18.1, < 2.0)
86
- rake (10.3.1)
86
+ rake (0.9.6)
87
87
  sprockets (2.12.1)
88
88
  hike (~> 1.2)
89
89
  multi_json (~> 1.0)
@@ -93,14 +93,14 @@ GEM
93
93
  actionpack (>= 3.0)
94
94
  activesupport (>= 3.0)
95
95
  sprockets (~> 2.8)
96
- sqlite3 (1.3.8)
96
+ sqlite3 (1.3.10)
97
97
  thor (0.19.1)
98
98
  thread_safe (0.3.3)
99
99
  tilt (1.4.1)
100
100
  treetop (1.4.15)
101
101
  polyglot
102
102
  polyglot (>= 0.3.1)
103
- turbolinks (2.2.2)
103
+ turbolinks (2.5.2)
104
104
  coffee-rails
105
105
  turn (0.9.6)
106
106
  ansi
@@ -115,7 +115,7 @@ DEPENDENCIES
115
115
  bundler (~> 1.3)
116
116
  mocha
117
117
  rails (>= 3.2, < 5)
118
- rake
118
+ rake (~> 0)
119
119
  sqlite3
120
120
  turboboost!
121
121
  turn
data/README.md CHANGED
@@ -32,9 +32,7 @@ or add the data attribute manually:
32
32
  <form data-turboboost> ...
33
33
  ```
34
34
 
35
- ### Usage
36
-
37
- #### Redirection with Turbolinks
35
+ ### Redirection with Turbolinks
38
36
 
39
37
  In its simplest server-side implementation, a basic Turboboost controller action with redirection might look like this:
40
38
 
@@ -47,7 +45,9 @@ end
47
45
 
48
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.
49
47
 
50
- #### Error Handling and Flash Messages
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.
49
+
50
+ ### Error handling
51
51
 
52
52
  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
53
 
@@ -73,6 +73,8 @@ def create
73
73
  end
74
74
  ```
75
75
 
76
+ #### Automatic error message insertion
77
+
76
78
  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:
77
79
 
78
80
  ``` html
@@ -91,7 +93,24 @@ To turn it on:
91
93
  Turboboost.insertErrors = true
92
94
  ```
93
95
 
94
- Currently Turboboost will handle invalid `ActiveRecord` and `ActiveModel` error messages as well as basic HTTP error messages.
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'
100
+ ```
101
+
102
+ #### Error internationalization
103
+
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}`:
105
+
106
+ ``` yaml
107
+ en:
108
+ turboboost:
109
+ errors:
110
+ "ActiveRecord::RecordNotFound": "Shoot, didn't find anything."
111
+ ```
112
+
113
+ ### Ajax flash message handling
95
114
 
96
115
  There is also a `turboboost:success` event that is triggered and passed a hash of all current flash messages if they are present:
97
116
 
@@ -100,7 +119,7 @@ $(document).on "turboboost:success", (e, flash) ->
100
119
  console.log(flash) # -> {'notice': 'Post was successfully created.'}
101
120
  ```
102
121
 
103
- #### Scoped response rendering
122
+ ### Scoped response rendering
104
123
 
105
124
  Turboboost also provides some options for rendering AJAX responses at specific locations in the DOM:
106
125
 
@@ -111,7 +130,7 @@ Turboboost also provides some options for rendering AJAX responses at specific l
111
130
  |`:prepend` |`prepend()` |
112
131
  |`:append` |`append()` |
113
132
 
114
- The value can be any jQuery selector. Examples usage:
133
+ The value can be any jQuery selector. Example usage:
115
134
 
116
135
  ``` ruby
117
136
  respond_to do |format|
@@ -17,6 +17,12 @@ enableForm = ($form) ->
17
17
  disableForm = ($form) ->
18
18
  $form.find("[type='submit']").attr('disabled', 'disabled')
19
19
 
20
+ tryJSONParse = (str) ->
21
+ try
22
+ JSON.parse str
23
+ catch e
24
+ null
25
+
20
26
  turboboostFormError = (e, errors) ->
21
27
  return if !Turboboost.insertErrors
22
28
  errors = tryJSONParse errors
@@ -24,7 +30,17 @@ turboboostFormError = (e, errors) ->
24
30
  $form = $(e.target)
25
31
  $el = $form.find(errID)
26
32
  if !$el.length
27
- $form.prepend $el = $("<div id='#{errID.substr(1)}'></div>")
33
+ $el = $("<div id='#{errID.substr(1)}'></div>")
34
+ switch Turboboost.insertErrors
35
+ when "append" then $form.append($el)
36
+ when "beforeSubmit" then $form.find("[type='submit']").before($el)
37
+ when "afterSubmit" then $form.find("[type='submit']").after($el)
38
+ when true then $form.prepend($el)
39
+ else
40
+ if Turboboost.insertErrors.match(/^\W+/)
41
+ $form.find(Turboboost.insertErrors).html($el)
42
+ else
43
+ $form.prepend($el)
28
44
  $el.html errTemplate(errors)
29
45
 
30
46
  turboboostComplete = (e, resp) ->
@@ -33,6 +49,7 @@ turboboostComplete = (e, resp) ->
33
49
 
34
50
  if resp.status in [200..299]
35
51
  $el.trigger "turboboost:success", tryJSONParse resp.getResponseHeader('X-Flash')
52
+ $el.find(errID).remove() if Turboboost.insertErrors and isForm
36
53
  if (location = resp.getResponseHeader('Location')) and !$el.attr('data-no-turboboost-redirect')
37
54
  Turbolinks.visit(location)
38
55
  else
@@ -50,16 +67,10 @@ turboboostBeforeSend = (e, xhr, settings) ->
50
67
  isForm = @nodeName is "FORM"
51
68
  return e.stopPropagation() unless isForm
52
69
  disableForm $(@)
53
- if settings.type == "GET"
70
+ if settings.type is "GET"
54
71
  Turbolinks.visit [@action, $(@).serialize()].join("?")
55
72
  return false
56
73
 
57
- tryJSONParse = (str) ->
58
- try
59
- JSON.parse str
60
- catch e
61
- null
62
-
63
74
  maybeInsertSuccessResponseBody = (resp) ->
64
75
  if (scope = resp.getResponseHeader('X-Within'))
65
76
  $(scope).html(resp.responseText)
@@ -28,10 +28,13 @@ module Turboboost
28
28
  def turboboost_error_handler(error)
29
29
  if request.xhr? and request.headers['HTTP_X_TURBOBOOST']
30
30
  error_status = CATCHABLE_ERRORS[error.class.name]
31
+ response.headers["X-Turboboosted"] = "1"
31
32
  if defined?(error.record)
32
33
  render_turboboost_errors_for(error.record)
33
34
  else
34
- render json: [error.message], status: error_status || 500
35
+ translation = I18n.t("turboboost.errors.#{error.class.name}")
36
+ message = translation.match("translation missing: (.+)") ? error.class.name : translation
37
+ render json: [message], status: error_status || 500, root: false
35
38
  end
36
39
  else
37
40
  raise error
@@ -44,7 +47,7 @@ module Turboboost
44
47
 
45
48
  def head_turboboost_success(turboboost_flash={})
46
49
  turboboost_flash = _turboboost_get_flash_messages(turboboost_flash)
47
- head :ok, "X-Flash" => turboboost_flash.to_json
50
+ head :ok, "X-Flash" => turboboost_flash.to_json, "X-Turboboosted" => "1"
48
51
  end
49
52
 
50
53
  def render(*args, &block)
@@ -61,6 +64,7 @@ module Turboboost
61
64
  response.headers["X-#{h.capitalize}"] = options[h] if options[h]
62
65
  end
63
66
  response.headers["X-Flash"] = flash.to_hash.to_json if !flash.empty?
67
+ response.headers["X-Turboboosted"] = "1"
64
68
  self.response_body = render_to_body(options)
65
69
  end
66
70
 
@@ -79,7 +83,12 @@ module Turboboost
79
83
  # set flash for turbo redirect headers
80
84
  turboboost_flash = _turboboost_get_flash_messages(response_status_and_flash)
81
85
 
82
- self.location = _compute_redirect_to_location(options)
86
+ if Rails.version < "4.2"
87
+ self.location = _compute_redirect_to_location(options)
88
+ else
89
+ self.location = _compute_redirect_to_location(request, options)
90
+ end
91
+
83
92
  head :ok, "X-Flash" => turboboost_flash.to_json
84
93
 
85
94
  flash.update(turboboost_flash) # set flash for rendered view
@@ -152,13 +161,12 @@ module Turboboost
152
161
 
153
162
  class Engine < Rails::Engine
154
163
  initializer :turboboost do
155
- ActionView::Base.send :include, Turboboost::FormHelper
156
- end
164
+ ActionView::Base.send :include, Turboboost::FormHelper
165
+ end
157
166
  end
158
167
 
159
168
  end
160
169
 
161
- # ActionView::Base.send :include, Turboboost::FormHelper
162
170
  ActiveSupport.on_load(:action_controller) do
163
171
  include Turboboost::Controller
164
172
  end
@@ -1,3 +1,3 @@
1
1
  module Turboboost
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Turboboost::VERSION
9
9
  spec.authors = ["Justin Talbott"]
10
10
  spec.email = ["justin@waymondo.com"]
11
- spec.description = %q{Turbolinks and AJAX enhancements for your Rails forms and links.}
12
- spec.summary = %q{Turbolinks and AJAX enhancements for your Rails forms and links.}
13
- spec.homepage = ""
11
+ spec.description = %q{Enhanced AJAX handling for Rails apps.}
12
+ spec.summary = %q{Turboboost extends the power of Turbolinks into the forms of your Rails app and provides additional convenient AJAX handlers for forms and links.}
13
+ spec.homepage = "https://github.com/waymondo/turboboost"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'coffee-rails'
24
24
  spec.add_dependency 'jquery-rails'
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.3"
27
- spec.add_development_dependency "rake"
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake', '~> 0'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turboboost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Talbott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -84,17 +84,17 @@ dependencies:
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Turbolinks and AJAX enhancements for your Rails forms and links.
97
+ description: Enhanced AJAX handling for Rails apps.
98
98
  email:
99
99
  - justin@waymondo.com
100
100
  executables: []
@@ -113,7 +113,7 @@ files:
113
113
  - test/test_helper.rb
114
114
  - test/view_test.rb
115
115
  - turboboost.gemspec
116
- homepage: ''
116
+ homepage: https://github.com/waymondo/turboboost
117
117
  licenses:
118
118
  - MIT
119
119
  metadata: {}
@@ -133,10 +133,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.2.0
136
+ rubygems_version: 2.2.2
137
137
  signing_key:
138
138
  specification_version: 4
139
- summary: Turbolinks and AJAX enhancements for your Rails forms and links.
139
+ summary: Turboboost extends the power of Turbolinks into the forms of your Rails app
140
+ and provides additional convenient AJAX handlers for forms and links.
140
141
  test_files:
141
142
  - test/controller_test.rb
142
143
  - test/test_helper.rb