lperichon-jintastic 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.md +95 -0
  5. data/Rakefile +58 -0
  6. data/VERSION.yml +4 -0
  7. data/assets/app/views/jintastic/_in_place_editor.html.erb +16 -0
  8. data/assets/public/javascripts/jintastic.js +36 -0
  9. data/init.rb +2 -0
  10. data/jintastic.gemspec +47 -0
  11. data/lib/jintastic.rb +70 -0
  12. data/lperichon-jintastic.gemspec +75 -0
  13. data/test/jintastic_test.rb +7 -0
  14. data/test/test_helper.rb +10 -0
  15. data/vendor/plugins/formtastic/MIT-LICENSE +20 -0
  16. data/vendor/plugins/formtastic/README.textile +359 -0
  17. data/vendor/plugins/formtastic/Rakefile +58 -0
  18. data/vendor/plugins/formtastic/VERSION.yml +4 -0
  19. data/vendor/plugins/formtastic/formtastic.gemspec +31 -0
  20. data/vendor/plugins/formtastic/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
  21. data/vendor/plugins/formtastic/generators/formtastic_stylesheets/templates/formtastic.css +120 -0
  22. data/vendor/plugins/formtastic/generators/formtastic_stylesheets/templates/formtastic_changes.css +10 -0
  23. data/vendor/plugins/formtastic/install.rb +1 -0
  24. data/vendor/plugins/formtastic/lib/formtastic.rb +1026 -0
  25. data/vendor/plugins/formtastic/lib/justin_french/formtastic.rb +10 -0
  26. data/vendor/plugins/formtastic/lib/locale/en.yml +8 -0
  27. data/vendor/plugins/formtastic/rails/init.rb +3 -0
  28. data/vendor/plugins/formtastic/spec/formtastic_spec.rb +2407 -0
  29. data/vendor/plugins/formtastic/spec/test_helper.rb +14 -0
  30. data/vendor/plugins/formtastic/tasks/formtastic_tasks.rake +1 -0
  31. data/vendor/plugins/formtastic/uninstall.rb +1 -0
  32. metadata +96 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .idea
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2008 Nandor Komzak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,95 @@
1
+ #Jintastic
2
+
3
+ Jintastic is a **j**Query based **in**-place editor generated by [Form**tastic**](http://github.com/justinfrench/formtastic/tree/master).
4
+
5
+ ## Features
6
+
7
+ * easy usage
8
+ * you can reuse your partials and controller actions
9
+ * you can edit more than one attribute at once
10
+ * you can use nested resources
11
+
12
+ ## Install
13
+
14
+ **Gem**
15
+
16
+ sudo gem install rubymood-jintastic
17
+
18
+ Add Jintastic as a dependency in your environment.rb file:
19
+
20
+ config.gem 'rubymood-jintastic', :lib => 'jintastic'
21
+
22
+ **Plugin**
23
+
24
+ script/plugin install git://github.com/rubymood/jintastic.git
25
+
26
+ ## Usage
27
+
28
+ Having downloaded jQuery(>=1.3.2) include javascript files in your template:
29
+
30
+ <%= javascripts_include_tag 'jquery', 'jintastic' %>
31
+
32
+ **Example**
33
+
34
+ Let's say you have a bookmark resource and you have this haml files:
35
+
36
+ # bookmarks/index.html.haml
37
+ %ul
38
+ = render @bookmarks
39
+
40
+ # bookmarks/_bookmark.html.haml
41
+ %li
42
+ = bookmark.name
43
+
44
+ # bookmarks/edit.html.haml
45
+ -# with formtastic
46
+ - semantic_form_for @bookmark do |f|
47
+ -f.inputs
48
+ = render :partial=>'form', :locals=>{:f=>f}
49
+ = f.commit_button
50
+ -# or with default form_for helper
51
+ - form_for @bookmark do |f|
52
+ = render :partial=>'form'
53
+ = f.submit_tag 'Save'
54
+
55
+ # bookmarks/_form.html.haml
56
+ -# with formtastic
57
+ = f.input :name
58
+ = f.input :url
59
+ -# or with default form_for helper
60
+ = error_messages_for :bookmark
61
+ = f.text_field :name
62
+ = f.text_field :url
63
+
64
+ This is simple. If you organize your views in this way you just follows the rails conventions. Now if you want to in-place editing a bookmark inside your index page just simply do one of the below:
65
+
66
+ # bookmarks/_bookmark.html.haml
67
+ %li{:id=>dom_id(bookmark)} # we are referencing the id later in a js file (see below)
68
+ -# this shows name attribute, and if you click on it, you can edit it
69
+ = in_place_editor_for bookmark, :name
70
+ -# this shows name attribute, and if you click on it, it will show your bookmark form partial
71
+ = in_place_editor_for bookmark, :name=>:form
72
+ -# this shows name attribute, and if you click on it, it will show your custom form partial
73
+ = in_place_editor_for bookmark, :name=>'bookmarks/custom_form'
74
+ -# this shows name attribute, and if you click on it, you can edit both the name and url attributes
75
+ = in_place_editor_for bookmark, :name=>[:name, :bookmark]
76
+ -# so you can edit something else (this shows name attribute, but when you click on it, you will edit the url attribute)
77
+ = in_place_editor_for bookmark, :name=>:url
78
+ -# and finally, you can add nested resource
79
+ = in_place_editor_for [:admin, bookmark], :name
80
+
81
+ Inside your bookmark controller you have to make nothing new. The only thing you have to do is some javascript magic:
82
+
83
+ # bookmarks/update.js.erb
84
+ $('#<%= dom_id @bookmark %>').replaceWith('<%= escape_javascript render @bookmark %>')
85
+
86
+ ## And finally, what happens at validation error?
87
+
88
+ With formtastic input helper the validation errors will be displayed automatic. If you use rails default input helpers you could display the errors in your form partial (see above in the example).
89
+
90
+ ## TODO
91
+
92
+ * some options to customize in place editor form
93
+ * make some tests
94
+
95
+ Copyright (c) 2009 Nandor Komzak, released under the MIT license
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lperichon-jintastic"
8
+ gem.summary = %Q{jQuery based in-place editor generated by Formtastic}
9
+ gem.email = "nandor.komzak@gmail.com"
10
+ gem.homepage = "http://github.com/rubymood/jintastic"
11
+ gem.authors = ["Nandor Komzak"]
12
+ gem.description = gem.summary
13
+ gem.files.include FileList["{assets}/**/*"]
14
+ gem.add_dependency("justinfrench-formtastic")
15
+ gem.has_rdoc = false
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION.yml')
47
+ config = YAML.load(File.read('VERSION.yml'))
48
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "jintastic #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
58
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 1
@@ -0,0 +1,16 @@
1
+ <div class="in_place_editor_wrapper">
2
+ <%= content_tag container_tag, attribute_display, content_tag_options %>
3
+ <% semantic_form_for path_spec_or_object, form_tag_options do |f| %>
4
+ <% f.inputs do %>
5
+ <% if input_attributes %>
6
+ <% input_attributes.each do |attr| %>
7
+ <%= f.input attr %>
8
+ <% end %>
9
+ <% else %>
10
+ <%= render :partial=>form_partial, :locals=>{:f=>f} %>
11
+ <% end %>
12
+ <% end %>
13
+ <%= submit_tag 'Save', :class=>'in_place_save' %>
14
+ <input type='button' value='Cancel' class='in_place_cancel' />
15
+ <% end %>
16
+ </div>
@@ -0,0 +1,36 @@
1
+ (function($){
2
+ $(function(){
3
+ $.inPlaceEditor = {
4
+ toggle: function() {
5
+ $([this.attribute, this.form]).toggle()
6
+
7
+ if (this.form.is(':visible'))
8
+ $.inPlaceEditor.form.find('fieldset li:nth-child(1)')
9
+ }
10
+ }
11
+
12
+ $('.in_place_attribute').live('click', function() {
13
+ $.inPlaceEditor.attribute = $(this)
14
+ $.inPlaceEditor.form = $.inPlaceEditor.attribute.next()
15
+ $.inPlaceEditor.toggle()
16
+ })
17
+
18
+ $('.in_place_save').live('click', function() {
19
+ $.inPlaceEditor.form = $(this).parent('form')
20
+ $.inPlaceEditor.attribute = $.inPlaceEditor.form.prev()
21
+ $.ajax({
22
+ url: $.inPlaceEditor.form[0].action,
23
+ type: "POST",
24
+ dataType: "script",
25
+ data: $.inPlaceEditor.form.serializeArray()
26
+ })
27
+ return false
28
+ })
29
+
30
+ $('.in_place_cancel').live('click', function() {
31
+ $.inPlaceEditor.form = $(this).parent('form')
32
+ $.inPlaceEditor.attribute = $.inPlaceEditor.form.prev()
33
+ $.inPlaceEditor.toggle()
34
+ })
35
+ })
36
+ })(jQuery)
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require File.join File.dirname(__FILE__), *%w{vendor plugins formtastic rails init}
2
+ require 'jintastic'
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{jintastic}
5
+ s.version = "1.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nandor Komzak"]
9
+ s.date = %q{2009-06-22}
10
+ s.description = %q{jQuery based in-place editor generated by Formtastic}
11
+ s.email = %q{nandor.komzak@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "README.md"
14
+ ]
15
+ s.files = [
16
+ "README.md",
17
+ "Rakefile",
18
+ "VERSION.yml",
19
+ "assets/app/views/jintastic/_in_place_editor.html.erb",
20
+ "assets/public/javascripts/jintastic.js",
21
+ "lib/jintastic.rb",
22
+ "test/jintastic_test.rb",
23
+ "test/test_helper.rb"
24
+ ]
25
+ s.homepage = %q{http://github.com/rubymood/jintastic}
26
+ s.rdoc_options = ["--charset=UTF-8"]
27
+ s.require_paths = ["lib"]
28
+ s.rubygems_version = %q{1.3.1}
29
+ s.summary = %q{jQuery based in-place editor generated by Formtastic}
30
+ s.test_files = [
31
+ "test/test_helper.rb",
32
+ "test/jintastic_test.rb"
33
+ ]
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 2
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<justinfrench-formtastic>, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<justinfrench-formtastic>, [">= 0"])
43
+ end
44
+ else
45
+ s.add_dependency(%q<justinfrench-formtastic>, [">= 0"])
46
+ end
47
+ end
@@ -0,0 +1,70 @@
1
+ require 'formtastic'
2
+
3
+ class ActionView::Base
4
+ def in_place_editor_for(path_spec_or_object, attributes, options = {})
5
+ instance = case path_spec_or_object
6
+ when ActiveRecord::Base: path_spec_or_object
7
+ when Array: path_spec_or_object.last
8
+ end
9
+
10
+ if attributes.class==Symbol
11
+ #simple one attribute in place editor
12
+ #in_place_editor_for @user, :name
13
+ attribute = attributes
14
+ input_attributes = Array(attribute)
15
+
16
+ elsif attributes.values.first==:form
17
+ #render default form partial
18
+ #in_place_editor_for @user, :name=>:form
19
+ attribute = attributes.keys.first
20
+
21
+ elsif attributes.values.first.class==String
22
+ #render custom form partial
23
+ #in_place_editor_for @user, :name=>'users/custom_form'
24
+ attribute = attributes.keys.first
25
+ form_partial = attributes[attribute]
26
+
27
+ else
28
+ #attribute is an array
29
+ #in_place_editor_for @user, :name=>[:name,:address]
30
+ attribute = attributes.keys.first
31
+ input_attributes = attributes[attribute]
32
+ end
33
+
34
+ container_tag = instance.column_for_attribute(attribute).type == :text ? :pre : :span
35
+
36
+ form_tag_options = {:id=>dom_id(path_spec_or_object, attribute)}
37
+ content_tag_options = {:class=>'in_place_attribute'}
38
+
39
+ form_partial ||= "#{instance.class.to_s.downcase.pluralize}/form" unless input_attributes
40
+
41
+ attribute_display = options[:display] || instance[attribute]
42
+ path = options[:path]
43
+ if path
44
+ form_tag_options.merge!({:url=>path})
45
+ end
46
+
47
+ instance.valid?
48
+ if instance.errors.on(attribute)
49
+ content_tag_options.merge!({:style=>"display: none"})
50
+ else
51
+ form_tag_options.merge!({:html=>{:style=>"display: none"}})
52
+ end
53
+
54
+ render :partial => 'jintastic/in_place_editor',
55
+ :locals => {:container_tag=>container_tag,
56
+ :input_attributes=>input_attributes,
57
+ :attribute=>attribute,
58
+ :path_spec_or_object=>path_spec_or_object,
59
+ :instance=>instance,
60
+ :content_tag_options=>content_tag_options,
61
+ :form_tag_options=>form_tag_options,
62
+ :form_partial=>form_partial,
63
+ :attribute_display => attribute_display}
64
+ end
65
+ end
66
+
67
+ # hack for assets because gems hasn't got rake tasks
68
+ #
69
+ # copy assets at every server start because after update maybe they have to update too
70
+ FileUtils.cp_r File.join(File.dirname(__FILE__), *%w{.. assets .}), Rails.root
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lperichon-jintastic}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nandor Komzak"]
12
+ s.date = %q{2009-12-02}
13
+ s.description = %q{jQuery based in-place editor generated by Formtastic}
14
+ s.email = %q{nandor.komzak@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "MIT-LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION.yml",
25
+ "assets/app/views/jintastic/_in_place_editor.html.erb",
26
+ "assets/app/views/jintastic/_in_place_editor.html.erb",
27
+ "assets/public/javascripts/jintastic.js",
28
+ "assets/public/javascripts/jintastic.js",
29
+ "init.rb",
30
+ "jintastic.gemspec",
31
+ "lib/jintastic.rb",
32
+ "test/jintastic_test.rb",
33
+ "test/test_helper.rb",
34
+ "vendor/plugins/formtastic/MIT-LICENSE",
35
+ "vendor/plugins/formtastic/README.textile",
36
+ "vendor/plugins/formtastic/Rakefile",
37
+ "vendor/plugins/formtastic/VERSION.yml",
38
+ "vendor/plugins/formtastic/formtastic.gemspec",
39
+ "vendor/plugins/formtastic/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb",
40
+ "vendor/plugins/formtastic/generators/formtastic_stylesheets/templates/formtastic.css",
41
+ "vendor/plugins/formtastic/generators/formtastic_stylesheets/templates/formtastic_changes.css",
42
+ "vendor/plugins/formtastic/install.rb",
43
+ "vendor/plugins/formtastic/lib/formtastic.rb",
44
+ "vendor/plugins/formtastic/lib/justin_french/formtastic.rb",
45
+ "vendor/plugins/formtastic/lib/locale/en.yml",
46
+ "vendor/plugins/formtastic/rails/init.rb",
47
+ "vendor/plugins/formtastic/spec/formtastic_spec.rb",
48
+ "vendor/plugins/formtastic/spec/test_helper.rb",
49
+ "vendor/plugins/formtastic/tasks/formtastic_tasks.rake",
50
+ "vendor/plugins/formtastic/uninstall.rb"
51
+ ]
52
+ s.homepage = %q{http://github.com/rubymood/jintastic}
53
+ s.rdoc_options = ["--charset=UTF-8"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = %q{1.3.5}
56
+ s.summary = %q{jQuery based in-place editor generated by Formtastic}
57
+ s.test_files = [
58
+ "test/test_helper.rb",
59
+ "test/jintastic_test.rb"
60
+ ]
61
+
62
+ if s.respond_to? :specification_version then
63
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
+ s.specification_version = 3
65
+
66
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ s.add_runtime_dependency(%q<justinfrench-formtastic>, [">= 0"])
68
+ else
69
+ s.add_dependency(%q<justinfrench-formtastic>, [">= 0"])
70
+ end
71
+ else
72
+ s.add_dependency(%q<justinfrench-formtastic>, [">= 0"])
73
+ end
74
+ end
75
+