best_in_placeish 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
- .DS_Store
2
- .bundle
3
- pkg/*
4
-
5
- Gemfile.lock
6
- test_app/.bundle
7
- test_app/db/*.sqlite3
8
- test_app/log/*.log
9
- test_app/tmp/**/*
10
-
11
- .rvmrc
1
+ .DS_Store
2
+ .bundle
3
+ pkg/*
4
+ *.gem
5
+
6
+ Gemfile.lock
7
+ test_app/.bundle
8
+ test_app/db/*.sqlite3
9
+ test_app/log/*.log
10
+ test_app/tmp/**/*
11
+
12
+ .rvmrc
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour
1
+ --colour
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in best_in_place.gemspec
4
- gemspec
5
-
6
- gem 'sqlite3-ruby', :require => 'sqlite3'
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in best_in_place.gemspec
4
+ gemspec
5
+
6
+ gem 'sqlite3-ruby', :require => 'sqlite3'
data/README.md CHANGED
@@ -1,195 +1,212 @@
1
- # Best In Placeish
2
- Forked from the rails-3.0 branch of best_in_place, this includes a couple of key enhancements for Rails 3.0.x users
3
-
4
- **Additional features not found in best_in_place-0.2.2:**
5
-
6
- - Integrated **:display_as** functionality from master branch of best_in_place
7
- - Added purr notifications for successful updates (see updated usage notes for example)
8
-
9
- Most of the read-me below is a direct copy of best_in_place's read-me, as the vast majority of the usage is the same, though the added features are also noted below.
10
-
11
-
12
- ##Description
13
-
14
- **Best in Place** is a jQuery based AJAX Inplace-Editor that takes profit of RESTful server-side controllers to allow users to edit stuff with
15
- no need of forms. If the server has standard defined REST methods, particularly those to UPDATE your objects (HTTP PUT), adding the
16
- Javascript file to the application will make all the fields with the proper defined classes in-place editable.
17
-
18
- The editor works by PUTting the updated value to the server and GETting the updated record afterwards to display the updated value.
19
-
20
- ---
21
-
22
- ##Features
23
-
24
- - Compatible with text **inputs**
25
- - Compatible with **textarea**
26
- - Compatible with **select** dropdown with custom collections
27
- - Compatible with custom boolean values (same usage of **checkboxes**)
28
- - Sanitize HTML and trim spaces of user's input on user's choice
29
- - Displays server-side **validation** errors
30
- - Allows external activator
31
- - ESC key destroys changes (requires user confirmation)
32
- - Autogrowing textarea
33
-
34
- ---
35
-
36
- ##Usage of Rails 3 Gem
37
-
38
- **best_in_placeish object, field, OPTIONS**
39
-
40
- Params:
41
-
42
- - **object** (Mandatory): The Object parameter represents the object you are about to modify
43
- - **field** (Mandatory): The field (passed as symbol) is the attribute of the Object you are going to display/edit.
44
-
45
- Options:
46
-
47
- - **:type** Accepts [:input, :textarea, :select, :checkbox] or if undefined it defaults to :input.
48
- - **:collection**: In case you are using the :select type then you must specify the collection of values to select from. If you are
49
- using the :checkbox type you can specify the two values it can take, otherwise it will default to Yes and No.
50
- - **:path**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
51
- - **:nil**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
52
- If undefined it will show *"-"*.
53
- - **:activator**: The DOM object that can activate the field. If not defined the field will become editable by clicking on it.
54
- - **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
55
- - **:html_args**: Hash of html arguments, such as maxlength, default-value etc.
56
- - **:display_as**: A model method which will be called in order to display this field.
57
-
58
-
59
- Examples (code in the views):
60
-
61
- ### Input
62
-
63
- <%= best_in_placeish @user, :name, :type => :input %>
64
-
65
- <%= best_in_placeish @user, :name, :type => :input, :nil => "Click me to add content!" %>
66
-
67
- ### Textarea
68
-
69
- <%= best_in_placeish @user, :description, :type => :textarea %>
70
-
71
- ### Select
72
-
73
- <%= best_in_placeish @user, :country, :type => :select, :collection => [[1, "Spain"], [2, "Italy"], [3, "Germany"], [4, "France"]] %>
74
-
75
- Of course it can take an instance or global variable for the collection, just remember the structure [[key, value], [key, value],...].
76
- The key can be a string or an integer.
77
-
78
- ### Checkbox
79
-
80
- <%= best_in_placeish @user, :receive_emails, :type => :checkbox, :collection => ["No, thanks", "Yes, of course!"] %>
81
-
82
- The first value is always the negative boolean value and the second the positive. Structure: ["false value", "true value"].
83
- If not defined, it will default to *Yes* and *No* options.
84
-
85
- ### Display server validation errors
86
-
87
- If you are using a Rails application, your controllers should respond to json. **best_in_placeish adds an additional step here, requiring a hash containing your success message to be displayed using Purr.**
88
- Example:
89
- Class UsersController
90
- respond_to :html, :json
91
-
92
- def update
93
- @user = User.find(params[:id])
94
- respond_with(@user) do |format|
95
- if @user.update_attributes(params[:user])
96
- format.html { redirect_to(@user) }
97
- format.json { render :json => { :success=>"User was successfully updated." }, :status => :ok }
98
- else
99
- format.html { render :action => "edit" }
100
- format.json { render :json => @user.errors.full_messages, :status => :unprocessable_entity }
101
- end
102
- end
103
-
104
- end
105
-
106
-
107
- At the same time, you must define the restrictions, validations and error messages in the model, as the example below:
108
-
109
- class User < ActiveRecord::Base
110
- validates :name,
111
- :length => { :minimum => 2, :maximum => 24, :message => "has invalid length"},
112
- :presence => {:message => "can't be blank"}
113
- validates :last_name,
114
- :length => { :minimum => 2, :maximum => 24, :message => "has invalid length"},
115
- :presence => {:message => "can't be blank"}
116
- validates :address,
117
- :length => { :minimum => 5, :message => "too short length"},
118
- :presence => {:message => "can't be blank"}
119
- validates :email,
120
- :presence => {:message => "can't be blank"},
121
- :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "has wrong email format"}
122
- validates :zip, :numericality => true, :length => { :minimum => 5 }
123
- end
124
-
125
- When the user tries to introduce invalid data, the error messages defined in the model will be displayed in pop-up windows using the jQuery.purr plugin.
126
-
127
- ---
128
-
129
- ## Custom display methods
130
-
131
- ### Using `display_as`
132
-
133
- You can use custom methods in your model in order to
134
- decide how a certain field has to be displayed. You can write something like:
135
-
136
- = best_in_placeish @user, :description, :type => :textarea, :display_as => :mk_description
137
-
138
- Then instead of using `@user.description` to show the actual value, best in
139
- place will call `@user.mk_description`. This can be used for any kind of
140
- custom formatting, text with markdown, etc...
141
-
142
- ##Installation
143
-
144
- It works by simply copying and loading the files from the folder **/public/javascripts** to your application and loading them in your layouts
145
- in the following order:
146
-
147
- - jquery-1.4.4.js
148
- - jquery.purr.js
149
- - **best_in_placeish.js**
150
-
151
- The last one you can copy it (and keeping up to date to the last version) by running the following generator in your application's root.
152
- Remember to do it every time you update the gem (or you will see no change).
153
-
154
- rails g best_in_placeish:setup
155
-
156
- To be able to use the script the following block must be added as well:
157
-
158
- $(document).ready(function() {
159
- /* Activating Best In Place */
160
- jQuery(".best_in_placeish").best_in_placeish()
161
- });
162
-
163
- In order to use the Rails 3 gem, just add the following line to the gemfile:
164
-
165
- gem "best_in_placeish"
166
-
167
- ----
168
-
169
- ## Security
170
-
171
- If the script is used with the Rails Gem no html tags will be allowed unless the sanitize option is set to true, in that case only the tags [*b i u s a strong em p h1 h2 h3 h4 h5 ul li ol hr pre span img*] will be allowed. If the script is used without the gem and with frameworks other than Rails, then you should make sure you are providing the csrf authenticity params as meta tags and you should always escape undesired html tags such as script, object and so forth.
172
-
173
- <meta name="csrf-param" content="authenticity_token"/>
174
- <meta name="csrf-token" content="YOUR UNIQUE TOKEN HERE"/>
175
-
176
-
177
- ---
178
-
179
- ##Changelog
180
-
181
- - v.0.1.0 Initial deploy
182
- - v.0.1.2 Fixing errors in collections (taken value[0] instead of index) and fixing test_app controller responses
183
- - v.0.1.3 Bug in Rails Helper. Key wrongly considered an Integer.
184
- - v.0.1.4 Adding two new parameters for further customization urlObject and nilValue and making input update on blur.
185
- - v.0.1.5 **Attention: this release is not backwards compatible**. Changing params from list to option hash, helper's refactoring,
186
- fixing bug with objects inside namespaces, adding feature for passing an external activator handler as param. Adding feature
187
- of key ESCAPE for destroying changes before they are made permanent (in inputs and textarea).
188
- - v.0.1.6-0.1.7 Avoiding request when the input is not modified and allowing the user to not sanitize input data.
189
- - v.0.1.8 jslint compliant, sanitizing tags in the gem, getting right csrf params, controlling size of textarea (elastic script, for autogrowing textarea)
190
-
191
- ##Authors, License and Stuff
192
-
193
- Code by [Bernat Farrero](http://bernatfarrero.com) from [Itnig Web Services](http://itnig.net) (it was based on the [original project](http://github.com/janv/rest_in_place/) of Jan Varwig) and released under [MIT license](http://www.opensource.org/licenses/mit-license.php).
194
-
195
- Many thanks to the contributors: [Roger Campos](http://github.com/rogercampos) and [Jack Senechal](https://github.com/jacksenechal)
1
+ # Best In Placeish
2
+ Forked from the rails-3.0 branch of best_in_place, this includes a couple of key enhancements for Rails 3.0.x users
3
+
4
+ **Additional features not found in best_in_place-0.2.2:**
5
+
6
+ - Integrated **:display_as** functionality from master branch of best_in_place
7
+ - Added purr notifications for successful updates (see updated usage notes for example)
8
+
9
+ Most of the read-me below is a direct copy of best_in_place's read-me, as the vast majority of the usage is the same, though the added features are also noted below.
10
+
11
+
12
+ ##Description
13
+
14
+ **Best in Placeish** is a jQuery based AJAX Inplace-Editor that takes profit of RESTful server-side controllers to allow users to edit content without using a form. If the server has standard defined REST methods, particularly those to UPDATE your objects (HTTP PUT), adding the
15
+ Javascript file to the application will make all the fields with the proper classes in-place editable.
16
+
17
+ The editor works by PUTting the updated value to the server and GETting the updated record afterwards to display the updated value.
18
+
19
+ ---
20
+
21
+ ##Features
22
+
23
+ - Compatible with text **inputs**
24
+ - Compatible with **textarea**
25
+ - Compatible with **select** dropdown with custom collections
26
+ - Compatible with custom boolean values (same usage of **checkboxes**)
27
+ - Sanitize HTML and trim spaces of user's input on user's choice
28
+ - Displays server-side **validation** errors
29
+ - Allows external activator
30
+ - ESC key destroys changes (requires user confirmation)
31
+ - Autogrowing textarea
32
+
33
+ ---
34
+
35
+ ##Usage of Rails 3 Gem
36
+
37
+ **best_in_placeish object, field, OPTIONS**
38
+
39
+ Params:
40
+
41
+ - **object** (required): The Object parameter represents the object you are about to modify
42
+ - **field** (required): The field (passed as symbol) is the attribute of the Object you are going to display/edit.
43
+
44
+ Options:
45
+
46
+ - **:type** Accepts [:input, :textarea, :select, :checkbox] or if undefined it defaults to :input.
47
+ - **:collection**: In case you are using the :select type then you must specify the collection of values to select from. If you are
48
+ using the :checkbox type you can specify the two values it can take, otherwise it will default to Yes and No.
49
+ - **:path**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
50
+ - **:nil**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
51
+ If undefined it will show *"-"*.
52
+ - **:activator**: The DOM object that can activate the field. If not defined the field will become editable by clicking on it.
53
+ - **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
54
+ - **:html_args**: Hash of html arguments, such as maxlength, default-value etc.
55
+ - **:display_as**: A model method which will be called in order to display this field.
56
+
57
+
58
+ Examples (code in the views):
59
+
60
+ ### Input
61
+
62
+ <%= best_in_placeish @user, :name, :type => :input %>
63
+
64
+ <%= best_in_placeish @user, :name, :type => :input, :nil => "Click me to add content!" %>
65
+
66
+ ### Datepicker (REQUIRES JQUERYUI - http://jqueryui.com/)
67
+
68
+ <%= best_in_placeish @user, :registered_on, :type => :datepicker %>
69
+
70
+ Currently returns the selected date in dd/MMM/yyyy format (for example: 01/JAN/2012)
71
+
72
+ ### Textarea
73
+
74
+ <%= best_in_placeish @user, :description, :type => :textarea %>
75
+
76
+ ### Select
77
+
78
+ <%= best_in_placeish @user, :country, :type => :select, :collection => [[1, "Spain"], [2, "Italy"], [3, "Germany"], [4, "France"]] %>
79
+
80
+ Of course it can take an instance or global variable for the collection, just remember the structure [[key, value], [key, value],...].
81
+ The key can be a string or an integer.
82
+
83
+ ### Checkbox
84
+
85
+ <%= best_in_placeish @user, :receive_emails, :type => :checkbox, :collection => ["No, thanks", "Yes, of course!"] %>
86
+
87
+ The first value is always the negative boolean value and the second the positive. Structure: ["false value", "true value"].
88
+ If not defined, it will default to *Yes* and *No* options.
89
+
90
+ ### Display server validation errors
91
+
92
+ If you are using a Rails application, your controllers should respond to json. **best_in_placeish adds an additional step here, requiring a hash containing your success message to be displayed using Purr.**
93
+ Example:
94
+
95
+ Class UsersController
96
+
97
+ respond_to :html, :json
98
+
99
+ def update
100
+ @user = User.find(params[:id])
101
+ respond_with(@user) do |format|
102
+ if @user.update_attributes(params[:user])
103
+ format.html { redirect_to(@user) }
104
+ format.json { render :json => { :success=>"User was successfully updated." }, :status => :ok }
105
+ else
106
+ format.html { render :action => "edit" }
107
+ format.json { render :json => @user.errors.full_messages, :status => :unprocessable_entity }
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+
114
+ At the same time, you must define the restrictions, validations and error messages in the model, as the example below:
115
+
116
+ class User < ActiveRecord::Base
117
+
118
+ validates :name,
119
+ :length => { :minimum => 2, :maximum => 24, :message => "has invalid length"},
120
+ :presence => {:message => "can't be blank"}
121
+ validates :last_name,
122
+ :length => { :minimum => 2, :maximum => 24, :message => "has invalid length"},
123
+ :presence => {:message => "can't be blank"}
124
+ validates :address,
125
+ :length => { :minimum => 5, :message => "too short length"},
126
+ :presence => {:message => "can't be blank"}
127
+ validates :email,
128
+ :presence => {:message => "can't be blank"},
129
+ :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "has wrong email format"}
130
+ validates :zip, :numericality => true, :length => { :minimum => 5 }
131
+
132
+ end
133
+
134
+ When the user tries to introduce invalid data, the error messages defined in the model will be displayed in pop-up windows using the jQuery.purr plugin.
135
+
136
+ ---
137
+
138
+ ## Custom display methods
139
+
140
+ ### Using `display_as`
141
+
142
+ You can use custom methods in your model in order to
143
+ decide how a certain field has to be displayed. You can write something like:
144
+
145
+ = best_in_placeish @user, :description, :type => :textarea, :display_as => :mk_description
146
+
147
+ Then instead of using `@user.description` to show the actual value, best in
148
+ place will call `@user.mk_description`. This can be used for any kind of
149
+ custom formatting, text with markdown, etc...
150
+
151
+ ##Installation
152
+
153
+ It works by simply copying and loading the files from the folder **/public/javascripts** to your application and loading them in your layouts
154
+ in the following order:
155
+
156
+ - jquery-1.4.4.js
157
+ - jquery.purr.js
158
+ - **best_in_placeish.js**
159
+
160
+ The last one you can copy it (and keeping up to date to the last version) by running the following generator in your application's root.
161
+ Remember to do it every time you update the gem (or you will see no change).
162
+
163
+ rails g best_in_placeish:setup
164
+
165
+ To be able to use the script the following block must be added as well:
166
+
167
+ $(document).ready(function() {
168
+ jQuery(".best_in_placeish").best_in_placeish()
169
+ });
170
+
171
+ In order to use the Rails 3 gem, just add the following line to the gemfile:
172
+
173
+ gem "best_in_placeish"
174
+
175
+ ----
176
+
177
+ ## Security
178
+
179
+ If the script is used with the Rails Gem no html tags will be allowed unless the sanitize option is set to true, in that case only the tags [*b i u s a strong em p h1 h2 h3 h4 h5 ul li ol hr pre span img*] will be allowed. If the script is used without the gem and with frameworks other than Rails, then you should make sure you are providing the csrf authenticity params as meta tags and you should always escape undesired html tags such as script, object and so forth.
180
+
181
+ <meta name="csrf-param" content="authenticity_token"/>
182
+ <meta name="csrf-token" content="YOUR UNIQUE TOKEN HERE"/>
183
+
184
+
185
+ ---
186
+
187
+ ##Changelog
188
+
189
+ best_in_place:
190
+
191
+ - v.0.1.0 Initial deploy
192
+ - v.0.1.2 Fixing errors in collections (taken value[0] instead of index) and fixing test_app controller responses
193
+ - v.0.1.3 Bug in Rails Helper. Key wrongly considered an Integer.
194
+ - v.0.1.4 Adding two new parameters for further customization urlObject and nilValue and making input update on blur.
195
+ - v.0.1.5 **Attention: this release is not backwards compatible**. Changing params from list to option hash, helper's refactoring,
196
+ fixing bug with objects inside namespaces, adding feature for passing an external activator handler as param. Adding feature
197
+ of key ESCAPE for destroying changes before they are made permanent (in inputs and textarea).
198
+ - v.0.1.6-0.1.7 Avoiding request when the input is not modified and allowing the user to not sanitize input data.
199
+ - v.0.1.8 jslint compliant, sanitizing tags in the gem, getting right csrf params, controlling size of textarea (elastic script, for autogrowing textarea)
200
+ - v.0.2.2 last rails 3.0.x version according to best_in_place project page
201
+
202
+ best_in_placeish:
203
+
204
+ - v.0.2.4 first best_in_placeish release, added success messaging and :display_as functions
205
+
206
+ ##Authors, License and Stuff
207
+
208
+ Original best_in_place code by [Bernat Farrero](http://bernatfarrero.com) from [Itnig Web Services](http://itnig.net) (it was based on the [original project](http://github.com/janv/rest_in_place/) of Jan Varwig) and released under [MIT license](http://www.opensource.org/licenses/mit-license.php).
209
+
210
+ best_in_place contributors: [Roger Campos](http://github.com/rogercampos) and [Jack Senechal](https://github.com/jacksenechal)
211
+
212
+ best_in_placeish-specific code by [Miles Roberts](http://github.com/MilesRoberts)
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core'
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task :default => :spec
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec