ajaxify_rails 0.2.1 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +5 -0
  4. data/README.md +4 -3
  5. data/Rakefile +13 -0
  6. data/ajaxify_rails.gemspec +11 -0
  7. data/lib/ajaxify_rails/version.rb +1 -1
  8. data/spec/ajaxify_test/Rakefile +7 -0
  9. data/spec/ajaxify_test/app/assets/images/ajax-loader-y.gif +0 -0
  10. data/spec/ajaxify_test/app/assets/images/ajax-loader.gif +0 -0
  11. data/spec/ajaxify_test/app/assets/javascripts/application.js +17 -0
  12. data/spec/ajaxify_test/app/assets/javascripts/home.js.coffee +16 -0
  13. data/spec/ajaxify_test/app/assets/javascripts/main.js.coffee +33 -0
  14. data/spec/ajaxify_test/app/assets/stylesheets/application.css +13 -0
  15. data/spec/ajaxify_test/app/assets/stylesheets/home.css.scss +93 -0
  16. data/spec/ajaxify_test/app/controllers/application_controller.rb +19 -0
  17. data/spec/ajaxify_test/app/controllers/home_controller.rb +34 -0
  18. data/spec/ajaxify_test/app/helpers/application_helper.rb +2 -0
  19. data/spec/ajaxify_test/app/helpers/home_helper.rb +2 -0
  20. data/spec/ajaxify_test/app/mailers/.gitkeep +0 -0
  21. data/spec/ajaxify_test/app/models/.gitkeep +0 -0
  22. data/spec/ajaxify_test/app/views/home/index.html.haml +1 -0
  23. data/spec/ajaxify_test/app/views/home/page1.html.haml +1 -0
  24. data/spec/ajaxify_test/app/views/home/page2.html.haml +10 -0
  25. data/spec/ajaxify_test/app/views/home/page3.html.haml +1 -0
  26. data/spec/ajaxify_test/app/views/layouts/application.html.haml +47 -0
  27. data/spec/ajaxify_test/config.ru +4 -0
  28. data/spec/ajaxify_test/config/application.rb +61 -0
  29. data/spec/ajaxify_test/config/boot.rb +19 -0
  30. data/spec/ajaxify_test/config/database.yml +25 -0
  31. data/spec/ajaxify_test/config/environment.rb +5 -0
  32. data/spec/ajaxify_test/config/environments/development.rb +37 -0
  33. data/spec/ajaxify_test/config/environments/production.rb +67 -0
  34. data/spec/ajaxify_test/config/environments/test.rb +34 -0
  35. data/spec/ajaxify_test/config/initializers/backtrace_silencers.rb +7 -0
  36. data/spec/ajaxify_test/config/initializers/inflections.rb +15 -0
  37. data/spec/ajaxify_test/config/initializers/mime_types.rb +5 -0
  38. data/spec/ajaxify_test/config/initializers/secret_token.rb +7 -0
  39. data/spec/ajaxify_test/config/initializers/session_store.rb +8 -0
  40. data/spec/ajaxify_test/config/initializers/wrap_parameters.rb +14 -0
  41. data/spec/ajaxify_test/config/locales/en.yml +5 -0
  42. data/spec/ajaxify_test/config/routes.rb +12 -0
  43. data/spec/ajaxify_test/db/development.sqlite3 +0 -0
  44. data/spec/ajaxify_test/db/seeds.rb +7 -0
  45. data/spec/ajaxify_test/db/test.sqlite3 +0 -0
  46. data/spec/ajaxify_test/lib/assets/.gitkeep +0 -0
  47. data/spec/ajaxify_test/lib/tasks/.gitkeep +0 -0
  48. data/spec/ajaxify_test/public/404.html +26 -0
  49. data/spec/ajaxify_test/public/422.html +26 -0
  50. data/spec/ajaxify_test/public/500.html +25 -0
  51. data/spec/ajaxify_test/public/favicon.ico +0 -0
  52. data/spec/ajaxify_test/public/robots.txt +5 -0
  53. data/spec/ajaxify_test/script/rails +6 -0
  54. data/spec/integration/ajaxify_rails_spec.rb +167 -0
  55. data/spec/spec_helper.rb +86 -0
  56. data/vendor/assets/javascripts/ajaxify_rails.js.coffee +103 -88
  57. metadata +252 -5
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  .idea
7
+ .sass-cache
7
8
  Gemfile.lock
8
9
  InstalledFiles
9
10
  _yardoc
