best_in_place 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/README.md +93 -0
  4. data/Rakefile +2 -0
  5. data/best_in_place.gemspec +22 -0
  6. data/lib/best_in_place.rb +33 -0
  7. data/lib/best_in_place/version.rb +3 -0
  8. data/lib/generators/best_in_place/best_in_place_generator.rb +12 -0
  9. data/public/javascripts/best_in_place.js +244 -0
  10. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  11. data/public/javascripts/jquery.purr.js +161 -0
  12. data/test_app/.gitignore +4 -0
  13. data/test_app/Gemfile +31 -0
  14. data/test_app/Gemfile.lock +80 -0
  15. data/test_app/README +256 -0
  16. data/test_app/Rakefile +7 -0
  17. data/test_app/app/controllers/application_controller.rb +3 -0
  18. data/test_app/app/controllers/users_controller.rb +91 -0
  19. data/test_app/app/helpers/application_helper.rb +2 -0
  20. data/test_app/app/helpers/users_helper.rb +2 -0
  21. data/test_app/app/models/user.rb +15 -0
  22. data/test_app/app/views/layouts/application.html.erb +14 -0
  23. data/test_app/app/views/users/_form.html.erb +43 -0
  24. data/test_app/app/views/users/index.html.erb +21 -0
  25. data/test_app/app/views/users/new.html.erb +5 -0
  26. data/test_app/app/views/users/show.html.erb +56 -0
  27. data/test_app/config.ru +4 -0
  28. data/test_app/config/application.rb +42 -0
  29. data/test_app/config/boot.rb +13 -0
  30. data/test_app/config/database.yml +22 -0
  31. data/test_app/config/environment.rb +5 -0
  32. data/test_app/config/environments/development.rb +26 -0
  33. data/test_app/config/environments/production.rb +49 -0
  34. data/test_app/config/environments/test.rb +35 -0
  35. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test_app/config/initializers/countries.rb +1 -0
  37. data/test_app/config/initializers/inflections.rb +10 -0
  38. data/test_app/config/initializers/mime_types.rb +5 -0
  39. data/test_app/config/initializers/secret_token.rb +7 -0
  40. data/test_app/config/initializers/session_store.rb +8 -0
  41. data/test_app/config/locales/en.yml +5 -0
  42. data/test_app/config/routes.rb +64 -0
  43. data/test_app/db/migrate/20101206205922_create_users.rb +18 -0
  44. data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +9 -0
  45. data/test_app/db/migrate/20110115204441_add_description_to_user.rb +9 -0
  46. data/test_app/db/schema.rb +28 -0
  47. data/test_app/db/seeds.rb +14 -0
  48. data/test_app/doc/README_FOR_APP +2 -0
  49. data/test_app/lib/tasks/.gitkeep +0 -0
  50. data/test_app/public/404.html +26 -0
  51. data/test_app/public/422.html +26 -0
  52. data/test_app/public/500.html +26 -0
  53. data/test_app/public/favicon.ico +0 -0
  54. data/test_app/public/images/rails.png +0 -0
  55. data/test_app/public/images/red_pen.png +0 -0
  56. data/test_app/public/javascripts/application.js +64 -0
  57. data/test_app/public/javascripts/best_in_place.js +244 -0
  58. data/test_app/public/javascripts/jquery-1.4.2.min.js +154 -0
  59. data/test_app/public/javascripts/jquery.purr.js +161 -0
  60. data/test_app/public/javascripts/jquery.rest_in_place.js +254 -0
  61. data/test_app/public/javascripts/rails.js +133 -0
  62. data/test_app/public/robots.txt +5 -0
  63. data/test_app/public/stylesheets/.gitkeep +0 -0
  64. data/test_app/public/stylesheets/scaffold.css +56 -0
  65. data/test_app/public/stylesheets/style.css +75 -0
  66. data/test_app/script/rails +6 -0
  67. data/test_app/test/fixtures/users.yml +17 -0
  68. data/test_app/test/functional/users_controller_test.rb +49 -0
  69. data/test_app/test/performance/browsing_test.rb +9 -0
  70. data/test_app/test/test_helper.rb +13 -0
  71. data/test_app/test/unit/helpers/users_helper_test.rb +4 -0
  72. data/test_app/test/unit/user_test.rb +8 -0
  73. data/test_app/vendor/plugins/.gitkeep +0 -0
  74. metadata +155 -0
