ajax 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +291 -0
  3. data/Rakefile +49 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/ajax_controller.rb +3 -0
  6. data/app/views/ajax/framework.html.erb +7 -0
  7. data/config/initializers/ajax.rb +14 -0
  8. data/lib/ajax.rb +79 -0
  9. data/lib/ajax/action_controller.rb +154 -0
  10. data/lib/ajax/action_view.rb +56 -0
  11. data/lib/ajax/helpers.rb +15 -0
  12. data/lib/ajax/helpers/request_helper.rb +76 -0
  13. data/lib/ajax/helpers/robot_helper.rb +31 -0
  14. data/lib/ajax/helpers/url_helper.rb +47 -0
  15. data/lib/ajax/railtie.rb +7 -0
  16. data/lib/ajax/routes.rb +12 -0
  17. data/lib/ajax/spec/extension.rb +34 -0
  18. data/lib/ajax/spec/helpers.rb +95 -0
  19. data/lib/ajax/tasks.rb +1 -0
  20. data/lib/rack-ajax.rb +60 -0
  21. data/lib/rack-ajax/decision_tree.rb +60 -0
  22. data/lib/rack-ajax/parser.rb +115 -0
  23. data/public/images/loading-icon-large.gif +0 -0
  24. data/public/images/loading-icon-small.gif +0 -0
  25. data/public/javascripts/ajax.js +529 -0
  26. data/public/javascripts/jquery.address-1.1.js +450 -0
  27. data/public/javascripts/jquery.address-1.1.min.js +11 -0
  28. data/public/javascripts/jquery.address-1.2.js +528 -0
  29. data/public/javascripts/jquery.address-1.2.min.js +25 -0
  30. data/public/javascripts/jquery.address-1.2rc.js +599 -0
  31. data/public/javascripts/jquery.address-1.2rc.min.js +27 -0
  32. data/public/javascripts/jquery.json-2.2.js +178 -0
  33. data/public/javascripts/jquery.json-2.2.min.js +31 -0
  34. data/rails/init.rb +4 -0
  35. data/rails/install.rb +23 -0
  36. data/rails/uninstall.rb +1 -0
  37. data/spec/ajax/helpers_spec.rb +102 -0
  38. data/spec/ajax/request_helper_spec.rb +33 -0
  39. data/spec/integration/ajax_spec.rb +146 -0
  40. data/spec/rack-ajax/parser_spec.rb +62 -0
  41. data/spec/spec.opts +1 -0
  42. data/spec/spec_helper.rb +18 -0
  43. data/tasks/ajax_tasks.rake +15 -0
  44. metadata +106 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,291 @@
