simply_edit 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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README +53 -0
- data/Rakefile +1 -0
- data/lib/generators/simply_edit/USAGE +8 -0
- data/lib/generators/simply_edit/simply_edit_generator.rb +8 -0
- data/lib/generators/simply_edit/templates/simply_edit.js +44 -0
- data/lib/simply_edit.rb +29 -0
- data/lib/simply_edit/version.rb +3 -0
- data/simply_edit.gemspec +21 -0
- metadata +74 -0
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Simply edit is a view helper that convert any label into an editable text, textarea or date picker field using JQuery.
|
2
|
+
|
3
|
+
Why did I make a gem out of this little thing? I felt it was a waste of time to got to a form if you only needed to update a title, content or a date. The helper currently only supports, text, textarea and date. The date field is basically a jQuery date control so styling in depends on the jQuery UI templating framework.
|
4
|
+
Anyway, hope you guys like it and sure there is always room for improvement.
|
5
|
+
|
6
|
+
Installing:
|
7
|
+
|
8
|
+
Add this to you Gemfile:
|
9
|
+
|
10
|
+
gem 'simply_edit'
|
11
|
+
|
12
|
+
The run:
|
13
|
+
|
14
|
+
bundle install
|
15
|
+
|
16
|
+
As simply_edit uses a javascript files, you will be required to install it for use (also remember to include it with javascript_include_tag):
|
17
|
+
|
18
|
+
rails g simply_edit
|
19
|
+
|
20
|
+
First you will need to include jquery-ui to you javascript files if you want to use the date_picker functionality.
|
21
|
+
|
22
|
+
Rails 3.1 (add this to application.js):
|
23
|
+
|
24
|
+
//= require jquery-ui
|
25
|
+
|
26
|
+
<= Rails 3.0:
|
27
|
+
|
28
|
+
Add the jquery-ui.js file of your preference to you layout file.
|
29
|
+
|
30
|
+
|
31
|
+
Using:
|
32
|
+
|
33
|
+
On any of your views just use this code:
|
34
|
+
|
35
|
+
<%= simply_edit_text_field(object, field, update_url, {other options} %>
|
36
|
+
<%= simply_edit_text_area(object, field, update_url, {other options} %>
|
37
|
+
<%= simply_edit_date_field(object, field, update_url, {other options} %>
|
38
|
+
|
39
|
+
Callbacks:
|
40
|
+
|
41
|
+
In order to react to a edit success and error event, you will need to listen to the "simply_edit:success" and "simply_edit:error" events like this:
|
42
|
+
|
43
|
+
$("#simply_edit_object").live("simply_edit:success", function(data){
|
44
|
+
alert("Updated sucessfully.");
|
45
|
+
}
|
46
|
+
|
47
|
+
$("#simply_edit_object").live("simply_edit:error", function(data){
|
48
|
+
alert("Failed to edit.");
|
49
|
+
}
|
50
|
+
|
51
|
+
That is basically it.
|
52
|
+
|
53
|
+
Hope you like it!!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Description:
|
2
|
+
This will copy the required javascript file to the Rails application ("public/javascripts/simply_edit.js" or "app/assets/javascripts/simply_edit.js")
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate simply_edit
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
public/javascripts/simply_edit.js or app/assets/javascripts/simply_edit.js
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class SimplyEditGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def generate_javascript
|
5
|
+
copy_file "simply_edit.js", (Rails::VERSION::STRING.starts_with?("3.1") ? "app/assets/javascripts/simply_edit.js" : "public/javascripts/simply_edit.js")
|
6
|
+
end
|
7
|
+
|
8
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
// Create Date picker fields
|
4
|
+
$(".simple_edit_date_field .simply_edit_input").live("mouseover", function(){
|
5
|
+
$(this).datepicker({ dateFormat: 'yy-mm-dd' });
|
6
|
+
});
|
7
|
+
// Display the editing elements and attach AJAX Functionality.
|
8
|
+
$('.simply_edit_link').live("click", function(){
|
9
|
+
$(this).siblings('.simply_edit_fields').show();
|
10
|
+
$(this).hide();
|
11
|
+
});
|
12
|
+
$('.simply_edit_cancel').live("click", function(){
|
13
|
+
$(this).parents(".simply_edit_fields").siblings(".simply_edit_link").show();
|
14
|
+
$(this).parents(".simply_edit_fields").hide();
|
15
|
+
});
|
16
|
+
$('.simply_edit_save').live("click", function(){
|
17
|
+
var $this = $(this);
|
18
|
+
var $parent = $this.parents(".simply_edit");
|
19
|
+
var $url = $(this).attr("data-href");
|
20
|
+
var $input = $(this).parents(".simply_edit_fields").find(".simply_edit_input");
|
21
|
+
|
22
|
+
if($input.length > 0){
|
23
|
+
var $value = $input.val();
|
24
|
+
var $name = $input.attr("name");
|
25
|
+
}
|
26
|
+
|
27
|
+
$.ajax({
|
28
|
+
type: 'post',
|
29
|
+
data: $name + "=" + $value +"&_method=put",
|
30
|
+
success: function(data){
|
31
|
+
$parent.find(".simply_edit_link").text($value);
|
32
|
+
$parent.trigger("simply_edit:success", data);
|
33
|
+
},
|
34
|
+
complete: function(){
|
35
|
+
$parent.find(".simply_edit_link").show();
|
36
|
+
$parent.find(".simply_edit_fields").hide();
|
37
|
+
},
|
38
|
+
error: function(data){
|
39
|
+
$parent.trigger("simply_edit:error", data);
|
40
|
+
},
|
41
|
+
url: $url
|
42
|
+
});
|
43
|
+
});
|
44
|
+
});
|
data/lib/simply_edit.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "simply_edit/version"
|
2
|
+
|
3
|
+
module SimplyEdit
|
4
|
+
def date_field_tag(*args)
|
5
|
+
text_field_tag(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def simply_edit(type, object, field, url, options = {})
|
9
|
+
options[:class] = "#{options[:class]} simply_edit simple_edit_#{type}".strip
|
10
|
+
content_tag(:span, :class => options[:class]) do
|
11
|
+
(link_to object.send(field).blank? ? "Edit Text" : object.send(field), "javascript:void(0);", :class => "simply_edit_link") +
|
12
|
+
content_tag(:span, :class => "simply_edit_fields", :style => "display:none;") do
|
13
|
+
(eval("#{type}_tag('#{object.class.to_s.downcase}[#{field}]', object.send(field), :class => 'simply_edit_input')")) +
|
14
|
+
content_tag(:span, :class => "simply_edit_actions") do
|
15
|
+
(link_to("Save", "javascript:void(0);", :class => "simply_edit_save save", :"data-href" => url)) +
|
16
|
+
(link_to("Cancel", "javascript:void(0);", :class => "simply_edit_cancel cancel"))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
%w(text_field text_area date_field).each do |method|
|
23
|
+
define_method("simply_edit_#{method}") do |*args|
|
24
|
+
simply_edit(method, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActionView::Base.send(:include, SimplyEdit)
|
data/simply_edit.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simply_edit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simply_edit"
|
7
|
+
s.version = SimplyEdit::VERSION
|
8
|
+
s.authors = ["Firebait"]
|
9
|
+
s.email = ["marcotapiag@gmail.com"]
|
10
|
+
s.homepage = "http://firebait.com"
|
11
|
+
s.summary = %q{Rails gem that makes updating a field from a database via ajax simply by converting a link into a texfield, textarea or a datefield. Useful for making editable labels.}
|
12
|
+
s.description = %q{Rails gem that makes updating a field from a database via ajax simply by converting a link into a texfield, textarea or a datefield.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "simply_edit"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_dependency('jquery-rails')
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simply_edit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Firebait
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-19 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jquery-rails
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Rails gem that makes updating a field from a database via ajax simply by converting a link into a texfield, textarea or a datefield.
|
27
|
+
email:
|
28
|
+
- marcotapiag@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- README
|
39
|
+
- Rakefile
|
40
|
+
- lib/generators/simply_edit/USAGE
|
41
|
+
- lib/generators/simply_edit/simply_edit_generator.rb
|
42
|
+
- lib/generators/simply_edit/templates/simply_edit.js
|
43
|
+
- lib/simply_edit.rb
|
44
|
+
- lib/simply_edit/version.rb
|
45
|
+
- simply_edit.gemspec
|
46
|
+
homepage: http://firebait.com
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: simply_edit
|
69
|
+
rubygems_version: 1.8.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Rails gem that makes updating a field from a database via ajax simply by converting a link into a texfield, textarea or a datefield. Useful for making editable labels.
|
73
|
+
test_files: []
|
74
|
+
|