repeated_auto_complete 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,108 @@
1
+ =Repeated Auto Complete
2
+
3
+ Fork of the standard auto_complete plugin to support:
4
+
5
+ 1. Creating auto complete text fields that can be repeated more than once on a single form.
6
+
7
+ 2. Using auto_complete_for with named scopes to display a customized list of autocomplete options.
8
+
9
+ See: {http://patshaughnessy.net/repeated_auto_complete}[http://patshaughnessy.net/repeated_auto_complete] for details.
10
+
11
+ == Install as a gem
12
+
13
+ gem sources -a http://gemcutter.org
14
+ sudo gem install repeated_auto_complete
15
+
16
+ and in config/environment.rb:
17
+
18
+ Rails::Initializer.run do |config|
19
+
20
+ config.gem "repeated_auto_complete"
21
+
22
+ end
23
+
24
+ == Install as a plugin
25
+
26
+ script/plugin install git://github.com/patshaughnessy/auto_complete.git
27
+
28
+ == Repeated autocomplete text fields:
29
+
30
+ A "text_field_with_auto_complete" method is made available to the form builder
31
+ yielded by form_for and fields_for that:
32
+ - Insures unique id's for <input> and <div> tags by inserting unique integers into their id attributes
33
+ - Uses the object name from the surrounding call to form_for or fields_for so attribute mass assignment will work as usual
34
+ - Works with the same server side controller method, auto_complete_for, as usual
35
+ - Supports nested attributes in Rails 2.3
36
+
37
+ form.text_field_with_auto_complete works the same as the original text_field_with_auto_complete macro, except it does not take the object as a parameter.
38
+
39
+ Example with nested attributes using Rails 2.3 or later:
40
+
41
+ class Project < ActiveRecord::Base
42
+ has_many :tasks
43
+ accepts_nested_attributes_for :tasks, :allow_destroy => true
44
+ end
45
+
46
+ <% form_for @project do |project_form| %>
47
+ <p>
48
+ <%= project_form.label :name, "Project:" %>
49
+ <%= project_form.text_field_with_auto_complete :name, {}, {:method => :get } %>
50
+ </p>
51
+ <% project_form.fields_for :tasks do |task_form| %>
52
+ <p>
53
+ <%= task_form.label :name, "Task:" %>
54
+ <%= task_form.text_field_with_auto_complete :name, {}, { :method => :get, :skip_style => true } %>
55
+ </p>
56
+ <% end %>
57
+ <% end %>
58
+
59
+
60
+ Rails 2.2 and earlier example:
61
+
62
+ <% for person in @group.people %>
63
+ <% fields_for "group[person_attributes][]", person do |person_form| %>
64
+ <p>
65
+ Person <%= person_form.label :name %><br/>
66
+ <%= person_form.text_field_with_auto_complete :name, {}, {:method => :get } %>
67
+ </p>
68
+ <% end %>
69
+ <% end %>
70
+
71
+ == Named scopes with auto_complete_for:
72
+
73
+ auto_complete_for now optionally accepts a block that is called with the item list and HTTP parameters
74
+ when the auto complete AJAX request is received. This block can be used to specify that a named scope
75
+ be used to generate a customized list of autocomplete options.
76
+
77
+ Example using anonymous scope:
78
+
79
+ auto_complete_for :some_model, :some_other_field do |items, params|
80
+ items.scoped( { :conditions => [ "a_third_field = ?", params['some_model']['a_third_field'] ] })
81
+ end
82
+
83
+ Example using named scope:
84
+
85
+ class Task < ActiveRecord::Base
86
+ belongs_to :project
87
+ named_scope :by_project,
88
+ lambda { |project_name| {
89
+ :include => :project,
90
+ :conditions => [ "projects.name = ?", project_name ]
91
+ } }
92
+ end
93
+
94
+ auto_complete_for :task, :name do | items, params |
95
+ items.by_project(params['project'])
96
+ end
97
+
98
+ == Autocomplete Scaffolding:
99
+
100
+ The "View Mapper" gem will generate scaffolding code that illustrates how to use
101
+ the standard Rails auto_complete plugin in a simple form, or the repeated_auto_complete
102
+ plugin/gem in a complex form.
103
+
104
+ See: {http://patshaughnessy.net/2009/10/1/auto_complete-scaffolding}[http://patshaughnessy.net/2009/10/1/auto_complete-scaffolding]
105
+
106
+ Or: {http://patshaughnessy.net/2009/11/25/scaffolding-for-auto-complete-on-a-complex-nested-form}[http://patshaughnessy.net/2009/11/25/scaffolding-for-auto-complete-on-a-complex-nested-form]
107
+
108
+ Copyright (c) 2009 [Pat Shaughnessy], released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -99,7 +99,7 @@ module AutoCompleteMacrosHelper
99
99
  def auto_complete_result(entries, field, phrase = nil)
100
100
  return unless entries
101
101
  items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : h(entry[field])) }
102
- content_tag("ul", items.uniq)
102
+ content_tag("ul", items.uniq.join)
103
103
  end
104
104
 
105
105
  # Wrapper for text_field with added AJAX autocompletion functionality.
@@ -5,22 +5,21 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{repeated_auto_complete}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pat Shaughnessy"]
12
- s.date = %q{2009-11-25}
12
+ s.date = %q{2010-02-10}
13
13
  s.description = %q{auto_complete plugin refactored to handle complex forms and named scopes}
14
14
  s.email = %q{pat@patshaughnessy.net}
15
15
  s.extra_rdoc_files = [
16
- "README"
16
+ "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
- "README",
20
+ "README.rdoc",
21
21
  "Rakefile",
22
22
  "VERSION",
23
- "init.rb",
24
23
  "lib/auto_complete.rb",
25
24
  "lib/auto_complete_form_builder_helper.rb",
26
25
  "lib/auto_complete_macros_helper.rb",
@@ -31,6 +31,12 @@ class AutoCompleteTest < ActionController::TestCase
31
31
  url << options[:action].to_s if options and options[:action]
32
32
  url
33
33
  end
34
+
35
+ class << self
36
+ def name
37
+ 'test_controller'
38
+ end
39
+ end
34
40
  end
35
41
  @controller = @controller.new
36
42
 
data/test/helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'active_record'
6
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
8
  require 'repeated_auto_complete'
9
- require File.join(File.dirname(__FILE__), '..', 'init')
9
+ require File.join(File.dirname(__FILE__), '..', 'rails', 'init')
10
10
 
11
11
  class Test::Unit::TestCase
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repeated_auto_complete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Shaughnessy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-25 00:00:00 -05:00
12
+ date: 2010-02-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,13 +20,12 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - README.rdoc
24
24
  files:
25
25
  - .gitignore
26
- - README
26
+ - README.rdoc
27
27
  - Rakefile
28
28
  - VERSION
29
- - init.rb
30
29
  - lib/auto_complete.rb
31
30
  - lib/auto_complete_form_builder_helper.rb
32
31
  - lib/auto_complete_macros_helper.rb
data/README DELETED
@@ -1,102 +0,0 @@
1
- Fork of the standard auto_complete plugin to support:
2
-
3
- 1. Creating auto complete text fields that can be repeated more than once a single form.
4
-
5
- 2. Using auto_complete_for with named scopes to display a customized list
6
- of autocomplete options.
7
-
8
- See: http://patshaughnessy.net/repeated_auto_complete for details.
9
-
10
-
11
- Repeated autocomplete text fields:
12
- ==================================
13
-
14
- A "text_field_with_auto_complete" method is made available to the form builder
15
- yielded by form_for and fields_for that:
16
- - Insures unique id's for <input> and <div> tags by inserting unique integers into their
17
- id attributes
18
- - Uses the object name from the surrounding call to form_for or fields_for so attribute
19
- mass assignment will work as usual
20
- - Works with the same server side controller method, auto_complete_for, as usual
21
- - Supports nested attributes in Rails 2.3
22
-
23
- form.text_field_with_auto_complete works the same as the original text_field_with_auto_complete macro,
24
- except it does not take the object as a parameter.
25
-
26
- Example with nested attributes using Rails 2.3 or later:
27
-
28
- class Project < ActiveRecord::Base
29
- has_many :tasks
30
- accepts_nested_attributes_for :tasks, :allow_destroy => true
31
- end
32
-
33
- <% form_for @project do |project_form| %>
34
- <p>
35
- <%= project_form.label :name, "Project:" %>
36
- <%= project_form.text_field_with_auto_complete :name, {}, {:method => :get } %>
37
- </p>
38
- <% project_form.fields_for :tasks do |task_form| %>
39
- <p>
40
- <%= task_form.label :name, "Task:" %>
41
- <%= task_form.text_field_with_auto_complete :name, {}, { :method => :get, :skip_style => true } %>
42
- </p>
43
- <% end %>
44
- <% end %>
45
-
46
-
47
- Rails 2.2 and earlier example:
48
-
49
- <% for person in @group.people %>
50
- <% fields_for "group[person_attributes][]", person do |person_form| %>
51
- <p>
52
- Person <%= person_form.label :name %><br/>
53
- <%= person_form.text_field_with_auto_complete :name, {}, {:method => :get } %>
54
- </p>
55
- <% end %>
56
- <% end %>
57
-
58
-
59
-
60
- Named scopes with auto_complete_for:
61
- ====================================
62
-
63
- auto_complete_for now optionally accepts a block that is called with the item list and HTTP parameters
64
- when the auto complete AJAX request is received. This block can be used to specify that a named scope
65
- be used to generate a customized list of autocomplete options.
66
-
67
- Example using anonymous scope:
68
-
69
- auto_complete_for :some_model, :some_other_field do |items, params|
70
- items.scoped( { :conditions => [ "a_third_field = ?", params['some_model']['a_third_field'] ] })
71
- end
72
-
73
-
74
-
75
- Example using named scope:
76
-
77
- class Task < ActiveRecord::Base
78
- belongs_to :project
79
- named_scope :by_project,
80
- lambda { |project_name| {
81
- :include => :project,
82
- :conditions => [ "projects.name = ?", project_name ]
83
- } }
84
- end
85
-
86
- auto_complete_for :task, :name do | items, params |
87
- items.by_project(params['project'])
88
- end
89
-
90
-
91
-
92
- Autocomplete Scaffolding:
93
- =========================
94
-
95
- The "View Mapper" gem will generate scaffolding code that illustrates how to use
96
- the standard Rails auto_complete plugin in a simple form, or the repeated_auto_complete
97
- plugin/gem in a complex form.
98
-
99
- See: http://pats
100
-
101
-
102
- Copyright (c) 2009 [Pat Shaughnessy], released under the MIT license
data/init.rb DELETED
@@ -1,3 +0,0 @@
1
- ActionController::Base.send :include, AutoComplete
2
- ActionController::Base.helper AutoCompleteMacrosHelper
3
- ActionView::Helpers::FormBuilder.send :include, AutoCompleteFormBuilderHelper