searchify 0.0.1 → 0.0.2
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/README.md +8 -0
- data/app/controllers/searchify/searchify_controller.rb +3 -5
- data/app/helpers/searchify/searchify_helper.rb +4 -4
- data/lib/searchify.rb +1 -0
- data/lib/searchify/controller.rb +17 -0
- data/lib/searchify/engine.rb +2 -0
- data/lib/searchify/version.rb +1 -1
- metadata +8 -9
- data/app/views/layouts/searchify/application.html.erb +0 -14
- data/app/views/searchify/searchify/search.html.erb +0 -2
data/README.md
CHANGED
@@ -57,6 +57,14 @@ Searchify can also be used in a form. For example, let's say that a post belongs
|
|
57
57
|
|
58
58
|
Searchify will include a `user_id` field in your form, which will be automatically populated.
|
59
59
|
|
60
|
+
#### Scopes
|
61
|
+
|
62
|
+
Searchify is scopes aware. Let's say you are here:
|
63
|
+
|
64
|
+
`/posts?created_by=3`
|
65
|
+
|
66
|
+
Assuming your `Post` model responds to the `created_by` method, it will be included in the search.
|
67
|
+
|
60
68
|
#### Search stategies
|
61
69
|
|
62
70
|
By default, Searchify does a case insensitive search on `name`, `title` and `abbreviation` fields of your models, if they exist. You can of course specify
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Searchify
|
2
|
-
class SearchifyController <
|
2
|
+
class SearchifyController < ::ApplicationController
|
3
3
|
|
4
4
|
respond_to :js
|
5
5
|
|
@@ -14,16 +14,14 @@ module Searchify
|
|
14
14
|
search_term = params[:term]
|
15
15
|
search_keyword = extract_search_key(resource_class)
|
16
16
|
|
17
|
-
scopes = params.except("controller", "action", "format", "collection", "term", "page")
|
18
|
-
|
19
17
|
collection = if resource_class.respond_to?(:search_strategy)
|
20
|
-
resource_class.search_strategy(search_term,
|
18
|
+
resource_class.search_strategy(search_term, current_scopes)
|
21
19
|
else
|
22
20
|
columns = DEFAULT_COLUMNS & resource_class.column_names
|
23
21
|
|
24
22
|
scoped = resource_class.where( columns.map{ |c| "(#{c} #{search_keyword} :term)" }.join(' OR '), :term => "%#{search_term}%")
|
25
23
|
|
26
|
-
|
24
|
+
searchify_scopes.each do |key, value|
|
27
25
|
scoped = scoped.send(key, value) if resource_class.respond_to?(key)
|
28
26
|
end
|
29
27
|
|
@@ -4,9 +4,9 @@ module Searchify
|
|
4
4
|
options = args.extract_options!
|
5
5
|
|
6
6
|
collection = options[:collection] || args.shift || extract_collection
|
7
|
-
search_url = options[:search_url] || extract_search_url(collection)
|
7
|
+
search_url = options[:search_url] || extract_search_url(collection, searchify_scopes)
|
8
8
|
select_url = options[:select_url] || extract_select_url
|
9
|
-
|
9
|
+
|
10
10
|
text_field_tag(:searchify, nil, :class => :searchify, :data => {:'select-url' => select_url, :'search-url' => search_url})
|
11
11
|
end
|
12
12
|
|
@@ -20,8 +20,8 @@ module Searchify
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def extract_search_url(collection)
|
24
|
-
"/searchify/search/#{collection}.json"
|
23
|
+
def extract_search_url(collection, scopes)
|
24
|
+
"/searchify/search/#{collection}.json?" + scopes.map{ |k,v| "#{k}=#{v}" }.join('&')
|
25
25
|
end
|
26
26
|
|
27
27
|
def extract_select_url
|
data/lib/searchify.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Searchify
|
2
|
+
module Controller
|
3
|
+
SCOPE_EXCLUSION = %w( controller action format collection term page )
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
include InstanceMethods
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def searchify_scopes
|
13
|
+
params.except(*SCOPE_EXCLUSION)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/searchify/engine.rb
CHANGED
@@ -3,6 +3,8 @@ module Searchify
|
|
3
3
|
isolate_namespace Searchify
|
4
4
|
|
5
5
|
initializer "extend Controller with Searchify helpers" do |app|
|
6
|
+
ActionController::Base.send :include, Searchify::Controller
|
7
|
+
ActionController::Base.helper_method :searchify_scopes
|
6
8
|
ActionController::Base.helper Searchify::SearchifyHelper
|
7
9
|
end
|
8
10
|
end
|
data/lib/searchify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-13 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &21309620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21309620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jquery-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &21309180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *21309180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &21308660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *21308660
|
47
47
|
description: Searchify provides a quick way to search your collections.
|
48
48
|
email:
|
49
49
|
- christ.blais@gmail.com
|
@@ -53,12 +53,11 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- app/helpers/searchify/searchify_helper.rb
|
55
55
|
- app/controllers/searchify/searchify_controller.rb
|
56
|
-
- app/views/searchify/searchify/search.html.erb
|
57
|
-
- app/views/layouts/searchify/application.html.erb
|
58
56
|
- app/assets/javascripts/searchify/searchify.js.coffee
|
59
57
|
- config/routes.rb
|
60
58
|
- lib/searchify/version.rb
|
61
59
|
- lib/searchify/engine.rb
|
60
|
+
- lib/searchify/controller.rb
|
62
61
|
- lib/searchify.rb
|
63
62
|
- lib/tasks/searchify_tasks.rake
|
64
63
|
- MIT-LICENSE
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Searchify</title>
|
5
|
-
<%= stylesheet_link_tag "searchify/application" %>
|
6
|
-
<%= javascript_include_tag "searchify/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|