1
+ = Ajax
2
+
3
+ <b>A Ruby on Rails plugin to augment a traditional Rails application with a completely AJAX frontend, while transparently handling issues important to both the enterprise and end users, such as testing, SEO and browser history.</b>
4
+
5
+ The Ajax philosophy is that you should not have to develop for AJAX: Your code shouldn't change; your tests shouldn't change; and the way Google sees your site shouldn't change. (Coming soon, this link {AJAX site crawling specification}[http://code.google.com/web/ajaxcrawling/docs/getting-started.html] may obviate that.)
6
+
7
+ The beauty of Ajax is that your Rails application only ever sees traditional requests, so it does not have to be "Ajax aware".
8
+
9
+ Ajax is being used live in production on altnet.com[http://altnet.com], if you would like to try it out (as of May 1st 2010 or thereabouts).
10
+
11
+ == Install
12
+
13
+ After installing, create layouts in <tt>app/views/layouts/ajax/</tt> that mimic your existing layouts. See <b>Request Handling -> Layouts</b>.
14
+
15
+ === Rails 3
16
+
17
+ 1. Add the gem to your <tt>Gemspec</tt>
18
+
19
+ gem 'ajax'
20
+
21
+ 2. <tt>bundle install</tt>
22
+ 3. <tt>rake ajax:install</tt>
23
+
24
+ === Rails 2.x.x
25
+
26
+ <b> As a Gem</b>
27
+
28
+ 1. Add the gem as a dependency in your <tt>config/environment.rb</tt>
29
+
30
+ config.gem 'ajax'
31
+
32
+ 2. <tt>rake gems:install</tt>
33
+
34
+ 3. Add to your <tt>Rakefile</tt>
35
+
36
+ begin
37
+ require 'ajax/tasks'
38
+ rescue Exception => e
39
+ puts "Warning, couldn't load gem tasks: #{e.message}! Skipping..."
40
+ end
41
+
42
+ 4. <tt>rake ajax:install</tt> to install required files. This command is safe to run multiple times. It will skip existing files.
43
+
44
+ <b> As a Plugin</b>
45
+
46
+ ./script/plugin install http://github.com/kjvarga/ajax.git
47
+
48
+ === Sample Output
49
+
50
+ $ rake ajax:install
51
+ created: app/controllers/ajax_controller.rb
52
+ created: app/views/ajax/framework.html.erb
53
+ created: config/initializers/ajax.rb
54
+ created: public/javascripts/ajax.js
55
+ created: public/javascripts/jquery.address-1.2rc.js
56
+ created: public/javascripts/jquery.address-1.2rc.min.js
57
+ created: public/javascripts/jquery.json-2.2.min.js
58
+ created: public/images/loading-icon-small.gif
59
+
60
+ $ rake ajax:install
61
+ skipped: app/controllers/ajax_controller.rb exists!
62
+ skipped: app/views/ajax/framework.html.erb exists!
63
+ ...
64
+
65
+ == Introduction
66
+
67
+ Ajax handles these common problems:
68
+
69
+ * SEO/Crawlability/Google Analytics support
70
+ * Browser History
71
+ * Bookmarkability / Deep-linking
72
+ * Redirects
73
+ * Cookies
74
+ * Lazy-loaded Assets
75
+ * Activating Tabs
76
+ * Request Rewriting & Redirecting
77
+
78
+ Ajax converts a traditional Rails application to use a completely AJAX frontend.
79
+
80
+ What do I mean by "completely AJAX"? Everyone uses AJAX. What we mean when we say "completely AJAX" is that the main page is only loaded once. Every link now loads content via AJAX.
81
+
82
+ But if we do that, the URL will never change and we will have no history, because that is how browsers determine history. It turns out the only way to change the URL without causing the browser to issue a new request, is to modify the named anchor - or "hashed" - part of the URL.
83
+
84
+ So now your traditional links auto-magically load content via AJAX into a page container and update the browser URL with the new URL. You have all the benefits of AJAX as well as history and link bookmarkability.
85
+
86
+ Where before you would have seen something like <tt>http://example.com/the-beatles/history</tt>, now you would see <tt>http://example.com/#/the-beatles/history</tt>. Notice the <tt>#/</tt>?
87
+
88
+ === How does it work?
89
+
90
+ Ajax comprises Rack middleware, Rails integrations and some JavaScript libraries to handle everything from redirecting and rewriting incoming requests, to managing the response headers and content, to handling the browser URL, JavaScript callbacks and client-side events.
91
+
92
+ Browsers do not send the hashed part of the the URL with page requests, so to an AJAX-ed application, all requests look like they are for root.
93
+
94
+ In order to load the correct page we must first render a framework page with accompanying JavaScript. The JS examines the URL and then issues another request to the server for the hashed part (which may still be <tt>/</tt> if the user requested the home page).
95
+
96
+ === An Example User Interaction
97
+
98
+ 1. User pastes http://example.com/#/beyonce/albums into a browser.
99
+ 2. Server receives request for http://example.com/ and renders the framework page.
100
+ 4. AJAX request for http://example.com/beyonce/albums is initiated by client-side JavaScript, and received by the server.
101
+ 5. Server renders http://example.com/beyonce/albums.
102
+ 6. Response headers are processed and the response inserted into the page container.
103
+
104
+ === Request Handling
105
+
106
+ <b>Ajax uses a custom HTTP header <tt>Ajax-Info</tt> to pass JSON back and forth between the client and server.</b> The client sends information about the state of the container, and the server sends new information back.
107
+
108
+ By default the current layout is sent in the <tt>Ajax-Info</tt> header. This can be useful for determining which assets to include, or layout to render in your response.
109
+
110
+ <b><tt>Ajax-Info</tt> headers with special meaning:</b>
111
+
112
+ [title] Sets the page title.
113
+ [tab] jQuery selector, triggers the <tt>activate</tt> event on matched element(s).
114
+ [container] jQuery selector, the container to receive the content (default: <tt>default_container</tt>).
115
+ [assets] Hash of JavaScript and CSS assets to load <tt>{ :javascripts => [], :stylesheets => [] }</tt>
116
+ [callbacks] List of string callbacks to execute after assets have finished loading.
117
+
118
+ === Robots and External APIS
119
+
120
+ <b>We detect robots by their User-Agent strings.</b> If a robot is detected the Ajax handling is bypassed and the robot sees the traditional Rails application.
121
+
122
+ By default any AJAX or non-GET requests pass through unmodified.
123
+
124
+ If you need to expose external APIs you can do so using a regular expression that is matched against incoming URLs.
125
+
126
+ == Compatibility
127
+
128
+ You must be running <b>jQuery 1.4.2</b> to use this plugin. Sorry, Prototype users.
129
+
130
+ The following JavaScript libraries are required and included in the plugin:
131
+
132
+ * {jQuery Address 1.2RC}[http://www.asual.com/jquery/address/]
133
+ * jQuery JSON 2.2
134
+
135
+ === Ruby and Rails:
136
+
137
+ * Rails 2.3.4 running Ruby 1.8.7 and Ruby 1.9
138
+ * Rails 2.3.5 running Ruby 1.8.7 and Ruby 1.9
139
+
140
+ === Browsers:
141
+
142
+ (See {jQuery address supported browsers}[http://www.asual.com/jquery/address/docs/].)
143
+
144
+ * Internet Explorer 6.0+
145
+ * Mozilla Firefox 1.0+
146
+ * Safari 1.3+
147
+ * Opera 9.5+
148
+ * Chrome 1.0+
149
+ * Camino 1.0+
150
+
151
+ = Documentation
152
+
153
+ Please browse the {API documentation at rDoc.info}[http://rdoc.info/projects/kjvarga/ajax]
154
+
155
+ == Configuration
156
+
157
+ It is important to be able to disable the plugin when you don't want it interfering, like when you are testing. You will also want to ensure that your site's JavaScript still works when the plugin is disabled.
158
+
159
+ To disable the plugin in your environment file:
160
+
161
+ # config/environments/test.rb
162
+ Ajax.enabled = false
163
+
164
+ If you need to, you can check the state of the plugin with:
165
+
166
+ Ajax.is_enabled?
167
+
168
+ Other onfiguration goes in <tt>config/initializers/ajax.rb</tt> such as indicating which links to except from the request processing. See <b>Excepted Links</b>.
169
+
170
+ == Ajax Layouts
171
+
172
+ Typically AJAX content does not render a layout because we just want to update a fragment of a page. Automatically turning off layouts when rendering AJAX is one option, but what about when we do want to use a layout?
173
+
174
+ My solution is to first look in <tt>app/views/layouts/ajax/</tt> for a layout with the same name as the default layout for the current action. If a layout is found, we use it, otherwise the default layout is used.
175
+
176
+ In your Ajax layouts you can define callbacks, tabs to activate or the container to receive content.
177
+
178
+ For example, our layouts:
179
+
180
+ layouts/
181
+ _assets.html.haml
182
+ ajax/
183
+ application.html.haml
184
+ single_column.html.haml
185
+ two_column.html.haml
186
+ application.html.haml
187
+ single_column.html.haml
188
+ two_column.html.haml
189
+
190
+ Gists
191
+ * {ajax/application.html.haml}[http://gist.github.com/373133#file_application.html.haml]
192
+ * {ajax/two_column.html.haml}[http://gist.github.com/373133#file_two_column.html.haml]
193
+
194
+ == Link Handling
195
+
196
+ <b>All links which are rendered using the <tt>link_to</tt> (or any other url) helper method automatically include a <tt>data-deep-link</tt> attribute</b> containing the path from the link's HREF.
197
+
198
+ The Ajax JavaScript class listens for clicks on any link with a <tt>data-deep-link</tt> attribute and loads the link's content using AJAX.
199
+
200
+ Should you need to, you can set this attribute on a link by passing in HTML options to <tt>link_to</tt>:
201
+
202
+ link_to odd_url, {}, { :data-deep-link => '/even/odder/url' }
203
+
204
+ To manually mark a link as traditional, pass <tt>:traditional => true</tt> or <tt>:data-deep-link => nil</tt>.
205
+
206
+ === Excepted Links
207
+
208
+ <b>Excepted links bypass Ajax request and link handling.</b> I call these traditional links.
209
+
210
+ Links can be excepted by passing in strings or regular expressions to <tt>Ajax.exclude_paths()</tt>. Only pass the path and not the full URL. The path will be modified to match against other paths as well as against full URLs:
211
+
212
+ # config/initializers/ajax.rb
213
+ Ajax.exclude_paths %w[ /login /logout /signup /altnet-pro /my-account/edit /user-session/new ]
214
+ Ajax.exclude_paths [%r[\/my-account\/.*]]
215
+
216
+ Typically, we except pages that require HTTPS, like signup forms, because including secure forms on an insecure page often triggers a browser warning.
217
+
218
+ Excepted links when rendered do not contain the <tt>data-deep-link</tt> attribute if they are rendered with the <tt>link_to</tt> (or any other url) helper method.
219
+
220
+ == Rails Helpers
221
+
222
+ Use the <tt>ajax_header</tt> helper in your controllers or views to add data to the <tt>Ajax-Info</tt> header. Values are converted to JSON before being sent over the wire. Internally this function uses <tt>Ajax.set_header</tt>.
223
+
224
+ You can use <tt>Ajax.get_header</tt> to inspect <tt>Ajax-Info</tt> header values. See the <b>In Views</b> example.
225
+
226
+ === In Controllers
227
+
228
+ In controllers, <tt>ajax_header</tt> uses an <tt>after_filter</tt> to add content to the response. It therefore accepts passing a block instead of a static value, as well as <tt>:only</tt> and <tt>:except</tt> modifiers, e.g:
229
+
230
+ # app/controllers/application_controller.rb
231
+ ajax_header :title { dynamic_page_attribute(:page_title) || "Music @ Altnet" }
232
+ ajax_header :assets do
233
+ { :stylesheets => [current_controller_stylesheet] }
234
+ end
235
+
236
+ # app/controllers/browse_controller.rb
237
+ ajax_header :tab, '#header .nav li:contains(Music)', :only => [:music, :artists, :albums, :tracks, :new_releases]
238
+ ajax_header :tab, '#header .nav li:contains(Playlists)', :only => :playlists
239
+ ajax_header :tab, '#header .nav li:contains(DJs)', :only => :djs
240
+
241
+ # app/controllers/activity_controller.rb
242
+ ajax_header :tab, '#header .nav li:contains(Realtime)'
243
+ ajax_header :assets, { :javascripts => javascript_files_for_expansion(:juggernaut_jquery) }
244
+
245
+ Array and Hash values are merged so you can call <tt>ajax_header</tt> multiple times. For example, the asset Hash and Array values will be merged.
246
+
247
+ === In Views
248
+
249
+ The syntax is similar to the controller version, except that we do not use an <tt>after_filter</tt>, so you cannot pass a block or <tt>:only</tt> and <tt>:except</tt> modifiers.
250
+
251
+ See {ajax/two_column.html.haml}[http://gist.github.com/373133#file_two_column.html.haml] for an example.
252
+
253
+ == Lazy-loading Assets
254
+
255
+ Use <code>ajax_header :assets { :stylesheets => [], :javascripts => [] }</code> to define assets that a page depends on. These assets will be loaded before the response content is inserted into the DOM.
256
+
257
+ Assets that have already been loaded are not loaded again, so it is safe to always include the assets header.
258
+
259
+ If you need to perform operations on the new content, or instantiate objects defined in the dependent assets, use <b>JavaScript Callbacks</b>.
260
+
261
+ == <a name="callbacks">JavaScript Callbacks</a>
262
+
263
+ To add a JavaScript callback(s) that will be executed <b>after any assets in <tt>Ajax-Info['assets']</tt> have been loaded</b> you can pass it in the header with the following. These callbacks are executed in the global scope:
264
+
265
+ ajax_header, :callbacks, 'window.player.init();'
266
+
267
+ Alternatively you may want to bind callbacks directly to the <tt>window.ajax</tt> object in your view:
268
+
269
+ # app/views/activity/recent.html.haml
270
+ window.ajax.onLoad('window.juggernaut = new Juggernaut(#{juggernaut_options.to_json}); window.liveFeed.init();');
271
+ window.ajax.prependOnLoad("$(document).trigger('player.init');");
272
+
273
+ When we add the juggernaut callback it must be a string because Juggernaut is defined in one of the assets that hasn't been loaded yet.
274
+
275
+ <tt>window.ajax.prependOnLoad</tt> adds the callback to the front of the queue. Callbacks can also be functions, for example:
276
+
277
+ window.ajax.onLoad(function() {
278
+ alert('All your asset are ours!');
279
+ });
280
+
281
+ == Contributions
282
+
283
+ Contributions are welcome. Please fork the project and send me a pull request with your changes and Spec tests.
284
+
285
+ == Useful Resources
286
+
287
+ * AjaxPatters[http://ajaxpatterns.org/Unique_URLs] useful discussion of techniques for maintaining state using JavaScript to poll for changes to <tt>window.location.hash</tt>.
288
+ * link jQuery Address[http://www.asual.com/jquery/address/] JavaScript library for managing the URL.
289
+ * SWFAddress[http://www.asual.com/swfaddress/] deep linking solution for Flash.
290
+
291
+ Copyright (c) 2010 Karl Varga, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+ require 'rubygems'
4
+ gem 'rspec', '1.3.0'
5
+ require 'spec/rake/spectask'
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "ajax"
11
+ gem.summary = %Q{A framework to augment a traditional Rails application with a completely AJAX frontend.}
12
+ gem.description = %Q{Augment a traditional Rails application with a completely AJAX frontend, while transparently handling issues important to both the enterprise and end users, such as testing, SEO and browser history.}
13
+ gem.email = "kjvarga@gmail.com"
14
+ gem.homepage = "http://github.com/kjvarga/ajax"
15
+ gem.authors = ["Karl Varga"]
16
+ gem.files = FileList["[A-Z]*", "{app,config,lib,public,rails,spec,tasks}/**/*"]
17
+ gem.test_files = []
18
+ gem.add_development_dependency "rspec"
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ desc 'Default: run spec tests.'
26
+ task :default => :spec
27
+
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/ajax/**/*_spec.rb', 'spec/rack-ajax/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ #task :spec => :check_dependencies
40
+
41
+ desc 'Generate documentation for the ajax plugin.'
42
+ Rake::RDocTask.new(:rdoc) do |rdoc|
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = 'Ajax'
45
+ rdoc.options << '--line-numbers' << '--inline-source'
46
+ rdoc.rdoc_files.include('README.rdoc')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ rdoc.rdoc_files.include('app/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,3 @@
1
+ class AjaxController < ApplicationController
2
+ unloadable
3
+ end
@@ -0,0 +1,7 @@
1
+ <script type="text/javascript">
2
+ $(function() {
3
+ if (window.ajax !== undefined) {
4
+ window.ajax.loaded_by_framework = true;
5
+ }
6
+ });
7
+ </script>
@@ -0,0 +1,14 @@
1
+ # Default Ajax initialization file
2
+
3
+ # Configure paths that will bypass Ajax handling:
4
+ #
5
+ # Ajax.exclude_paths %w[ /login /logout /signup /user-session/new ]
6
+ # Ajax.exclude_paths [%r[\/my-account\/.*]]
7
+
8
+ # If you use a custom <tt>Rack::Ajax.decision_tree</tt>, include your
9
+ # parser extensions in the Rack::Ajax::Parser module.
10
+ #
11
+ # The extensions define custom methods that are used in the
12
+ # <tt>Rack::Ajax.decision_tree</tt>.
13
+ #
14
+ # Rack::Ajax::Parser.send(:include, Rack::Ajax::Parser::Extensions)
data/lib/ajax.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'ajax/helpers'
2
+
3
+ module Ajax
4
+ include Ajax::Helpers
5
+
6
+ class << self
7
+ attr_writer :logger
8
+ end
9
+
10
+ # Return a logger instance.
11
+ #
12
+ # Use the Rails logger by default, assign nil to turn off logging.
13
+ # Dummy a logger if logging is turned off of if Ajax isn't enabled.
14
+ def self.logger
15
+ if !@logger.nil? && is_enabled?
16
+ @logger
17
+ else
18
+ @logger = Class.new { def method_missing(*args); end; }.new
19
+ end
20
+ end
21
+
22
+ # Return a boolean indicating whether the plugin is enabled.
23
+ #
24
+ # Enabled by default.
25
+ def self.is_enabled?
26
+ @enabled.nil? ? true : !!@enabled
27
+ end
28
+
29
+ # Set to false to disable this plugin completely.
30
+ #
31
+ # ActionController and ActionView helpers are still mixed in but
32
+ # they are effectively disabled, which means your code will still
33
+ # run.
34
+ def self.enabled=(value)
35
+ @enabled = !!value
36
+ end
37
+
38
+ # Return a boolean indicating whether the plugin is being mock tested.
39
+ #
40
+ # Mocking forces the environment to be returned after Ajax processing
41
+ # so that we can introspect it and verify that the correct actions were
42
+ # taken.
43
+ def self.is_mocked?
44
+ @mocked ||= false
45
+ end
46
+
47
+ # Set to true to enable mocking testing the plugin.
48
+ #
49
+ # Integration tests will return the result of the URL rewriting in a
50
+ # special response. Redirects will be indicated using standard responses.
51
+ #
52
+ # Use this to test the handling of URLs in various states and with different
53
+ # HTTP request methods.
54
+ def self.mocked=(value)
55
+ @mocked = !!value
56
+ end
57
+
58
+ # Installs Ajax for Rails.
59
+ #
60
+ # This method is called by <tt>init.rb</tt>, which is run by Rails on startup.
61
+ #
62
+ # Customize rendering. Include custom headers and don't render the layout for AJAX.
63
+ # Insert the Rack::Ajax middleware to rewrite and handle requests.
64
+ # Add custom attributes to outgoing links.
65
+ def self.install_for_rails
66
+ if defined?(Rails)
67
+ Ajax.logger = Rails.logger
68
+
69
+ # Customize rendering. Include custom headers and don't render the layout for AJAX.
70
+ ::ActionController::Base.send(:include, Ajax::ActionController)
71
+
72
+ # Insert the Rack::Ajax middleware to rewrite and handle requests
73
+ ::ActionController::Dispatcher.middleware.insert_before(Rack::Head, Rack::Ajax)
74
+
75
+ # Add custom attributes to outgoing links
76
+ ::ActionView::Base.send(:include, Ajax::ActionView)
77
+ end
78
+ end
79
+ end