meta_search 0.9.9 → 0.9.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/VERSION +1 -1
- data/lib/meta_search.rb +2 -0
- data/lib/meta_search/helpers/form_helper.rb +2 -3
- data/lib/meta_search/locale/en.yml +23 -0
- data/lib/meta_search/model_compatibility.rb +24 -1
- data/lib/meta_search/searches/active_record.rb +21 -1
- data/meta_search.gemspec +50 -52
- data/test/helper.rb +1 -1
- data/test/locales/flanders.yml +11 -0
- data/test/test_view_helpers.rb +33 -0
- metadata +7 -7
- data/.gitignore +0 -21
- data/Gemfile +0 -3
- data/test/locales/en.yml +0 -36
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Changes since 0.9.9 (2010-11-15):
|
2
|
+
* Fix bug introduced by new polymorphic belongs_to association code in
|
3
|
+
honoring :url param to form_for
|
4
|
+
* Support localization of predicate text in labels
|
5
|
+
|
1
6
|
Changes since 0.9.8 (2010-10-20):
|
2
7
|
* ARel 2.x and Rails 3.0.2 compatability
|
3
8
|
* sort_link uses search_key from builder. Search_key defaults to "search"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.9
|
1
|
+
0.9.9.1
|
data/lib/meta_search.rb
CHANGED
@@ -45,6 +45,8 @@ require 'meta_search/join_dependency'
|
|
45
45
|
require 'meta_search/searches/active_record'
|
46
46
|
require 'meta_search/helpers'
|
47
47
|
|
48
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'meta_search', 'locale', '*.yml')]
|
49
|
+
|
48
50
|
ActiveRecord::Associations::ClassMethods::JoinDependency.send(:include, MetaSearch::JoinDependency)
|
49
51
|
ActiveRecord::Base.send(:include, MetaSearch::Searches::ActiveRecord)
|
50
52
|
ActionView::Helpers::FormBuilder.send(:include, MetaSearch::Helpers::FormBuilder)
|
@@ -4,9 +4,9 @@ module MetaSearch
|
|
4
4
|
def apply_form_for_options!(object_or_array, options)
|
5
5
|
if object_or_array.is_a?(MetaSearch::Builder)
|
6
6
|
builder = object_or_array
|
7
|
-
url
|
7
|
+
options[:url] ||= polymorphic_path(object_or_array.base)
|
8
8
|
elsif object_or_array.is_a?(Array) && (builder = object_or_array.detect {|o| o.is_a?(MetaSearch::Builder)})
|
9
|
-
url
|
9
|
+
options[:url] ||= polymorphic_path(object_or_array.map {|o| o.is_a?(MetaSearch::Builder) ? o.base : o})
|
10
10
|
else
|
11
11
|
super and return
|
12
12
|
end
|
@@ -17,7 +17,6 @@ module MetaSearch
|
|
17
17
|
:method => :get }
|
18
18
|
options[:html] ||= {}
|
19
19
|
options[:html].reverse_merge!(html_options)
|
20
|
-
options[:url] ||= url
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
en:
|
2
|
+
meta_search:
|
3
|
+
predicates:
|
4
|
+
equals: "%{attribute} equals"
|
5
|
+
does_not_equal: "%{attribute} doesn't equal"
|
6
|
+
contains: "%{attribute} contains"
|
7
|
+
does_not_contain: "%{attribute} doesn't contain"
|
8
|
+
starts_with: "%{attribute} starts with"
|
9
|
+
does_not_start_with: "%{attribute} doesn't start with"
|
10
|
+
ends_with: "%{attribute} ends with"
|
11
|
+
does_not_end_with: "%{attribute} doesn't end with"
|
12
|
+
greater_than: "%{attribute} greater than"
|
13
|
+
less_than: "%{attribute} less than"
|
14
|
+
greater_than_or_equal_to: "%{attribute} greater than or equal to"
|
15
|
+
less_than_or_equal_to: "%{attribute} less than or equal to"
|
16
|
+
in: "%{attribute} is one of"
|
17
|
+
not_in: "%{attribute} isn't one of"
|
18
|
+
is_true: "%{attribute} is true"
|
19
|
+
is_false: "%{attribute} is false"
|
20
|
+
is_present: "%{attribute} is present"
|
21
|
+
is_blank: "%{attribute} is blank"
|
22
|
+
is_null: "%{attribute} is null"
|
23
|
+
is_not_null: "%{attribute} isn't null"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'meta_search/utility'
|
2
|
+
|
1
3
|
module MetaSearch
|
2
4
|
|
3
5
|
module ModelCompatibility
|
@@ -24,7 +26,7 @@ module MetaSearch
|
|
24
26
|
end
|
25
27
|
|
26
28
|
class Name < String
|
27
|
-
attr_reader :singular, :plural, :element, :collection, :partial_path, :human, :param_key, :route_key
|
29
|
+
attr_reader :singular, :plural, :element, :collection, :partial_path, :human, :param_key, :route_key, :i18n_key
|
28
30
|
alias_method :cache_key, :collection
|
29
31
|
|
30
32
|
def initialize
|
@@ -37,13 +39,34 @@ module MetaSearch
|
|
37
39
|
@partial_path = "#{@collection}/#{@element}".freeze
|
38
40
|
@param_key = "search".freeze
|
39
41
|
@route_key = "searches".freeze
|
42
|
+
@i18n_key = :meta_search
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
module ClassMethods
|
47
|
+
include Utility
|
48
|
+
|
44
49
|
def model_name
|
45
50
|
@_model_name ||= Name.new
|
46
51
|
end
|
52
|
+
|
53
|
+
def human_attribute_name(attribute, options = {})
|
54
|
+
method_name = preferred_method_name(attribute)
|
55
|
+
|
56
|
+
defaults = [:"meta_search.attributes.#{klass.model_name.i18n_key}.#{method_name || attribute}"]
|
57
|
+
|
58
|
+
if method_name
|
59
|
+
predicate = Where.get(method_name)[:name]
|
60
|
+
predicate_attribute = method_name.sub(/_#{predicate}=?$/, '')
|
61
|
+
defaults << :"meta_search.predicates.#{predicate}"
|
62
|
+
end
|
63
|
+
|
64
|
+
defaults << options.delete(:default) if options[:default]
|
65
|
+
defaults << attribute.to_s.humanize
|
66
|
+
|
67
|
+
options.reverse_merge! :count => 1, :default => defaults, :attribute => klass.human_attribute_name(predicate_attribute)
|
68
|
+
I18n.translate(defaults.shift, options)
|
69
|
+
end
|
47
70
|
end
|
48
71
|
|
49
72
|
end
|
@@ -4,6 +4,7 @@ require 'meta_search/builder'
|
|
4
4
|
|
5
5
|
module MetaSearch
|
6
6
|
module Searches
|
7
|
+
|
7
8
|
module ActiveRecord
|
8
9
|
|
9
10
|
def self.included(base)
|
@@ -27,7 +28,7 @@ module MetaSearch
|
|
27
28
|
# in that it doesn't actually query the database until you do something that
|
28
29
|
# requires it to do so.
|
29
30
|
def metasearch(params = nil, opts = nil)
|
30
|
-
builder =
|
31
|
+
builder = Searches.for(self).new(self, opts || {})
|
31
32
|
builder.build(params || {})
|
32
33
|
end
|
33
34
|
|
@@ -92,5 +93,24 @@ module MetaSearch
|
|
92
93
|
alias_method :search_method, :search_methods
|
93
94
|
end
|
94
95
|
end
|
96
|
+
|
97
|
+
def self.for(klass)
|
98
|
+
DISPATCH[klass]
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
DISPATCH = Hash.new do |hash, klass|
|
104
|
+
class_name = klass.name.gsub('::', '_')
|
105
|
+
hash[klass] = module_eval <<-RUBY_EVAL
|
106
|
+
class #{class_name} < MetaSearch::Builder
|
107
|
+
def self.klass
|
108
|
+
::#{klass}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#{class_name}
|
113
|
+
RUBY_EVAL
|
114
|
+
end
|
95
115
|
end
|
96
116
|
end
|
data/meta_search.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{meta_search}
|
8
|
-
s.version = "0.9.9"
|
8
|
+
s.version = "0.9.9.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ernie Miller"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-16}
|
13
13
|
s.description = %q{
|
14
14
|
Allows simple search forms to be created against an AR3 model
|
15
15
|
and its associations, has useful view helpers for sort links
|
@@ -18,49 +18,48 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.email = %q{ernie@metautonomo.us}
|
19
19
|
s.extra_rdoc_files = [
|
20
20
|
"LICENSE",
|
21
|
-
|
21
|
+
"README.rdoc"
|
22
22
|
]
|
23
23
|
s.files = [
|
24
24
|
".document",
|
25
|
-
|
26
|
-
|
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
|
-
"test/test_view_helpers.rb"
|
25
|
+
".gitmodules",
|
26
|
+
"CHANGELOG",
|
27
|
+
"LICENSE",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"lib/meta_search.rb",
|
32
|
+
"lib/meta_search/builder.rb",
|
33
|
+
"lib/meta_search/exceptions.rb",
|
34
|
+
"lib/meta_search/helpers.rb",
|
35
|
+
"lib/meta_search/helpers/form_builder.rb",
|
36
|
+
"lib/meta_search/helpers/form_helper.rb",
|
37
|
+
"lib/meta_search/helpers/url_helper.rb",
|
38
|
+
"lib/meta_search/join_dependency.rb",
|
39
|
+
"lib/meta_search/locale/en.yml",
|
40
|
+
"lib/meta_search/method.rb",
|
41
|
+
"lib/meta_search/model_compatibility.rb",
|
42
|
+
"lib/meta_search/searches/active_record.rb",
|
43
|
+
"lib/meta_search/utility.rb",
|
44
|
+
"lib/meta_search/where.rb",
|
45
|
+
"meta_search.gemspec",
|
46
|
+
"test/fixtures/companies.yml",
|
47
|
+
"test/fixtures/company.rb",
|
48
|
+
"test/fixtures/data_type.rb",
|
49
|
+
"test/fixtures/data_types.yml",
|
50
|
+
"test/fixtures/developer.rb",
|
51
|
+
"test/fixtures/developers.yml",
|
52
|
+
"test/fixtures/developers_projects.yml",
|
53
|
+
"test/fixtures/note.rb",
|
54
|
+
"test/fixtures/notes.yml",
|
55
|
+
"test/fixtures/project.rb",
|
56
|
+
"test/fixtures/projects.yml",
|
57
|
+
"test/fixtures/schema.rb",
|
58
|
+
"test/helper.rb",
|
59
|
+
"test/locales/es.yml",
|
60
|
+
"test/locales/flanders.yml",
|
61
|
+
"test/test_search.rb",
|
62
|
+
"test/test_view_helpers.rb"
|
64
63
|
]
|
65
64
|
s.homepage = %q{http://metautonomo.us/projects/metasearch/}
|
66
65
|
s.post_install_message = %q{
|
@@ -71,20 +70,19 @@ you're feeling especially appreciative. It'd help me justify this
|
|
71
70
|
"open source" stuff to my lovely wife. :)
|
72
71
|
|
73
72
|
}
|
74
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
75
73
|
s.require_paths = ["lib"]
|
76
74
|
s.rubygems_version = %q{1.3.7}
|
77
75
|
s.summary = %q{Object-based searching (and more) for simply creating search forms.}
|
78
76
|
s.test_files = [
|
79
77
|
"test/fixtures/company.rb",
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
78
|
+
"test/fixtures/data_type.rb",
|
79
|
+
"test/fixtures/developer.rb",
|
80
|
+
"test/fixtures/note.rb",
|
81
|
+
"test/fixtures/project.rb",
|
82
|
+
"test/fixtures/schema.rb",
|
83
|
+
"test/helper.rb",
|
84
|
+
"test/test_search.rb",
|
85
|
+
"test/test_view_helpers.rb"
|
88
86
|
]
|
89
87
|
|
90
88
|
if s.respond_to? :specification_version then
|
data/test/helper.rb
CHANGED
@@ -25,7 +25,7 @@ end
|
|
25
25
|
|
26
26
|
Fixtures.create_fixtures(FIXTURES_PATH, ActiveRecord::Base.connection.tables)
|
27
27
|
|
28
|
-
I18n.load_path
|
28
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locales', '*.yml')]
|
29
29
|
|
30
30
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
31
31
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
data/test/test_view_helpers.rb
CHANGED
@@ -32,6 +32,39 @@ class TestViewHelpers < ActionView::TestCase
|
|
32
32
|
@controller = @controller.new
|
33
33
|
end
|
34
34
|
|
35
|
+
context "A search against Company and a search against Developer" do
|
36
|
+
setup do
|
37
|
+
@s1 = Company.search
|
38
|
+
@s2 = Developer.search
|
39
|
+
form_for @s1 do |f|
|
40
|
+
@f1 = f
|
41
|
+
end
|
42
|
+
|
43
|
+
form_for @s2 do |f|
|
44
|
+
@f2 = f
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
should "use the default localization for predicates" do
|
49
|
+
assert_match /Name isn't null/, @f1.label(:name_is_not_null)
|
50
|
+
end
|
51
|
+
|
52
|
+
context "in the Flanders locale" do
|
53
|
+
setup do
|
54
|
+
I18n.locale = :flanders
|
55
|
+
end
|
56
|
+
|
57
|
+
teardown do
|
58
|
+
I18n.locale = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
should "localize according to their bases" do
|
62
|
+
assert_match /Company name-diddly contains-diddly/, @f1.label(:name_contains)
|
63
|
+
assert_match /Developer name-diddly contains-aroonie/, @f2.label(:name_like)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
35
68
|
context "A previously-filled search form" do
|
36
69
|
setup do
|
37
70
|
@s = Company.search
|
metadata
CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 9
|
8
8
|
- 9
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.9.9.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ernie Miller
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-16 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -101,10 +102,8 @@ extra_rdoc_files:
|
|
101
102
|
- README.rdoc
|
102
103
|
files:
|
103
104
|
- .document
|
104
|
-
- .gitignore
|
105
105
|
- .gitmodules
|
106
106
|
- CHANGELOG
|
107
|
-
- Gemfile
|
108
107
|
- LICENSE
|
109
108
|
- README.rdoc
|
110
109
|
- Rakefile
|
@@ -117,6 +116,7 @@ files:
|
|
117
116
|
- lib/meta_search/helpers/form_helper.rb
|
118
117
|
- lib/meta_search/helpers/url_helper.rb
|
119
118
|
- lib/meta_search/join_dependency.rb
|
119
|
+
- lib/meta_search/locale/en.yml
|
120
120
|
- lib/meta_search/method.rb
|
121
121
|
- lib/meta_search/model_compatibility.rb
|
122
122
|
- lib/meta_search/searches/active_record.rb
|
@@ -136,8 +136,8 @@ files:
|
|
136
136
|
- test/fixtures/projects.yml
|
137
137
|
- test/fixtures/schema.rb
|
138
138
|
- test/helper.rb
|
139
|
-
- test/locales/en.yml
|
140
139
|
- test/locales/es.yml
|
140
|
+
- test/locales/flanders.yml
|
141
141
|
- test/test_search.rb
|
142
142
|
- test/test_view_helpers.rb
|
143
143
|
has_rdoc: true
|
@@ -150,8 +150,8 @@ post_install_message: "\n\
|
|
150
150
|
walkthrough of MetaSearch's features, and click the donate button if\n\
|
151
151
|
you're feeling especially appreciative. It'd help me justify this\n\
|
152
152
|
\"open source\" stuff to my lovely wife. :)\n\n"
|
153
|
-
rdoc_options:
|
154
|
-
|
153
|
+
rdoc_options: []
|
154
|
+
|
155
155
|
require_paths:
|
156
156
|
- lib
|
157
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/test/locales/en.yml
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
# Use the strftime parameters for formats.
|
5
|
-
# When no format has been given, it uses default.
|
6
|
-
# You can provide other formats here if you like!
|
7
|
-
default: "%Y-%m-%d"
|
8
|
-
short: "%b %d"
|
9
|
-
long: "%B %d, %Y"
|
10
|
-
|
11
|
-
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
12
|
-
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
13
|
-
|
14
|
-
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
15
|
-
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
16
|
-
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
17
|
-
# Used in date_select and datetime_select.
|
18
|
-
order:
|
19
|
-
- :year
|
20
|
-
- :month
|
21
|
-
- :day
|
22
|
-
|
23
|
-
time:
|
24
|
-
formats:
|
25
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
26
|
-
short: "%d %b %H:%M"
|
27
|
-
long: "%B %d, %Y %H:%M"
|
28
|
-
am: "am"
|
29
|
-
pm: "pm"
|
30
|
-
|
31
|
-
# Used in array.to_sentence.
|
32
|
-
support:
|
33
|
-
array:
|
34
|
-
words_connector: ", "
|
35
|
-
two_words_connector: " and "
|
36
|
-
last_word_connector: ", and "
|