@@ -0,0 +1,133 @@
1
+ jQuery(function ($) {
2
+ var csrf_token = $('meta[name=csrf-token]').attr('content'),
3
+ csrf_param = $('meta[name=csrf-param]').attr('content');
4
+
5
+ $.fn.extend({
6
+ /**
7
+ * Triggers a custom event on an element and returns the event result
8
+ * this is used to get around not being able to ensure callbacks are placed
9
+ * at the end of the chain.
10
+ *
11
+ * TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our
12
+ * own events and placing ourselves at the end of the chain.
13
+ */
14
+ triggerAndReturn: function (name, data) {
15
+ var event = new $.Event(name);
16
+ this.trigger(event, data);
17
+
18
+ return event.result !== false;
19
+ },
20
+
21
+ /**
22
+ * Handles execution of remote calls firing overridable events along the way
23
+ */
24
+ callRemote: function () {
25
+ var el = this,
26
+ method = el.attr('method') || el.attr('data-method') || 'GET',
27
+ url = el.attr('action') || el.attr('href'),
28
+ dataType = el.attr('data-type') || 'script';
29
+
30
+ if (url === undefined) {
31
+ throw "No URL specified for remote call (action or href must be present).";
32
+ } else {
33
+ if (el.triggerAndReturn('ajax:before')) {
34
+ var data = el.is('form') ? el.serializeArray() : [];
35
+ $.ajax({
36
+ url: url,
37
+ data: data,
38
+ dataType: dataType,
39
+ type: method.toUpperCase(),
40
+ beforeSend: function (xhr) {
41
+ el.trigger('ajax:loading', xhr);
42
+ },
43
+ success: function (data, status, xhr) {
44
+ el.trigger('ajax:success', [data, status, xhr]);
45
+ },
46
+ complete: function (xhr) {
47
+ el.trigger('ajax:complete', xhr);
48
+ },
49
+ error: function (xhr, status, error) {
50
+ el.trigger('ajax:failure', [xhr, status, error]);
51
+ }
52
+ });
53
+ }
54
+
55
+ el.trigger('ajax:after');
56
+ }
57
+ }
58
+ });
59
+
60
+ /**
61
+ * confirmation handler
62
+ */
63
+ $('a[data-confirm],input[data-confirm]').live('click', function () {
64
+ var el = $(this);
65
+ if (el.triggerAndReturn('confirm')) {
66
+ if (!confirm(el.attr('data-confirm'))) {
67
+ return false;
68
+ }
69
+ }
70
+ });
71
+
72
+
73
+ /**
74
+ * remote handlers
75
+ */
76
+ $('form[data-remote]').live('submit', function (e) {
77
+ $(this).callRemote();
78
+ e.preventDefault();
79
+ });
80
+
81
+ $('a[data-remote],input[data-remote]').live('click', function (e) {
82
+ $(this).callRemote();
83
+ e.preventDefault();
84
+ });
85
+
86
+ $('a[data-method]:not([data-remote])').live('click', function (e){
87
+ var link = $(this),
88
+ href = link.attr('href'),
89
+ method = link.attr('data-method'),
90
+ form = $('<form method="post" action="'+href+'"></form>'),
91
+ metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
92
+
93
+ if (csrf_param != null && csrf_token != null) {
94
+ metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
95
+ }
96
+
97
+ form.hide()
98
+ .append(metadata_input)
99
+ .appendTo('body');
100
+
101
+ e.preventDefault();
102
+ form.submit();
103
+ });
104
+
105
+ /**
106
+ * disable-with handlers
107
+ */
108
+ var disable_with_input_selector = 'input[data-disable-with]';
109
+ var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
110
+ var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')';
111
+
112
+ var disable_with_input_function = function () {
113
+ $(this).find(disable_with_input_selector).each(function () {
114
+ var input = $(this);
115
+ input.data('enable-with', input.val())
116
+ .attr('value', input.attr('data-disable-with'))
117
+ .attr('disabled', 'disabled');
118
+ });
119
+ };
120
+
121
+ $(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
122
+ $(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
123
+
124
+ $(disable_with_form_remote_selector).live('ajax:complete', function () {
125
+ $(this).find(disable_with_input_selector).each(function () {
126
+ var input = $(this);
127
+ input.removeAttr('disabled')
128
+ .val(input.data('enable-with'));
129
+ });
130
+ });
131
+
132
+ });
133
+
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
File without changes
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,75 @@
1
+ /* ======================================================= */
2
+ /* User Account */
3
+ /* ======================================================= */
4
+ table {
5
+ width: 50em;
6
+ border: 1px solid #CCC;
7
+ background-color: #f5f5f5;
8
+ }
9
+ table td:first-child {
10
+ width: 12em;
11
+ padding: 0.5em;
12
+ }
13
+ table th {
14
+ text-align: left;
15
+ }
16
+ input {
17
+ width: 80%;
18
+ }
19
+ input[type=submit] {
20
+ width: 5em;
21
+ }
22
+ input[type=checkbox] {
23
+ width: 1em;
24
+ }
25
+ textarea {
26
+ height:15em;
27
+ width: 30em;
28
+ }
29
+ .best_in_place {
30
+ padding: .1m;
31
+ cursor: hand;
32
+ cursor: pointer;
33
+ -moz-transition: background 0.5s linear;
34
+ -o-transition: background 0.5s linear;
35
+ -webkit-transition: background 0.5s linear;
36
+ -moz-border-radius: 5px;
37
+ -webkit-border-radius: 5px;
38
+ -o-border-radius: 5px;
39
+ -ms-border-radius: 5px;
40
+ -khtml-border-radius: 5px;
41
+ border-radius: 5px;
42
+ }
43
+ .best_in_place:hover, #user_account .do_hover {
44
+ padding-right: 1.5em;
45
+ background: url("/images/red_pen.png") no-repeat right;
46
+ background-color: #CCC;
47
+ }
48
+ .info_edit {
49
+ float: right;
50
+ cursor: hand;
51
+ cursor: pointer;
52
+ }
53
+
54
+ /* Missatges Flotants */
55
+
56
+ .purr {
57
+ position: fixed;
58
+ width: 324px;
59
+ top: 20px;
60
+ right: 15px;
61
+ padding: 20px;
62
+ background-color: #000000;
63
+ color: #FFFFFF;
64
+ border: 2px solid #FFFFFF;
65
+ }
66
+ .purr:hover .close {
67
+ position: absolute;
68
+ top: 5px;
69
+ right: 3px;
70
+ display: block;
71
+ width: 25px;
72
+ height: 25px;
73
+ text-indent: -9999px;
74
+ background: url("/images/close-button.gif") no-repeat;
75
+ }
@@ -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,17 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+ last_name: MyString
6
+ address: MyString
7
+ email: MyString
8
+ zip: 1
9
+ country: MyString
10
+
11
+ two:
12
+ name: MyString
13
+ last_name: MyString
14
+ address: MyString
15
+ email: MyString
16
+ zip: 1
17
+ country: MyString
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+ setup do
5
+ @user = users(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get :index
10
+ assert_response :success
11
+ assert_not_nil assigns(:users)
12
+ end
13
+
14
+ test "should get new" do
15
+ get :new
16
+ assert_response :success
17
+ end
18
+
19
+ test "should create user" do
20
+ assert_difference('User.count') do
21
+ post :create, :user => @user.attributes
22
+ end
23
+
24
+ assert_redirected_to user_path(assigns(:user))
25
+ end
26
+
27
+ test "should show user" do
28
+ get :show, :id => @user.to_param
29
+ assert_response :success
30
+ end
31
+
32
+ test "should get edit" do
33
+ get :edit, :id => @user.to_param
34
+ assert_response :success
35
+ end
36
+
37
+ test "should update user" do
38
+ put :update, :id => @user.to_param, :user => @user.attributes
39
+ assert_redirected_to user_path(assigns(:user))
40
+ end
41
+
42
+ test "should destroy user" do
43
+ assert_difference('User.count', -1) do
44
+ delete :destroy, :id => @user.to_param
45
+ end
46
+
47
+ assert_redirected_to users_path
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'rails/performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionDispatch::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class UsersHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
File without changes
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: best_in_place
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Bernat Farrero
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-16 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: It is basically a jQuery script and a Rails 3 helper that allows to use the method best_in_place to display any object that the user will be able to edit by just clicking on it. It supports input data, text data, boolean data and custom dropdown data. It works with RESTful controllers.
38
+ email:
39
+ - bernat@itnig.net
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - best_in_place.gemspec
52
+ - lib/best_in_place.rb
53
+ - lib/best_in_place/version.rb
54
+ - lib/generators/best_in_place/best_in_place_generator.rb
55
+ - public/javascripts/best_in_place.js
56
+ - public/javascripts/jquery-1.4.2.min.js
57
+ - public/javascripts/jquery.purr.js
58
+ - test_app/.gitignore
59
+ - test_app/Gemfile
60
+ - test_app/Gemfile.lock
61
+ - test_app/README
62
+ - test_app/Rakefile
63
+ - test_app/app/controllers/application_controller.rb
64
+ - test_app/app/controllers/users_controller.rb
65
+ - test_app/app/helpers/application_helper.rb
66
+ - test_app/app/helpers/users_helper.rb
67
+ - test_app/app/models/user.rb
68
+ - test_app/app/views/layouts/application.html.erb
69
+ - test_app/app/views/users/_form.html.erb
70
+ - test_app/app/views/users/index.html.erb
71
+ - test_app/app/views/users/new.html.erb
72
+ - test_app/app/views/users/show.html.erb
73
+ - test_app/config.ru
74
+ - test_app/config/application.rb
75
+ - test_app/config/boot.rb
76
+ - test_app/config/database.yml
77
+ - test_app/config/environment.rb
78
+ - test_app/config/environments/development.rb
79
+ - test_app/config/environments/production.rb
80
+ - test_app/config/environments/test.rb
81
+ - test_app/config/initializers/backtrace_silencers.rb
82
+ - test_app/config/initializers/countries.rb
83
+ - test_app/config/initializers/inflections.rb
84
+ - test_app/config/initializers/mime_types.rb
85
+ - test_app/config/initializers/secret_token.rb
86
+ - test_app/config/initializers/session_store.rb
87
+ - test_app/config/locales/en.yml
88
+ - test_app/config/routes.rb
89
+ - test_app/db/migrate/20101206205922_create_users.rb
90
+ - test_app/db/migrate/20101212170114_add_receive_email_to_user.rb
91
+ - test_app/db/migrate/20110115204441_add_description_to_user.rb
92
+ - test_app/db/schema.rb
93
+ - test_app/db/seeds.rb
94
+ - test_app/doc/README_FOR_APP
95
+ - test_app/lib/tasks/.gitkeep
96
+ - test_app/public/404.html
97
+ - test_app/public/422.html
98
+ - test_app/public/500.html
99
+ - test_app/public/favicon.ico
100
+ - test_app/public/images/rails.png
101
+ - test_app/public/images/red_pen.png
102
+ - test_app/public/javascripts/application.js
103
+ - test_app/public/javascripts/best_in_place.js
104
+ - test_app/public/javascripts/jquery-1.4.2.min.js
105
+ - test_app/public/javascripts/jquery.purr.js
106
+ - test_app/public/javascripts/jquery.rest_in_place.js
107
+ - test_app/public/javascripts/rails.js
108
+ - test_app/public/robots.txt
109
+ - test_app/public/stylesheets/.gitkeep
110
+ - test_app/public/stylesheets/scaffold.css
111
+ - test_app/public/stylesheets/style.css
112
+ - test_app/script/rails
113
+ - test_app/test/fixtures/users.yml
114
+ - test_app/test/functional/users_controller_test.rb
115
+ - test_app/test/performance/browsing_test.rb
116
+ - test_app/test/test_helper.rb
117
+ - test_app/test/unit/helpers/users_helper_test.rb
118
+ - test_app/test/unit/user_test.rb
119
+ - test_app/vendor/plugins/.gitkeep
120
+ has_rdoc: true
121
+ homepage: http://github.com/bernat/best_in_place
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project: best_in_place
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: It makes any field in place editable by clicking on it, it works for inputs, textareas, select dropdowns and checkboxes
154
+ test_files: []
155
+