restapi 0.0.1

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.
Files changed (78) hide show
  1. data/.autotest +3 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +15 -0
  6. data/Gemfile.lock +118 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.rdoc +0 -0
  9. data/Rakefile +13 -0
  10. data/app/controllers/restapis_controller.rb +11 -0
  11. data/app/public/javascripts/backbone.js +1431 -0
  12. data/app/public/javascripts/bootstrap-collapse.js +138 -0
  13. data/app/public/javascripts/bootstrap.js +1726 -0
  14. data/app/public/javascripts/jquery-1.7.2.js +9404 -0
  15. data/app/public/javascripts/json2.js +487 -0
  16. data/app/public/javascripts/restapi/jst.js +108 -0
  17. data/app/public/javascripts/restapi/restapi.js +14 -0
  18. data/app/public/javascripts/restapi/routers/documentation_router.js +47 -0
  19. data/app/public/javascripts/underscore.js +999 -0
  20. data/app/public/stylesheets/bootstrap-responsive.css +686 -0
  21. data/app/public/stylesheets/bootstrap-responsive.min.css +12 -0
  22. data/app/public/stylesheets/bootstrap.css +3990 -0
  23. data/app/public/stylesheets/bootstrap.min.css +689 -0
  24. data/app/public/stylesheets/restapi/application.css +7 -0
  25. data/app/views/restapis/index.html.erb +47 -0
  26. data/lib/restapi.rb +22 -0
  27. data/lib/restapi/application.rb +155 -0
  28. data/lib/restapi/dsl_definition.rb +119 -0
  29. data/lib/restapi/error_description.rb +15 -0
  30. data/lib/restapi/method_description.rb +38 -0
  31. data/lib/restapi/param_description.rb +48 -0
  32. data/lib/restapi/railtie.rb +9 -0
  33. data/lib/restapi/resource_description.rb +75 -0
  34. data/lib/restapi/restapi_module.rb +54 -0
  35. data/lib/restapi/routing.rb +15 -0
  36. data/lib/restapi/validator.rb +193 -0
  37. data/lib/restapi/version.rb +4 -0
  38. data/restapi.gemspec +23 -0
  39. data/spec/controllers/restapis_controller_spec.rb +13 -0
  40. data/spec/controllers/users_controller_spec.rb +175 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/controllers/dogs_controller.rb +22 -0
  44. data/spec/dummy/app/controllers/twitter_example_controller.rb +306 -0
  45. data/spec/dummy/app/controllers/users_controller.rb +211 -0
  46. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/spec/dummy/app/views/users/doc.html.erb +24 -0
  49. data/spec/dummy/config.ru +4 -0
  50. data/spec/dummy/config/application.rb +45 -0
  51. data/spec/dummy/config/boot.rb +10 -0
  52. data/spec/dummy/config/database.yml +22 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +25 -0
  55. data/spec/dummy/config/environments/production.rb +49 -0
  56. data/spec/dummy/config/environments/test.rb +35 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/inflections.rb +10 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  60. data/spec/dummy/config/initializers/restapi.rb +30 -0
  61. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  62. data/spec/dummy/config/initializers/session_store.rb +8 -0
  63. data/spec/dummy/config/locales/en.yml +5 -0
  64. data/spec/dummy/config/routes.rb +69 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +26 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/public/javascripts/application.js +2 -0
  70. data/spec/dummy/public/javascripts/controls.js +965 -0
  71. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  72. data/spec/dummy/public/javascripts/effects.js +1123 -0
  73. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  74. data/spec/dummy/public/javascripts/rails.js +202 -0
  75. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  76. data/spec/dummy/script/rails +6 -0
  77. data/spec/spec_helper.rb +32 -0
  78. metadata +207 -0
