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 +12 -11
- data/.rspec +1 -1
- data/Gemfile +6 -6
- data/README.md +212 -195
- data/Rakefile +8 -8
- data/best_in_placeish.gemspec +27 -27
- data/lib/best_in_placeish.rb +8 -8
- data/lib/best_in_placeish/helper.rb +57 -57
- data/lib/best_in_placeish/test_helpers.rb +39 -39
- data/lib/best_in_placeish/utils.rb +15 -15
- data/lib/best_in_placeish/version.rb +3 -3
- data/lib/generators/best_in_placeish/setup_generator.rb +11 -11
- data/public/javascripts/best_in_placeish.js +39 -0
- data/spec/helpers/best_in_place_spec.rb +239 -239
- data/spec/integration/double_init_spec.rb +32 -32
- data/spec/integration/js_spec.rb +165 -165
- data/spec/integration/text_area_spec.rb +30 -30
- data/spec/spec_helper.rb +23 -23
- metadata +4 -6
- data/best_in_placeish-0.2.2.gem +0 -0
- data/best_in_placeish-0.2.3.gem +0 -0
data/.gitignore
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
.DS_Store
|
2
|
-
.bundle
|
3
|
-
pkg/*
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
test_app
|
8
|
-
test_app/
|
9
|
-
test_app/
|
10
|
-
|
11
|
-
|
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
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- Compatible with
|
25
|
-
- Compatible with **
|
26
|
-
- Compatible with
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
- **
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
- **:
|
48
|
-
|
49
|
-
|
50
|
-
- **:
|
51
|
-
|
52
|
-
|
53
|
-
- **:
|
54
|
-
- **:
|
55
|
-
- **:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
:presence => {:message => "can't be blank"}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|