on_the_spot 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.bundle/config +2 -0
  2. data/Gemfile +10 -6
  3. data/Gemfile.lock +84 -38
  4. data/History.md +25 -0
  5. data/VERSION +1 -1
  6. data/app/assets/javascripts/jquery.jeditable.mini.js +38 -0
  7. data/{lib/generators/on_the_spot/install/templates → app/assets/javascripts}/on_the_spot.js +0 -0
  8. data/lib/generators/on_the_spot/install/install_generator.rb +14 -6
  9. data/lib/on_the_spot.rb +1 -1
  10. data/on_the_spot.gemspec +57 -32
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  13. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  14. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/spec/dummy/config.ru +4 -0
  16. data/spec/dummy/config/application.rb +45 -0
  17. data/spec/dummy/config/boot.rb +10 -0
  18. data/spec/dummy/config/database.yml +22 -0
  19. data/spec/dummy/config/environment.rb +5 -0
  20. data/spec/dummy/config/environments/development.rb +26 -0
  21. data/spec/dummy/config/environments/production.rb +49 -0
  22. data/spec/dummy/config/environments/test.rb +35 -0
  23. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/spec/dummy/config/initializers/inflections.rb +10 -0
  25. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  26. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  27. data/spec/dummy/config/initializers/session_store.rb +8 -0
  28. data/spec/dummy/config/locales/en.yml +5 -0
  29. data/spec/dummy/config/routes.rb +58 -0
  30. data/spec/dummy/public/404.html +26 -0
  31. data/spec/dummy/public/422.html +26 -0
  32. data/spec/dummy/public/500.html +26 -0
  33. data/spec/dummy/public/favicon.ico +0 -0
  34. data/spec/dummy/public/javascripts/application.js +2 -0
  35. data/spec/dummy/public/javascripts/controls.js +965 -0
  36. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  37. data/spec/dummy/public/javascripts/effects.js +1123 -0
  38. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  39. data/spec/dummy/public/javascripts/rails.js +175 -0
  40. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  41. data/spec/dummy/script/rails +6 -0
  42. data/spec/generators/install_generator_spec.rb +47 -0
  43. data/spec/spec_helper.rb +32 -7
  44. metadata +62 -25
  45. data/.gitignore +0 -23
  46. data/.rspec +0 -1
  47. data/autotest/discover.rb +0 -1
  48. data/spec/spec.opts +0 -1
@@ -0,0 +1,175 @@
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
74
+ function handleRemote(element) {
75
+ var method, url, params;
76
+
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
80
+ if (element.tagName.toLowerCase() === 'form') {
81
+ method = element.readAttribute('method') || 'post';
82
+ url = element.readAttribute('action');
83
+ params = element.serialize();
84
+ } else {
85
+ method = element.readAttribute('data-method') || 'get';
86
+ url = element.readAttribute('href');
87
+ params = {};
88
+ }
89
+
90
+ new Ajax.Request(url, {
91
+ method: method,
92
+ parameters: params,
93
+ evalScripts: true,
94
+
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
98
+ });
99
+
100
+ element.fire("ajax:after");
101
+ }
102
+
103
+ function handleMethod(element) {
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
108
+
109
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
110
+ element.parentNode.insert(form);
111
+
112
+ if (method !== 'post') {
113
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
114
+ form.insert(field);
115
+ }
116
+
117
+ if (csrf_param) {
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
122
+ }
123
+
124
+ form.submit();
125
+ }
126
+
127
+
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
132
+
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
143
+ });
144
+
145
+ document.on("submit", function(event) {
146
+ var element = event.findElement(),
147
+ message = element.readAttribute('data-confirm');
148
+ if (message && !confirm(message)) {
149
+ event.stop();
150
+ return false;
151
+ }
152
+
153
+ var inputs = element.select("input[type=submit][data-disable-with]");
154
+ inputs.each(function(input) {
155
+ input.disabled = true;
156
+ input.writeAttribute('data-original-value', input.value);
157
+ input.value = input.readAttribute('data-disable-with');
158
+ });
159
+
160
+ var element = event.findElement("form[data-remote]");
161
+ if (element) {
162
+ handleRemote(element);
163
+ event.stop();
164
+ }
165
+ });
166
+
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
174
+ });
175
+ })();
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'generator_spec/test_case'
3
+ require 'generators/on_the_spot/install/install_generator'
4
+
5
+ describe OnTheSpot::Generators::InstallGenerator do
6
+ include GeneratorSpec::TestCase
7
+
8
+ destination File.expand_path("../../tmp", __FILE__)
9
+
10
+ context "in rails 3.0" do
11
+ context "with no arguments" do
12
+ before(:all) do
13
+ ::Rails.stub(:version) { '3.0.8' }
14
+ prepare_destination
15
+ run_generator
16
+ end
17
+
18
+ it "stubs the version correctly" do
19
+ Rails.version[0..2].should == "3.0"
20
+ end
21
+
22
+ it "stubs the version correctly" do
23
+ test_version = (Rails.version[0..2].to_f >= 3.1)
24
+ test_version.should be_false
25
+ end
26
+
27
+ it "copies on_the_spot.js to the correct folder" do
28
+ assert_file "public/javascripts/on_the_spot.js"
29
+ end
30
+ end
31
+ end
32
+
33
+ context "in rails 3.1" do
34
+ context "with no arguments" do
35
+ before(:all) do
36
+ ::Rails.stub(:version) { '3.1.0' }
37
+ prepare_destination
38
+ run_generator
39
+ end
40
+
41
+ it "does not copy on_the_spot.js" do
42
+ assert_no_file "public/javascripts/on_the_spot.js"
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -1,12 +1,37 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rspec/core'
4
- #require 'autotest/rspec2'
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
5
3
 
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "rspec/rails"
6
7
  require 'simplecov'