@@ -0,0 +1,202 @@
1
+ (function() {
2
+ Ajax.Responders.register({
3
+ onCreate: function(request) {
4
+ var token = $$('meta[name=csrf-token]')[0];
5
+ if (token) {
6
+ if (!request.options.requestHeaders) request.options.requestHeaders = {};
7
+ request.options.requestHeaders['X-CSRF-Token'] = token.readAttribute('content');
8
+ }
9
+ }
10
+ });
11
+
12
+ // Technique from Juriy Zaytsev
13
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
14
+ function isEventSupported(eventName) {
15
+ var el = document.createElement('div');
16
+ eventName = 'on' + eventName;
17
+ var isSupported = (eventName in el);
18
+ if (!isSupported) {
19
+ el.setAttribute(eventName, 'return;');
20
+ isSupported = typeof el[eventName] == 'function';
21
+ }
22
+ el = null;
23
+ return isSupported;
24
+ }
25
+
26
+ function isForm(element) {
27
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM';
28
+ }
29
+
30
+ function isInput(element) {
31
+ if (Object.isElement(element)) {
32
+ var name = element.nodeName.toUpperCase();
33
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA';
34
+ }
35
+ else return false;
36
+ }
37
+
38
+ var submitBubbles = isEventSupported('submit'),
39
+ changeBubbles = isEventSupported('change');
40
+
41
+ if (!submitBubbles || !changeBubbles) {
42
+ // augment the Event.Handler class to observe custom events when needed
43
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
44
+ function(init, element, eventName, selector, callback) {
45
+ init(element, eventName, selector, callback);
46
+ // is the handler being attached to an element that doesn't support this event?
47
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
48
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
49
+ // "submit" => "emulated:submit"
50
+ this.eventName = 'emulated:' + this.eventName;
51
+ }
52
+ }
53
+ );
54
+ }
55
+
56
+ if (!submitBubbles) {
57
+ // discover forms on the page by observing focus events which always bubble
58
+ document.on('focusin', 'form', function(focusEvent, form) {
59
+ // special handler for the real "submit" event (one-time operation)
60
+ if (!form.retrieve('emulated:submit')) {
61
+ form.on('submit', function(submitEvent) {
62
+ var emulated = form.fire('emulated:submit', submitEvent, true);
63
+ // if custom event received preventDefault, cancel the real one too
64
+ if (emulated.returnValue === false) submitEvent.preventDefault();
65
+ });
66
+ form.store('emulated:submit', true);
67
+ }
68
+ });
69
+ }
70
+
71
+ if (!changeBubbles) {
72
+ // discover form inputs on the page
73
+ document.on('focusin', 'input, select, textarea', function(focusEvent, input) {
74
+ // special handler for real "change" events
75
+ if (!input.retrieve('emulated:change')) {
76
+ input.on('change', function(changeEvent) {
77
+ input.fire('emulated:change', changeEvent, true);
78
+ });
79
+ input.store('emulated:change', true);
80
+ }
81
+ });
82
+ }
83
+
84
+ function handleRemote(element) {
85
+ var method, url, params;
86
+
87
+ var event = element.fire("ajax:before");
88
+ if (event.stopped) return false;
89
+
90
+ if (element.tagName.toLowerCase() === 'form') {
91
+ method = element.readAttribute('method') || 'post';
92
+ url = element.readAttribute('action');
93
+ // serialize the form with respect to the submit button that was pressed
94
+ params = element.serialize({ submit: element.retrieve('rails:submit-button') });
95
+ // clear the pressed submit button information
96
+ element.store('rails:submit-button', null);
97
+ } else {
98
+ method = element.readAttribute('data-method') || 'get';
99
+ url = element.readAttribute('href');
100
+ params = {};
101
+ }
102
+
103
+ new Ajax.Request(url, {
104
+ method: method,
105
+ parameters: params,
106
+ evalScripts: true,
107
+
108
+ onCreate: function(response) { element.fire("ajax:create", response); },
109
+ onComplete: function(response) { element.fire("ajax:complete", response); },
110
+ onSuccess: function(response) { element.fire("ajax:success", response); },
111
+ onFailure: function(response) { element.fire("ajax:failure", response); }
112
+ });
113
+
114
+ element.fire("ajax:after");
115
+ }
116
+
117
+ function insertHiddenField(form, name, value) {
118
+ form.insert(new Element('input', { type: 'hidden', name: name, value: value }));
119
+ }
120
+
121
+ function handleMethod(element) {
122
+ var method = element.readAttribute('data-method'),
123
+ url = element.readAttribute('href'),
124
+ csrf_param = $$('meta[name=csrf-param]')[0],
125
+ csrf_token = $$('meta[name=csrf-token]')[0];
126
+
127
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
128
+ $(element.parentNode).insert(form);
129
+
130
+ if (method !== 'post') {
131
+ insertHiddenField(form, '_method', method);
132
+ }
133
+
134
+ if (csrf_param) {
135
+ insertHiddenField(form, csrf_param.readAttribute('content'), csrf_token.readAttribute('content'));
136
+ }
137
+
138
+ form.submit();
139
+ }
140
+
141
+ function disableFormElements(form) {
142
+ form.select('input[type=submit][data-disable-with]').each(function(input) {
143
+ input.store('rails:original-value', input.getValue());
144
+ input.setValue(input.readAttribute('data-disable-with')).disable();
145
+ });
146
+ }
147
+
148
+ function enableFormElements(form) {
149
+ form.select('input[type=submit][data-disable-with]').each(function(input) {
150
+ input.setValue(input.retrieve('rails:original-value')).enable();
151
+ });
152
+ }
153
+
154
+ function allowAction(element) {
155
+ var message = element.readAttribute('data-confirm');
156
+ return !message || confirm(message);
157
+ }
158
+
159
+ document.on('click', 'a[data-confirm], a[data-remote], a[data-method]', function(event, link) {
160
+ if (!allowAction(link)) {
161
+ event.stop();
162
+ return false;
163
+ }
164
+
165
+ if (link.readAttribute('data-remote')) {
166
+ handleRemote(link);
167
+ event.stop();
168
+ } else if (link.readAttribute('data-method')) {
169
+ handleMethod(link);
170
+ event.stop();
171
+ }
172
+ });
173
+
174
+ document.on("click", "form input[type=submit], form button[type=submit], form button:not([type])", function(event, button) {
175
+ // register the pressed submit button
176
+ event.findElement('form').store('rails:submit-button', button.name || false);
177
+ });
178
+
179
+ document.on("submit", function(event) {
180
+ var form = event.findElement();
181
+
182
+ if (!allowAction(form)) {
183
+ event.stop();
184
+ return false;
185
+ }
186
+
187
+ if (form.readAttribute('data-remote')) {
188
+ handleRemote(form);
189
+ event.stop();
190
+ } else {
191
+ disableFormElements(form);
192
+ }
193
+ });
194
+
195
+ document.on('ajax:create', 'form', function(event, form) {
196
+ if (form == event.findElement()) disableFormElements(form);
197
+ });
198
+
199
+ document.on('ajax:complete', 'form', function(event, form) {
200
+ if (form == event.findElement()) enableFormElements(form);
201
+ });
202
+ })();
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,32 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+ require File.expand_path("../dummy/config/environment", __FILE__)
6
+
7
+ require 'rspec/rails'
8
+ require 'rspec/autorun'
9
+
10
+ require 'restapi'
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc,
13
+ # in spec/support/ and its subdirectories.
14
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
15
+
16
+ RSpec.configure do |config|
17
+
18
+ config.mock_with :rspec
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restapi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pavel Pokorny
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec-rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rcov
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Maintain your API documentation up to date!
49
+ email:
50
+ - pajkycz@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .autotest
59
+ - .gitignore
60
+ - .rspec
61
+ - .rvmrc
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - MIT-LICENSE
65
+ - README.rdoc
66
+ - Rakefile
67
+ - app/controllers/restapis_controller.rb
68
+ - app/public/javascripts/backbone.js
69
+ - app/public/javascripts/bootstrap-collapse.js
70
+ - app/public/javascripts/bootstrap.js
71
+ - app/public/javascripts/jquery-1.7.2.js
72
+ - app/public/javascripts/json2.js
73
+ - app/public/javascripts/restapi/jst.js
74
+ - app/public/javascripts/restapi/restapi.js
75
+ - app/public/javascripts/restapi/routers/documentation_router.js
76
+ - app/public/javascripts/underscore.js
77
+ - app/public/stylesheets/bootstrap-responsive.css
78
+ - app/public/stylesheets/bootstrap-responsive.min.css
79
+ - app/public/stylesheets/bootstrap.css
80
+ - app/public/stylesheets/bootstrap.min.css
81
+ - app/public/stylesheets/restapi/application.css
82
+ - app/views/restapis/index.html.erb
83
+ - lib/restapi.rb
84
+ - lib/restapi/application.rb
85
+ - lib/restapi/dsl_definition.rb
86
+ - lib/restapi/error_description.rb
87
+ - lib/restapi/method_description.rb
88
+ - lib/restapi/param_description.rb
89
+ - lib/restapi/railtie.rb
90
+ - lib/restapi/resource_description.rb
91
+ - lib/restapi/restapi_module.rb
92
+ - lib/restapi/routing.rb
93
+ - lib/restapi/validator.rb
94
+ - lib/restapi/version.rb
95
+ - restapi.gemspec
96
+ - spec/controllers/restapis_controller_spec.rb
97
+ - spec/controllers/users_controller_spec.rb
98
+ - spec/dummy/Rakefile
99
+ - spec/dummy/app/controllers/application_controller.rb
100
+ - spec/dummy/app/controllers/dogs_controller.rb
101
+ - spec/dummy/app/controllers/twitter_example_controller.rb
102
+ - spec/dummy/app/controllers/users_controller.rb
103
+ - spec/dummy/app/helpers/application_helper.rb
104
+ - spec/dummy/app/views/layouts/application.html.erb
105
+ - spec/dummy/app/views/users/doc.html.erb
106
+ - spec/dummy/config.ru
107
+ - spec/dummy/config/application.rb
108
+ - spec/dummy/config/boot.rb
109
+ - spec/dummy/config/database.yml
110
+ - spec/dummy/config/environment.rb
111
+ - spec/dummy/config/environments/development.rb
112
+ - spec/dummy/config/environments/production.rb
113
+ - spec/dummy/config/environments/test.rb
114
+ - spec/dummy/config/initializers/backtrace_silencers.rb
115
+ - spec/dummy/config/initializers/inflections.rb
116
+ - spec/dummy/config/initializers/mime_types.rb
117
+ - spec/dummy/config/initializers/restapi.rb
118
+ - spec/dummy/config/initializers/secret_token.rb
119
+ - spec/dummy/config/initializers/session_store.rb
120
+ - spec/dummy/config/locales/en.yml
121
+ - spec/dummy/config/routes.rb
122
+ - spec/dummy/public/404.html
123
+ - spec/dummy/public/422.html
124
+ - spec/dummy/public/500.html
125
+ - spec/dummy/public/favicon.ico
126
+ - spec/dummy/public/javascripts/application.js
127
+ - spec/dummy/public/javascripts/controls.js
128
+ - spec/dummy/public/javascripts/dragdrop.js
129
+ - spec/dummy/public/javascripts/effects.js
130
+ - spec/dummy/public/javascripts/prototype.js
131
+ - spec/dummy/public/javascripts/rails.js
132
+ - spec/dummy/public/stylesheets/.gitkeep
133
+ - spec/dummy/script/rails
134
+ - spec/spec_helper.rb
135
+ homepage: http://github.com/Pajk/restapi
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project: restapi
164
+ rubygems_version: 1.8.21
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: REST API documentation tool
168
+ test_files:
169
+ - spec/controllers/restapis_controller_spec.rb
170
+ - spec/controllers/users_controller_spec.rb
171
+ - spec/dummy/Rakefile
172
+ - spec/dummy/app/controllers/application_controller.rb
173
+ - spec/dummy/app/controllers/dogs_controller.rb
174
+ - spec/dummy/app/controllers/twitter_example_controller.rb
175
+ - spec/dummy/app/controllers/users_controller.rb
176
+ - spec/dummy/app/helpers/application_helper.rb
177
+ - spec/dummy/app/views/layouts/application.html.erb
178
+ - spec/dummy/app/views/users/doc.html.erb
179
+ - spec/dummy/config.ru
180
+ - spec/dummy/config/application.rb
181
+ - spec/dummy/config/boot.rb
182
+ - spec/dummy/config/database.yml
183
+ - spec/dummy/config/environment.rb
184
+ - spec/dummy/config/environments/development.rb
185
+ - spec/dummy/config/environments/production.rb
186
+ - spec/dummy/config/environments/test.rb
187
+ - spec/dummy/config/initializers/backtrace_silencers.rb
188
+ - spec/dummy/config/initializers/inflections.rb
189
+ - spec/dummy/config/initializers/mime_types.rb
190
+ - spec/dummy/config/initializers/restapi.rb
191
+ - spec/dummy/config/initializers/secret_token.rb
192
+ - spec/dummy/config/initializers/session_store.rb
193
+ - spec/dummy/config/locales/en.yml
194
+ - spec/dummy/config/routes.rb
195
+ - spec/dummy/public/404.html
196
+ - spec/dummy/public/422.html
197
+ - spec/dummy/public/500.html
198
+ - spec/dummy/public/favicon.ico
199
+ - spec/dummy/public/javascripts/application.js
200
+ - spec/dummy/public/javascripts/controls.js
201
+ - spec/dummy/public/javascripts/dragdrop.js
202
+ - spec/dummy/public/javascripts/effects.js
203
+ - spec/dummy/public/javascripts/prototype.js
204
+ - spec/dummy/public/javascripts/rails.js
205
+ - spec/dummy/public/stylesheets/.gitkeep
206
+ - spec/dummy/script/rails
207
+ - spec/spec_helper.rb