@@ -16,3 +17,6 @@ spec/reports
16
17
  test/tmp
17
18
  test/version_tmp
18
19
  tmp
20
+ spec/ajaxify_test/log
21
+ spec/ajaxify_test/tmp
22
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.3
3
+ before_script:
4
+ - "export DISPLAY=:99.0"
5
+ - "sh -e /etc/init.d/xvfb start"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ajaxify Rails
1
+ # Ajaxify Rails [![Build Status](https://travis-ci.org/ncri/ajaxify_rails.png)](https://travis-ci.org/ncri/ajaxify_rails)
2
2
 
3
3
  No more full page reloads for your Rails app! Yay!
4
4
 
@@ -25,7 +25,8 @@ Inspired by the pjax_rails gem (https://github.com/rails/pjax_rails).
25
25
 
26
26
  ## Requirements
27
27
 
28
- - Ruby 1.9 and the asset pipeline.
28
+ - Ruby 1.9 and the asset pipeline,
29
+ - jQuery,
29
30
  - Your app doesn't use named anchors (#). Named anchors can't be correctly represented in the fallback hash based url scheme.
30
31
 
31
32
  ## Installation
@@ -194,4 +195,4 @@ You can temporarily deactivate Ajaxify by calling `Ajaxify.activate(false)`. You
194
195
  2. Create your feature branch (`git checkout -b my-new-feature`)
195
196
  3. Commit your changes (`git commit -am 'Added some feature'`)
196
197
  4. Push to the branch (`git push origin my-new-feature`)
197
- 5. Create new Pull Request
198
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,15 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ # require "rake/testtask"
4
+
5
+ # Rake::TestTask.new(:test) do |t|
6
+ # t.libs << 'test'
7
+ # t.test_files = FileList['test/**/*_test.rb']
8
+ # t.verbose = true
9
+ # end
10
+
11
+
12
+ require 'rspec/core/rake_task'
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+ task default: :spec
@@ -20,4 +20,15 @@ Gem::Specification.new do |gem|
20
20
  gem.version = AjaxifyRails::VERSION
21
21
 
22
22
  gem.add_dependency 'rails', '>= 3.1.0'
23
+
24
+ gem.add_development_dependency 'jquery-rails'
25
+ gem.add_development_dependency 'rspec-rails', '2.9'
26
+ gem.add_development_dependency 'rspec-steps'
27
+ gem.add_development_dependency 'capybara'
28
+ gem.add_development_dependency 'selenium-webdriver', '>= 2.30.0'
29
+ gem.add_development_dependency 'sqlite3'
30
+ gem.add_development_dependency 'haml', '>= 3.1.5'
31
+ gem.add_development_dependency 'sass-rails', '~> 3.2.3'
32
+ gem.add_development_dependency 'coffee-rails', '~> 3.2.1'
33
+ #gem.add_development_dependency 'poltergeist'
23
34
  end
@@ -1,3 +1,3 @@
1
1
  module AjaxifyRails
2
- VERSION = "0.2.1"
2
+ VERSION = "0.5"
3
3
  end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ AjaxifyTest::Application.load_tasks
@@ -0,0 +1,17 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require ajaxify_rails
16
+ //= require main
17
+ //= require home
@@ -0,0 +1,16 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4
+
5
+ jQuery ->
6
+
7
+ $('#ajaxify').click ->
8
+ if this.checked
9
+ window.location.href = '?ajaxify_on=true'
10
+ else
11
+ window.location.href = '?ajaxify_off=true'
12
+
13
+
14
+
15
+
16
+
@@ -0,0 +1,33 @@
1
+
2
+ #Ajaxify.init
3
+ # flash_types: ['notice', 'warning']
4
+ # base_paths: ['de']
5
+
6
+ jQuery ->
7
+ $(document).on 'ajaxify:content_loaded', (event, data, status, jqXHR, url) ->
8
+ $nav_links = $('#navigation a')
9
+ $nav_links.removeClass 'active'
10
+ $nav_links.filter( ->
11
+ href = $(this).attr('href')
12
+ (window.location.pathname == href and window.location.hash == '') or # for browsers with histori api
13
+ window.location.hash.match(new RegExp("^#(#{href}\\?|#{href}$)")) # for browsers without histori api
14
+ ).addClass 'active'
15
+
16
+ flash_timeout = null
17
+
18
+ $(document).on 'ajaxify:flash_displayed', (event, flash_type) ->
19
+ clearTimeout flash_timeout if flash_timeout
20
+ flash_timeout = setTimeout( ->
21
+ $("##{flash_type}").fadeOut()
22
+ , 5000)
23
+
24
+ # $('body').on 'ajaxify:before_load', (event, url) ->
25
+ # alert "Will load #{url}"
26
+ #
27
+ # $('body').on 'ajaxify:content_loaded', (event, data, status, jqXHR, url) ->
28
+ # alert "Content loaded"
29
+ #
30
+ # $('body').on 'ajaxify:content_inserted', ->
31
+ # alert "Content inserted"
32
+
33
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,93 @@
1
+ // Place all the styles related to the home controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+
5
+ body{
6
+ font-family: Arial;
7
+ color: #555;
8
+ text-align: left;
9
+ }
10
+
11
+ #main, #navigation, #notice, #title, #hints, #footnote{
12
+ margin-top: 20px;
13
+ width: 650px;
14
+ margin: 0 auto;
15
+ }
16
+
17
+ #hints{
18
+ margin-bottom: 60px;
19
+ color: orange;
20
+ }
21
+
22
+ #footnote{
23
+ font-size: 0.8em;
24
+ margin-top: 10px;
25
+ text-align: right;
26
+ }
27
+
28
+ h1#title{
29
+ margin: 40px auto 40px;
30
+ font-size: 20px;
31
+
32
+ a{
33
+ text-decoration: underline;
34
+ }
35
+ }
36
+
37
+ #main{
38
+ border: 1px solid #aaa;
39
+ padding: 70px 10px 10px;
40
+ width: 630px;
41
+ height: 140px;
42
+ text-align: center;
43
+ }
44
+
45
+ #notice{
46
+ width: 630px;
47
+ padding: 10px;
48
+ background-color: orange;
49
+ color: white;
50
+ }
51
+
52
+ .active{
53
+ font-weight: bold;
54
+ }
55
+
56
+ a{
57
+ text-decoration: none;
58
+ font-weight: normal;
59
+ color: #555;
60
+ }
61
+
62
+ ul{
63
+ padding-left: 0;
64
+ margin-left: 0;
65
+ width: 100%;
66
+ }
67
+
68
+ li{
69
+ display: inline-block;
70
+ padding-right: 15px;
71
+ }
72
+
73
+ #toggle_ajaxify{
74
+ float: right;
75
+ }
76
+
77
+ form{
78
+ text-align: left;
79
+ width: 100px;
80
+ margin: 0 auto;
81
+ }
82
+
83
+
84
+ /* Ajaxify */
85
+
86
+ .ajaxify_loader{
87
+ width: 32px;
88
+ height: 32px;
89
+ margin: 0 auto;
90
+ background-color: white;
91
+ background-repeat: no-repeat;
92
+ background-image: asset-url('ajax-loader.gif', image);
93
+ }
@@ -0,0 +1,19 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ helper_method :page_title
5
+
6
+
7
+ def page_title
8
+ title = case action_name
9
+ when 'index'
10
+ 'Home'
11
+ when 'page1'
12
+ 'Page 1'
13
+ when 'page2'
14
+ 'Page 2'
15
+ end
16
+ "Ajaxify Test - #{title}"
17
+ end
18
+
19
+ end
@@ -0,0 +1,34 @@
1
+ class HomeController < ApplicationController
2
+
3
+ before_filter :toggle_ajaxify
4
+
5
+ def index
6
+ sleep 0.5
7
+ end
8
+
9
+ def page1
10
+ sleep 0.5
11
+ end
12
+
13
+ def page2
14
+ sleep 0.5
15
+ if request.post?
16
+ flash.now[:notice] = "Form submitted (#{params[:input1]}, #{params[:input2]}, #{params[:check_me]})"
17
+ end
18
+ end
19
+
20
+ def page3
21
+ flash[:notice] = 'Redirected to Page 1'
22
+ redirect_to '/home/page1'
23
+ end
24
+
25
+
26
+ private
27
+
28
+ def toggle_ajaxify
29
+ session[:ajaxify] = true if params[:ajaxify_on]
30
+ session[:ajaxify] = false if params[:ajaxify_off]
31
+ session[:push_state_enabled] = (params[:push_state_enabled] != 'false') if params[:push_state_enabled].present?
32
+ end
33
+
34
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module HomeHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1 @@
1
+ Home Content
@@ -0,0 +1 @@
1
+ Page 1 Content
@@ -0,0 +1,10 @@
1
+ = form_tag '/home/page2' do
2
+ %strong A Form
3
+ %br
4
+ = text_field_tag :input1
5
+ %br
6
+ = text_field_tag :input2
7
+ %br
8
+ = check_box_tag :check_me
9
+ %br
10
+ = submit_tag 'Submit me'
@@ -0,0 +1 @@
1
+ Page 3 Content
@@ -0,0 +1,47 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %meta(content="text/html; charset=utf-8" http-equiv="Content-Type")
5
+
6
+ %title= page_title
7
+
8
+ = csrf_meta_tag
9
+ = javascript_include_tag( 'application' )
10
+ = stylesheet_link_tag "application"
11
+
12
+ = content_tag :body, data: { id: Time.now.to_i } do
13
+
14
+ -# No need to do call Ajaxify.init obtrusively in your app. Just call it from your js/coffeescript file, as early as possible.
15
+ -# I only do it hackishly here to access the rails session.
16
+ :javascript
17
+ Ajaxify.init( { push_state_enabled: #{(session[:push_state_enabled] == false) ? 'false' : 'true'}, active: #{session[:ajaxify] ? 'true' : 'false'} } );
18
+
19
+ - sleep 1
20
+
21
+ %h1#title
22
+ Ajaxify Rails Demo (more info: #{link_to('ajaxify_rails gem', 'https://github.com/ncri/ajaxify_rails')})
23
+
24
+ #hints
25
+ - if session[:ajaxify]
26
+ Navigate. Note the difference. Also try out the browser's back and forward buttons.
27
+ - else
28
+ Navigate. Then switch on Ajaxify (checkbox right).
29
+
30
+ #notice{ style: "#{'display:none' unless flash[:notice]}" }= flash[:notice]
31
+
32
+ #navigation
33
+ #toggle_ajaxify
34
+ Ajaxify
35
+ = check_box_tag :ajaxify, '1', session[:ajaxify]
36
+ %ul
37
+ %li= link_to 'Home', '/', class: current_page?('/') ? 'active' : nil
38
+ %li= link_to 'Page 1', '/home/page1', class: current_page?('/home/page1') ? 'active' : nil
39
+ %li= link_to 'Page 2', '/home/page2', class: current_page?('/home/page2') ? 'active' : nil
40
+ %li= link_to 'Page 3 (redirects to page 1)', '/home/page3', class: current_page?('/home/page3') ? 'active' : nil
41
+
42
+ #main
43
+ = yield
44
+
45
+ #footnote
46
+ Note: Layout rendering is delayed by one second to simulate a complex layout.
47
+
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run AjaxifyTest::Application
@@ -0,0 +1,61 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "action_controller/railtie"
5
+ require "action_mailer/railtie"
6
+ require "active_resource/railtie"
7
+ require "sprockets/railtie"
8
+
9
+ #require "rails/test_unit/railtie"
10
+
11
+ require 'jquery-rails'
12
+
13
+ Bundler.require
14
+ require "ajaxify_rails"
15
+
16
+
17
+ module AjaxifyTest
18
+ class Application < Rails::Application
19
+ # Settings in config/environments/* take precedence over those specified here.
20
+ # Application configuration should go into files in config/initializers
21
+ # -- all .rb files in that directory are automatically loaded.
22
+
23
+ # Custom directories with classes and modules you want to be autoloadable.
24
+ # config.autoload_paths += %W(#{config.root}/extras)
25
+
26
+ # Only load the plugins named here, in the order given (default is alphabetical).
27
+ # :all can be used as a placeholder for all plugins not explicitly named.
28
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
29
+
30
+ # Activate observers that should always be running.
31
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
32
+
33
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
34
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
35
+ # config.time_zone = 'Central Time (US & Canada)'
36
+
37
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
38
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
39
+ # config.i18n.default_locale = :de
40
+
41
+ # Configure the default encoding used in templates for Ruby 1.9.
42
+ config.encoding = "utf-8"
43
+
44
+ # Configure sensitive parameters which will be filtered from the log file.
45
+ config.filter_parameters += [:password]
46
+
47
+ # Enable escaping HTML in JSON.
48
+ config.active_support.escape_html_entities_in_json = true
49
+
50
+ # Use SQL instead of Active Record's schema dumper when creating the database.
51
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
52
+ # like if you have constraints or database-specific column types
53
+ # config.active_record.schema_format = :sql
54
+
55
+ # Enable the asset pipeline
56
+ config.assets.enabled = true
57
+
58
+ # Version of your assets, change this if you want to expire all your assets
59
+ config.assets.version = '1.0'
60
+ end
61
+ end