auto_complete 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +37 -0
- data/Rakefile +8 -0
- data/app/helpers/auto_complete_macros_helper.rb +145 -0
- data/auto_complete.gemspec +25 -0
- data/lib/auto_complete.rb +13 -0
- data/lib/auto_complete/class_methods.rb +49 -0
- data/lib/auto_complete/version.rb +3 -0
- data/test/auto_complete_test.rb +55 -0
- data/test/dummy/.gitignore +15 -0
- data/test/dummy/Gemfile +38 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/images/rails.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +16 -0
- data/test/dummy/app/assets/javascripts/example.js.coffee +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/swfs/example.swf +0 -0
- data/test/dummy/app/assets/swfs/source/Example.as +26 -0
- data/test/dummy/app/assets/swfs/source/example.fla +0 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/application/example.html.erb +7 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +67 -0
- data/test/dummy/config/boot.rb +6 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +59 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/robots.txt +5 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/.gitkeep +0 -0
- data/test/dummy/test/functional/.gitkeep +0 -0
- data/test/dummy/test/integration/.gitkeep +0 -0
- data/test/dummy/test/test_helper.rb +13 -0
- data/test/dummy/test/unit/.gitkeep +0 -0
- data/test/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/dummy/vendor/plugins/.gitkeep +0 -0
- data/test/test_helper.rb +19 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c07000c74780498b78972c3f1079bb09c62d5a1
|
4
|
+
data.tar.gz: 4f957c335e169222ed8d1a9494215884382ddd15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dbd5465d5ce60dcd7b190e6a4f76fe3610864db3b7308252c91f2203ece61fbdf5abd2749aaf20ce3f742fb9118ce66551c59a392b05da2d1ec173a6d045261
|
7
|
+
data.tar.gz: a8a2904e5709daa65f17341084b7722a3849c1d1491387e1862b0f55cb00be87f7259b7896b9b0acce9e2ebb1cb10238fccdd9c8b0b74c25ce19fd8711df12b6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2007 David Heinemeier Hansson (original code)
|
2
|
+
Copyright (c) 2013 Marc-Andre Lafortune (gem)
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# AutoComplete
|
2
|
+
|
3
|
+
Gem port of the legacy auto_complete plugin for Rails 3+
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:Example:
|
8
|
+
|
9
|
+
# Controller
|
10
|
+
class BlogController < ApplicationController
|
11
|
+
auto_complete_for :post, :title
|
12
|
+
end
|
13
|
+
|
14
|
+
# View
|
15
|
+
<%= text_field_with_auto_complete :post, title %>
|
16
|
+
|
17
|
+
By default, auto_complete_for limits the results to 10 entries,
|
18
|
+
and sorts by the given field.
|
19
|
+
|
20
|
+
auto_complete_for takes a third parameter, an options hash to
|
21
|
+
the find method used to search for the records:
|
22
|
+
|
23
|
+
auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
|
24
|
+
|
25
|
+
For more examples, see script.aculo.us:
|
26
|
+
* http://script.aculo.us/demos/ajax/autocompleter
|
27
|
+
* http://script.aculo.us/demos/ajax/autocompleter_customized
|
28
|
+
|
29
|
+
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
module AutoCompleteMacrosHelper
|
2
|
+
# Adds AJAX autocomplete functionality to the text input field with the
|
3
|
+
# DOM ID specified by +field_id+.
|
4
|
+
#
|
5
|
+
# This function expects that the called action returns an HTML <ul> list,
|
6
|
+
# or nothing if no entries should be displayed for autocompletion.
|
7
|
+
#
|
8
|
+
# You'll probably want to turn the browser's built-in autocompletion off,
|
9
|
+
# so be sure to include an <tt>autocomplete="off"</tt> attribute with your text
|
10
|
+
# input field.
|
11
|
+
#
|
12
|
+
# The autocompleter object is assigned to a Javascript variable named <tt>field_id</tt>_auto_completer.
|
13
|
+
# This object is useful if you for example want to trigger the auto-complete suggestions through
|
14
|
+
# other means than user input (for that specific case, call the <tt>activate</tt> method on that object).
|
15
|
+
#
|
16
|
+
# Required +options+ are:
|
17
|
+
# <tt>:url</tt>:: URL to call for autocompletion results
|
18
|
+
# in url_for format.
|
19
|
+
#
|
20
|
+
# Addtional +options+ are:
|
21
|
+
# <tt>:update</tt>:: Specifies the DOM ID of the element whose
|
22
|
+
# innerHTML should be updated with the autocomplete
|
23
|
+
# entries returned by the AJAX request.
|
24
|
+
# Defaults to <tt>field_id</tt> + '_auto_complete'
|
25
|
+
# <tt>:with</tt>:: A JavaScript expression specifying the
|
26
|
+
# parameters for the XMLHttpRequest. This defaults
|
27
|
+
# to 'fieldname=value'.
|
28
|
+
# <tt>:frequency</tt>:: Determines the time to wait after the last keystroke
|
29
|
+
# for the AJAX request to be initiated.
|
30
|
+
# <tt>:indicator</tt>:: Specifies the DOM ID of an element which will be
|
31
|
+
# displayed while autocomplete is running.
|
32
|
+
# <tt>:tokens</tt>:: A string or an array of strings containing
|
33
|
+
# separator tokens for tokenized incremental
|
34
|
+
# autocompletion. Example: <tt>:tokens => ','</tt> would
|
35
|
+
# allow multiple autocompletion entries, separated
|
36
|
+
# by commas.
|
37
|
+
# <tt>:min_chars</tt>:: The minimum number of characters that should be
|
38
|
+
# in the input field before an Ajax call is made
|
39
|
+
# to the server.
|
40
|
+
# <tt>:on_hide</tt>:: A Javascript expression that is called when the
|
41
|
+
# autocompletion div is hidden. The expression
|
42
|
+
# should take two variables: element and update.
|
43
|
+
# Element is a DOM element for the field, update
|
44
|
+
# is a DOM element for the div from which the
|
45
|
+
# innerHTML is replaced.
|
46
|
+
# <tt>:on_show</tt>:: Like on_hide, only now the expression is called
|
47
|
+
# then the div is shown.
|
48
|
+
# <tt>:after_update_element</tt>:: A Javascript expression that is called when the
|
49
|
+
# user has selected one of the proposed values.
|
50
|
+
# The expression should take two variables: element and value.
|
51
|
+
# Element is a DOM element for the field, value
|
52
|
+
# is the value selected by the user.
|
53
|
+
# <tt>:select</tt>:: Pick the class of the element from which the value for
|
54
|
+
# insertion should be extracted. If this is not specified,
|
55
|
+
# the entire element is used.
|
56
|
+
# <tt>:method</tt>:: Specifies the HTTP verb to use when the autocompletion
|
57
|
+
# request is made. Defaults to POST.
|
58
|
+
def auto_complete_field(field_id, options = {})
|
59
|
+
function = "var #{field_id}_auto_completer = new Ajax.Autocompleter("
|
60
|
+
function << "'#{field_id}', "
|
61
|
+
function << "'" + (options[:update] || "#{field_id}_auto_complete") + "', "
|
62
|
+
function << "'#{url_for(options[:url])}'"
|
63
|
+
|
64
|
+
js_options = {}
|
65
|
+
js_options[:tokens] = array_or_string_for_javascript(options[:tokens]) if options[:tokens]
|
66
|
+
js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with]
|
67
|
+
js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator]
|
68
|
+
js_options[:select] = "'#{options[:select]}'" if options[:select]
|
69
|
+
js_options[:paramName] = "'#{options[:param_name]}'" if options[:param_name]
|
70
|
+
js_options[:frequency] = "#{options[:frequency]}" if options[:frequency]
|
71
|
+
js_options[:method] = "'#{options[:method].to_s}'" if options[:method]
|
72
|
+
|
73
|
+
{ :after_update_element => :afterUpdateElement,
|
74
|
+
:on_show => :onShow, :on_hide => :onHide, :min_chars => :minChars }.each do |k,v|
|
75
|
+
js_options[v] = options[k] if options[k]
|
76
|
+
end
|
77
|
+
|
78
|
+
function << (', ' + options_for_javascript(js_options) + ')')
|
79
|
+
|
80
|
+
javascript_tag(function)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Use this method in your view to generate a return for the AJAX autocomplete requests.
|
84
|
+
#
|
85
|
+
# Example action:
|
86
|
+
#
|
87
|
+
# def auto_complete_for_item_title
|
88
|
+
# @items = Item.find(:all,
|
89
|
+
# :conditions => [ 'LOWER(description) LIKE ?',
|
90
|
+
# '%' + request.raw_post.downcase + '%' ])
|
91
|
+
# render :inline => "<%= auto_complete_result(@items, 'description') %>"
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# The auto_complete_result can of course also be called from a view belonging to the
|
95
|
+
# auto_complete action if you need to decorate it further.
|
96
|
+
def auto_complete_result(entries, field, phrase = nil)
|
97
|
+
return unless entries
|
98
|
+
items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : entry[field]) }
|
99
|
+
content_tag("ul", safe_join(items.uniq))
|
100
|
+
end
|
101
|
+
|
102
|
+
# Wrapper for text_field with added AJAX autocompletion functionality.
|
103
|
+
#
|
104
|
+
# In your controller, you'll need to define an action called
|
105
|
+
# auto_complete_for to respond the AJAX calls,
|
106
|
+
#
|
107
|
+
def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
|
108
|
+
(completion_options[:skip_style] ? "".html_safe : auto_complete_stylesheet) +
|
109
|
+
text_field(object, method, tag_options) +
|
110
|
+
content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") +
|
111
|
+
auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
STYLE = <<-EOT.html_safe.freeze
|
116
|
+
div.auto_complete {
|
117
|
+
width: 350px;
|
118
|
+
background: #fff;
|
119
|
+
}
|
120
|
+
div.auto_complete ul {
|
121
|
+
border:1px solid #888;
|
122
|
+
margin:0;
|
123
|
+
padding:0;
|
124
|
+
width:100%;
|
125
|
+
list-style-type:none;
|
126
|
+
}
|
127
|
+
div.auto_complete ul li {
|
128
|
+
margin:0;
|
129
|
+
padding:3px;
|
130
|
+
}
|
131
|
+
div.auto_complete ul li.selected {
|
132
|
+
background-color: #ffb;
|
133
|
+
}
|
134
|
+
div.auto_complete ul strong.highlight {
|
135
|
+
color: #800;
|
136
|
+
margin:0;
|
137
|
+
padding:0;
|
138
|
+
}
|
139
|
+
EOT
|
140
|
+
|
141
|
+
def auto_complete_stylesheet
|
142
|
+
content_tag('style', STYLE, :type => Mime::CSS)
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'auto_complete/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "auto_complete"
|
8
|
+
spec.version = AutoComplete::VERSION
|
9
|
+
spec.authors = ["David Heinemeier Hansson, Marc-André Lafortune"]
|
10
|
+
spec.email = ["github@marc-andre.ca"]
|
11
|
+
spec.description = %q{Gem for the legacy auto_complete plugin}
|
12
|
+
spec.summary = %q{Gem for the legacy auto_complete plugin}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "auto_complete/version"
|
2
|
+
require "auto_complete/class_methods"
|
3
|
+
|
4
|
+
module AutoComplete
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
# Thanks to http://robots.thoughtbot.com/post/159805560/tips-for-writing-your-own-rails-engine for:
|
7
|
+
config.to_prepare do
|
8
|
+
ActionView::Helpers.send :include, AutoCompleteMacrosHelper
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionController::Base.send :include, AutoComplete
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module AutoComplete
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# # Controller
|
11
|
+
# class BlogController < ApplicationController
|
12
|
+
# auto_complete_for :post, :title
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # View
|
16
|
+
# <%= text_field_with_auto_complete :post, title %>
|
17
|
+
#
|
18
|
+
# By default, auto_complete_for limits the results to 10 entries,
|
19
|
+
# and sorts by the given field.
|
20
|
+
#
|
21
|
+
# auto_complete_for takes a third parameter, an options hash to
|
22
|
+
# the find method used to search for the records:
|
23
|
+
#
|
24
|
+
# auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
|
25
|
+
#
|
26
|
+
# For help on defining text input fields with autocompletion,
|
27
|
+
# see ActionView::Helpers::JavaScriptHelper.
|
28
|
+
#
|
29
|
+
# For more examples, see script.aculo.us:
|
30
|
+
# * http://script.aculo.us/demos/ajax/autocompleter
|
31
|
+
# * http://script.aculo.us/demos/ajax/autocompleter_customized
|
32
|
+
module ClassMethods
|
33
|
+
def auto_complete_for(object, method, options = {})
|
34
|
+
define_method("auto_complete_for_#{object}_#{method}") do
|
35
|
+
table = object.to_s.camelize.constantize.table_name
|
36
|
+
|
37
|
+
find_options = {
|
38
|
+
:conditions => [ "LOWER(#{table}.#{method}) LIKE (?)", '%' + params[object][method].downcase + '%' ],
|
39
|
+
:order => "#{table}.#{method} ASC",
|
40
|
+
:limit => 10 }.merge!(options)
|
41
|
+
|
42
|
+
@items = object.to_s.camelize.constantize.find(:all, find_options)
|
43
|
+
|
44
|
+
render :inline => "<%= auto_complete_result @items, '#{method}' %>"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
|
3
|
+
class AutoCompleteTest < ActionView::TestCase
|
4
|
+
def assert_dom_equal(expected, actual)
|
5
|
+
super
|
6
|
+
assert_equal true, actual.html_safe?
|
7
|
+
end
|
8
|
+
|
9
|
+
def url_for(opt)
|
10
|
+
"http://www.example.com/#{opt[:action]}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_auto_complete_field
|
14
|
+
#stub!(:url_for).and_return("/path")
|
15
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})\n//]]>\n</script>),
|
16
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" });
|
17
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})\n//]]>\n</script>),
|
18
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
|
19
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})\n//]]>\n</script>),
|
20
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
|
21
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {minChars:3})\n//]]>\n</script>),
|
22
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3);
|
23
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){alert('me');}})\n//]]>\n</script>),
|
24
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){alert('me');}");
|
25
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {frequency:2})\n//]]>\n</script>),
|
26
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :frequency => 2);
|
27
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {afterUpdateElement:function(element,value){alert('You have chosen: '+value)}})\n//]]>\n</script>),
|
28
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" },
|
29
|
+
:after_update_element => "function(element,value){alert('You have chosen: '+value)}");
|
30
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {paramName:'huidriwusch'})\n//]]>\n</script>),
|
31
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :param_name => 'huidriwusch');
|
32
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {method:'get'})\n//]]>\n</script>),
|
33
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :method => :get);
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_auto_complete_result
|
37
|
+
result = [ { :title => 'test1' }, { :title => 'test2' } ]
|
38
|
+
assert_dom_equal %(<ul><li>test1</li><li>test2</li></ul>),
|
39
|
+
auto_complete_result(result, :title)
|
40
|
+
assert_dom_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
|
41
|
+
auto_complete_result(result, :title, "est")
|
42
|
+
|
43
|
+
resultuniq = [ { :title => 'test1' }, { :title => 'test1' } ]
|
44
|
+
assert_dom_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li></ul>),
|
45
|
+
auto_complete_result(resultuniq, :title, "est")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_text_field_with_auto_complete
|
49
|
+
assert_match %(<style type="text/css">),
|
50
|
+
text_field_with_auto_complete(:message, :recipient)
|
51
|
+
|
52
|
+
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\nvar message_recipient_auto_completer = new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})\n//]]>\n</script>),
|
53
|
+
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/test/dummy/Gemfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.2.6'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
# gem 'sqlite3'
|
9
|
+
|
10
|
+
# Gems used only for assets and not required
|
11
|
+
# in production environments by default.
|
12
|
+
group :assets do
|
13
|
+
gem 'sass-rails', '~> 3.2.3'
|
14
|
+
gem 'coffee-rails', '~> 3.2.1'
|
15
|
+
|
16
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
17
|
+
# gem 'therubyracer', :platforms => :ruby
|
18
|
+
|
19
|
+
gem 'uglifier', '>= 1.0.3'
|
20
|
+
end
|
21
|
+
|
22
|
+
gem 'jquery-rails'
|
23
|
+
|
24
|
+
gem 'auto_complete', :path => "../.."
|
25
|
+
# To use ActiveModel has_secure_password
|
26
|
+
# gem 'bcrypt-ruby', '~> 3.0.0'
|
27
|
+
|
28
|
+
# To use Jbuilder templates for JSON
|
29
|
+
# gem 'jbuilder'
|
30
|
+
|
31
|
+
# Use unicorn as the app server
|
32
|
+
# gem 'unicorn'
|
33
|
+
|
34
|
+
# Deploy with Capistrano
|
35
|
+
# gem 'capistrano'
|
36
|
+
|
37
|
+
# To use debugger
|
38
|
+
# gem 'debugger'
|