admin_fu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.document +11 -0
  2. data/.metrics +5 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +133 -0
  6. data/LICENSE +20 -0
  7. data/LICENSE_ADMIN_TEMPLATE +10 -0
  8. data/README.rdoc +3 -0
  9. data/Rakefile +44 -0
  10. data/VERSION +1 -0
  11. data/app/controllers/admin_fu/application_controller.rb +4 -0
  12. data/app/controllers/admin_fu/dashboards_controller.rb +4 -0
  13. data/app/controllers/admin_fu/samples_controller.rb +7 -0
  14. data/app/helpers/admin_fu_helper.rb +20 -0
  15. data/app/stylesheets/_colors.sass +73 -0
  16. data/app/stylesheets/_template.sass +71 -0
  17. data/app/stylesheets/_typography.sass +60 -0
  18. data/app/stylesheets/_utils.sass +7 -0
  19. data/app/stylesheets/styles.sass +51 -0
  20. data/app/views/admin_fu/dashboards/show.html.haml +35 -0
  21. data/app/views/admin_fu/samples/form.html.haml +25 -0
  22. data/app/views/admin_fu/samples/list.html.haml +33 -0
  23. data/app/views/admin_fu/samples/text.html.haml +12 -0
  24. data/app/views/layouts/_flash.html.haml +4 -0
  25. data/app/views/layouts/admin_fu.html.haml +27 -0
  26. data/config/compass.rb +7 -0
  27. data/config/routes.rb +9 -0
  28. data/lib/admin_fu.rb +4 -0
  29. data/lib/admin_fu/config.rb +41 -0
  30. data/lib/admin_fu/engine.rb +11 -0
  31. data/lib/admin_fu/rails/routes.rb +8 -0
  32. data/public/images/admin_fu/body.png +0 -0
  33. data/public/images/admin_fu/box-h2.png +0 -0
  34. data/public/images/admin_fu/edit.png +0 -0
  35. data/public/images/admin_fu/error.png +0 -0
  36. data/public/images/admin_fu/gradient.png +0 -0
  37. data/public/images/admin_fu/trash.png +0 -0
  38. data/public/javascripts/admin_fu/html5.js +2 -0
  39. data/public/stylesheets/admin_fu/styles.css +1005 -0
  40. data/spec/dummy/Rakefile +7 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  42. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  43. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  44. data/spec/dummy/config.ru +4 -0
  45. data/spec/dummy/config/application.rb +44 -0
  46. data/spec/dummy/config/boot.rb +10 -0
  47. data/spec/dummy/config/environment.rb +5 -0
  48. data/spec/dummy/config/environments/development.rb +26 -0
  49. data/spec/dummy/config/environments/production.rb +49 -0
  50. data/spec/dummy/config/environments/test.rb +35 -0
  51. data/spec/dummy/config/initializers/admin_fu.rb +7 -0
  52. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/spec/dummy/config/initializers/inflections.rb +10 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/locales/en.yml +10 -0
  58. data/spec/dummy/config/routes.rb +6 -0
  59. data/spec/dummy/public/404.html +26 -0
  60. data/spec/dummy/public/422.html +26 -0
  61. data/spec/dummy/public/500.html +26 -0
  62. data/spec/dummy/public/favicon.ico +0 -0
  63. data/spec/dummy/public/javascripts/application.js +2 -0
  64. data/spec/dummy/public/javascripts/controls.js +965 -0
  65. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  66. data/spec/dummy/public/javascripts/effects.js +1123 -0
  67. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  68. data/spec/dummy/public/javascripts/rails.js +175 -0
  69. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  70. data/spec/dummy/script/rails +6 -0
  71. data/spec/requests/menu_spec.rb +25 -0
  72. data/spec/requests/routes_spec.rb +21 -0
  73. data/spec/requests/samples_spec.rb +23 -0
  74. data/spec/spec_helper.rb +32 -0
  75. metadata +239 -0