7
- SimpleCov.start 'rails'
8
8
 
9
- RSpec.configure do |c|
10
- c.color_enabled = true
9
+ ActionMailer::Base.delivery_method = :test
10
+ ActionMailer::Base.perform_deliveries = true
11
+ ActionMailer::Base.default_url_options[:host] = "test.com"
12
+
13
+ Rails.backtrace_cleaner.remove_silencers!
14
+
15
+ ## Configure capybara for integration testing
16
+ #require "capybara/rails"
17
+ #Capybara.default_driver = :rack_test
18
+ #Capybara.default_selector = :css
19
+
20
+ # Run any available migration
21
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
22
+
23
+ # Load support files
24
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
25
+
26
+ RSpec.configure do |config|
27
+ # Remove this line if you don't want RSpec's should and should_not
28
+ # methods or matchers
29
+ require 'rspec/expectations'
30
+ config.include RSpec::Matchers
31
+
32
+ # == Mock Framework
33
+ config.mock_with :rspec
34
+
35
+ config.color_enabled = true
11
36
  end
12
37
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: on_the_spot
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 5
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 12
9
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
10
11
  platform: ruby
11
12
  authors:
12
13
  - Nathan Van der Auwera
@@ -14,54 +15,58 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-07-02 00:00:00 +02:00
18
+ date: 2011-07-24 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: rspec
22
- prerelease: false
22
+ type: :development
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
+ hash: 7712058
28
29
  segments:
29
30
  - 2
30
31
  - 0
31
- - 0rc
32
+ - 0
33
+ - rc
32
34
  version: 2.0.0rc
33
- type: :development
35
+ name: rspec
34
36
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: actionpack
37
37
  prerelease: false
38
+ - !ruby/object:Gem::Dependency
39
+ type: :development
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 7
43
46
  segments:
44
47
  - 3
45
48
  - 0
46
49
  - 0
47
50
  version: 3.0.0
48
- type: :development
51
+ name: actionpack
49
52
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: json_pure
52
53
  prerelease: false
54
+ - !ruby/object:Gem::Dependency
55
+ type: :runtime
53
56
  requirement: &id003 !ruby/object:Gem::Requirement
54
57
  none: false
55
58
  requirements:
56
59
  - - ">="
57
60
  - !ruby/object:Gem::Version
61
+ hash: 11
58
62
  segments:
59
63
  - 1
60
64
  - 4
61
65
  - 6
62
66
  version: 1.4.6
63
- type: :runtime
67
+ name: json_pure
64
68
  version_requirements: *id003
69
+ prerelease: false
65
70
  description: Unobtrusive in place editing, using jEditable; only works in Rails 3
66
71
  email: nathan@dixis.com
67
72
  executables: []
@@ -72,35 +77,66 @@ extra_rdoc_files:
72
77
  - LICENSE