@@ -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,25 @@
1
+ require "spec_helper"
2
+
3
+ describe "AdminFu menus" do
4
+
5
+ before :each do
6
+ AdminFu.clear_menu
7
+ AdminFu.menu do
8
+ entry :menu1, :menu1_path
9
+ entry :menu2, "/custommenu2"
10
+ entry :menu3, "/"
11
+ end
12
+ end
13
+
14
+ it "should show configured menus on admin layout" do
15
+ visit admin_fu_root_path
16
+ page.should have_selector("nav[role=mainmenu] ul li a[href='#{menu1_path}']")
17
+ page.should have_selector("nav[role=mainmenu] ul li a[href='/custommenu2']")
18
+ page.should have_selector("nav[role=mainmenu] ul li a[href='/']")
19
+ end
20
+
21
+ after :each do
22
+ Rails.application.reload_routes!
23
+ end
24
+
25
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe "AdminFu routes" do
4
+
5
+ before :each do
6
+ Rails.application.routes.draw do
7
+ admin_fu_namespace do
8
+ resource :apples
9
+ end
10
+ end
11
+ end
12
+
13
+ it "should generate url helpers alias with admin_fu_namespace and the configured namespace" do
14
+ admin_fu_apples_path.should == admin_apples_path
15
+ end
16
+
17
+ after :each do
18
+ Rails.application.reload_routes!
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe "AdminFu samples" do
4
+
5
+ it "should show the form sample page" do
6
+ visit admin_fu_sample_path('form')
7
+ page.should have_selector("form")
8
+ page.should have_content("News Article")
9
+ end
10
+
11
+ it "should show the text sample page" do
12
+ visit admin_fu_sample_path('text')
13
+ page.should have_content("About")
14
+ page.should have_content("Credits")
15
+ end
16
+
17
+ it "should show the list sample page" do
18
+ visit admin_fu_sample_path('list')
19
+ page.should have_selector("input[value='Search']")
20
+ find('table').should have_content('Actions')
21
+ end
22
+
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ # Configure Rails Envinronment
5
+ ENV["RAILS_ENV"] = "test"
6
+
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
+ require "rspec/rails"
9
+
10
+ ActionMailer::Base.delivery_method = :test
11
+ ActionMailer::Base.perform_deliveries = true
12
+ ActionMailer::Base.default_url_options[:host] = "test.com"
13
+
14
+ Rails.backtrace_cleaner.remove_silencers!
15
+
16
+ # Configure capybara for integration testing
17
+ require "capybara/rails"
18
+ Capybara.default_driver = :rack_test
19
+ Capybara.default_selector = :css
20
+
21
+ # Load support files
22
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
23
+
24
+ RSpec.configure do |config|
25
+ # Remove this line if you don't want RSpec's should and should_not
26
+ # methods or matchers
27
+ require 'rspec/expectations'
28
+ config.include RSpec::Matchers
29
+
30
+ # == Mock Framework
31
+ config.mock_with :rspec
32
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: admin_fu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Fabio Kreusch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-15 00:00:00 -02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml-rails
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.7
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: simplecov
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.3.8
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec-rails
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 2.0.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: sqlite3-ruby
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: capybara
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: jeweler
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: 1.5.2
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ description: Provides a basic administration interface for Rails3 applications
105
+ email: fabio@kreusch.com.br
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files:
111
+ - LICENSE
112
+ - LICENSE_ADMIN_TEMPLATE
113
+ - README.rdoc
114
+ files:
115
+ - .document
116
+ - .metrics
117
+ - .rspec
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE
121
+ - LICENSE_ADMIN_TEMPLATE
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - app/controllers/admin_fu/application_controller.rb
126
+ - app/controllers/admin_fu/dashboards_controller.rb
127
+ - app/controllers/admin_fu/samples_controller.rb
128
+ - app/helpers/admin_fu_helper.rb
129
+ - app/stylesheets/_colors.sass
130
+ - app/stylesheets/_template.sass
131
+ - app/stylesheets/_typography.sass
132
+ - app/stylesheets/_utils.sass
133
+ - app/stylesheets/styles.sass
134
+ - app/views/admin_fu/dashboards/show.html.haml
135
+ - app/views/admin_fu/samples/form.html.haml
136
+ - app/views/admin_fu/samples/list.html.haml
137
+ - app/views/admin_fu/samples/text.html.haml
138
+ - app/views/layouts/_flash.html.haml
139
+ - app/views/layouts/admin_fu.html.haml
140
+ - config/compass.rb
141
+ - config/routes.rb
142
+ - lib/admin_fu.rb
143
+ - lib/admin_fu/config.rb
144
+ - lib/admin_fu/engine.rb
145
+ - lib/admin_fu/rails/routes.rb
146
+ - public/images/admin_fu/body.png
147
+ - public/images/admin_fu/box-h2.png
148
+ - public/images/admin_fu/edit.png
149
+ - public/images/admin_fu/error.png
150
+ - public/images/admin_fu/gradient.png
151
+ - public/images/admin_fu/trash.png
152
+ - public/javascripts/admin_fu/html5.js
153
+ - public/stylesheets/admin_fu/styles.css
154
+ - spec/dummy/Rakefile
155
+ - spec/dummy/app/controllers/application_controller.rb
156
+ - spec/dummy/app/helpers/application_helper.rb
157
+ - spec/dummy/app/views/layouts/application.html.erb
158
+ - spec/dummy/config.ru
159
+ - spec/dummy/config/application.rb
160
+ - spec/dummy/config/boot.rb
161
+ - spec/dummy/config/environment.rb
162
+ - spec/dummy/config/environments/development.rb
163
+ - spec/dummy/config/environments/production.rb
164
+ - spec/dummy/config/environments/test.rb
165
+ - spec/dummy/config/initializers/admin_fu.rb
166
+ - spec/dummy/config/initializers/backtrace_silencers.rb
167
+ - spec/dummy/config/initializers/inflections.rb
168
+ - spec/dummy/config/initializers/mime_types.rb
169
+ - spec/dummy/config/initializers/secret_token.rb
170
+ - spec/dummy/config/initializers/session_store.rb
171
+ - spec/dummy/config/locales/en.yml
172
+ - spec/dummy/config/routes.rb
173
+ - spec/dummy/public/404.html
174
+ - spec/dummy/public/422.html
175
+ - spec/dummy/public/500.html
176
+ - spec/dummy/public/favicon.ico
177
+ - spec/dummy/public/javascripts/application.js
178
+ - spec/dummy/public/javascripts/controls.js
179
+ - spec/dummy/public/javascripts/dragdrop.js
180
+ - spec/dummy/public/javascripts/effects.js
181
+ - spec/dummy/public/javascripts/prototype.js
182
+ - spec/dummy/public/javascripts/rails.js
183
+ - spec/dummy/public/stylesheets/.gitkeep
184
+ - spec/dummy/script/rails
185
+ - spec/requests/menu_spec.rb
186
+ - spec/requests/routes_spec.rb
187
+ - spec/requests/samples_spec.rb
188
+ - spec/spec_helper.rb
189
+ has_rdoc: true
190
+ homepage: ""
191
+ licenses: []
192
+
193
+ post_install_message:
194
+ rdoc_options: []
195
+
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ none: false
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ hash: 2097967032112241607
204
+ segments:
205
+ - 0
206
+ version: "0"
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ none: false
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: "0"
213
+ requirements: []
214
+
215
+ rubyforge_project:
216
+ rubygems_version: 1.5.0
217
+ signing_key:
218
+ specification_version: 3
219
+ summary: Basic administration interface for Rails3 apps
220
+ test_files:
221
+ - spec/dummy/app/controllers/application_controller.rb
222
+ - spec/dummy/app/helpers/application_helper.rb
223
+ - spec/dummy/config/application.rb
224
+ - spec/dummy/config/boot.rb
225
+ - spec/dummy/config/environment.rb
226
+ - spec/dummy/config/environments/development.rb
227
+ - spec/dummy/config/environments/production.rb
228
+ - spec/dummy/config/environments/test.rb
229
+ - spec/dummy/config/initializers/admin_fu.rb
230
+ - spec/dummy/config/initializers/backtrace_silencers.rb
231
+ - spec/dummy/config/initializers/inflections.rb
232
+ - spec/dummy/config/initializers/mime_types.rb
233
+ - spec/dummy/config/initializers/secret_token.rb
234
+ - spec/dummy/config/initializers/session_store.rb
235
+ - spec/dummy/config/routes.rb
236
+ - spec/requests/menu_spec.rb
237
+ - spec/requests/routes_spec.rb
238
+ - spec/requests/samples_spec.rb
239
+ - spec/spec_helper.rb