73
78
  - README.markdown
74
79
  files:
80
+ - .bundle/config
75
81
  - .document
76
- - .gitignore
77
- - .rspec
78
82
  - .travis.yml
79
83
  - Gemfile
80
84
  - Gemfile.lock
85
+ - History.md
81
86
  - LICENSE
82
87
  - README.markdown
83
88
  - Rakefile
84
89
  - VERSION
85
- - autotest/discover.rb
90
+ - app/assets/javascripts/jquery.jeditable.mini.js
91
+ - app/assets/javascripts/on_the_spot.js
86
92
  - lib/generators/on_the_spot/install/install_generator.rb
87
93
  - lib/generators/on_the_spot/install/templates/jquery.jeditable.mini.js
88
94
  - lib/generators/on_the_spot/install/templates/on_the_spot.en.yml
89
- - lib/generators/on_the_spot/install/templates/on_the_spot.js
90
95
  - lib/on_the_spot.rb
91
96
  - lib/on_the_spot/controller_extension.rb
92
97
  - lib/on_the_spot/on_the_spot_helpers.rb
93
98
  - on_the_spot.gemspec
99
+ - spec/dummy/Rakefile
100
+ - spec/dummy/app/controllers/application_controller.rb
101
+ - spec/dummy/app/helpers/application_helper.rb
102
+ - spec/dummy/app/views/layouts/application.html.erb
103
+ - spec/dummy/config.ru
104
+ - spec/dummy/config/application.rb
105
+ - spec/dummy/config/boot.rb
106
+ - spec/dummy/config/database.yml
107
+ - spec/dummy/config/environment.rb
108
+ - spec/dummy/config/environments/development.rb
109
+ - spec/dummy/config/environments/production.rb
110
+ - spec/dummy/config/environments/test.rb
111
+ - spec/dummy/config/initializers/backtrace_silencers.rb
112
+ - spec/dummy/config/initializers/inflections.rb
113
+ - spec/dummy/config/initializers/mime_types.rb
114
+ - spec/dummy/config/initializers/secret_token.rb
115
+ - spec/dummy/config/initializers/session_store.rb
116
+ - spec/dummy/config/locales/en.yml
117
+ - spec/dummy/config/routes.rb
118
+ - spec/dummy/public/404.html
119
+ - spec/dummy/public/422.html
120
+ - spec/dummy/public/500.html
121
+ - spec/dummy/public/favicon.ico
122
+ - spec/dummy/public/javascripts/application.js
123
+ - spec/dummy/public/javascripts/controls.js
124
+ - spec/dummy/public/javascripts/dragdrop.js
125
+ - spec/dummy/public/javascripts/effects.js
126
+ - spec/dummy/public/javascripts/prototype.js
127
+ - spec/dummy/public/javascripts/rails.js
128
+ - spec/dummy/public/stylesheets/.gitkeep
129
+ - spec/dummy/script/rails
130
+ - spec/generators/install_generator_spec.rb
94
131
  - spec/on_the_spot_spec.rb
95
- - spec/spec.opts
96
132
  - spec/spec_helper.rb
97
133
  has_rdoc: true
98
134
  homepage: http://github.com/nathanvda/on_the_spot
99
135
  licenses: []
100
136
 
101
137
  post_install_message:
102
- rdoc_options:
103
- - --charset=UTF-8
138
+ rdoc_options: []
139
+
104
140
  require_paths:
105
141
  - lib
106
142
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -108,6 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
144
  requirements:
109
145
  - - ">="
110
146
  - !ruby/object:Gem::Version
147
+ hash: 3
111
148
  segments:
112
149
  - 0
113
150
  version: "0"
@@ -116,16 +153,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
153
  requirements:
117
154
  - - ">="
118
155
  - !ruby/object:Gem::Version
156
+ hash: 3
119
157
  segments:
120
158
  - 0
121
159
  version: "0"
122
160
  requirements: []
123
161
 
124
162
  rubyforge_project:
125
- rubygems_version: 1.3.7
163
+ rubygems_version: 1.6.2
126
164
  signing_key:
127
165
  specification_version: 3
128
166
  summary: unobtrusive in place editing
129
- test_files:
130
- - spec/spec_helper.rb
131
- - spec/on_the_spot_spec.rb
167
+ test_files: []
168
+