is_filterable 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in is_filterable.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011-2012 Philip Kurmann
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.
@@ -0,0 +1,65 @@
1
+ = isFilterable for Rails3
2
+
3
+ Simple AJAX filter to filter/search results a ActiveRecord Model
4
+
5
+ == Install
6
+
7
+ === Rails
8
+ Inside your Gemfile:
9
+ gem "is_filterable"
10
+
11
+ and then run:
12
+ bundle install
13
+
14
+
15
+ === Javascripts
16
+
17
+ You have to include the filterable Javascript in your Javascript file.
18
+
19
+ //= require filterable
20
+
21
+ === Gem Dependencies
22
+
23
+ Please check if all those requirements are satisfied on your environment.
24
+
25
+ * jquery-rails
26
+
27
+
28
+ == Usage
29
+
30
+ === Model
31
+
32
+ In the model you have to include:
33
+ class User < ActiveRecord::Base
34
+ ...
35
+ is_filterable
36
+ ...
37
+ end
38
+
39
+ === Controller
40
+
41
+ In your Controller you have to use the method search.
42
+ The search Method used the first parmameter as the attribute on which the query should be done and the second as input filter parameter.
43
+
44
+ In your Controller
45
+ class UsersController < ApplicationController
46
+ ...
47
+ def index
48
+ @users = User.search('login',params[:search]).order('login').page(params[:page]).per_page(15)
49
+
50
+ respond_to do |format|
51
+ format.html # index.html.erb
52
+ format.js
53
+ end
54
+ end
55
+ ...
56
+ end
57
+
58
+
59
+ === View
60
+
61
+ text_field_tag :search, params[:search], :class => "input-medium search-query search-observer", :placeholder => "user name"
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2011 - 2012 In&Work AG. See LICENSE for details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ # Filter Search Field Observer
2
+ jQuery ($) ->
3
+ $(".search-observer").keyup ->
4
+ group = $(this)
5
+ form = group.parents("form").eq(0)
6
+ $.get form.attr("action"), form.serialize(), null, "script"
7
+ false
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "is_filterable/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "is_filterable"
7
+ s.version = IsFilterable::VERSION
8
+ s.authors = ["Lucien Stuker","Philip Kurmann"]
9
+ s.email = ["lucien.stuker@inwork.ch","philip.kurmann@inwork.ch"]
10
+ s.homepage = "https://github.com/InWork/is_filterable"
11
+ s.summary = %q{Simple AJAX filter to filter/search results a ActiveRecord Model}
12
+ s.description = %q{This Gem implements the option to filter/search in a ActiveRecord model by a search pattern}
13
+
14
+ s.rubyforge_project = "is_filterable"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_dependency "jquery-rails"
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require 'is_filterable/filterable'
3
+ require 'is_filterable/version'
4
+
5
+ module IsFilterable
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+
10
+ ActiveRecord::Base.send(:include, IsFilterable::Filterable)
@@ -0,0 +1,31 @@
1
+ module IsFilterable
2
+ module Filterable
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+
8
+ module ClassMethods
9
+ def is_filterable args = {}
10
+ include IsFilterable::Filterable::InstanceMethods
11
+ extend IsFilterable::Filterable::SingletonMethods
12
+ end
13
+ end
14
+
15
+
16
+ module SingletonMethods
17
+ def search attribute, search
18
+ if search
19
+ where "#{attribute} LIKE ?", "%#{search}%"
20
+ else
21
+ scoped
22
+ end
23
+ end
24
+ end
25
+
26
+
27
+ module InstanceMethods
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module IsFilterable
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_filterable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lucien Stuker
9
+ - Philip Kurmann
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &70147176745980 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70147176745980
26
+ - !ruby/object:Gem::Dependency
27
+ name: jquery-rails
28
+ requirement: &70147176745540 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70147176745540
37
+ description: This Gem implements the option to filter/search in a ActiveRecord model
38
+ by a search pattern
39
+ email:
40
+ - lucien.stuker@inwork.ch
41
+ - philip.kurmann@inwork.ch
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - app/assets/javascript/is_filterable.js.coffee
52
+ - is_filterable.gemspec
53
+ - lib/is_filterable.rb
54
+ - lib/is_filterable/filterable.rb
55
+ - lib/is_filterable/version.rb
56
+ homepage: https://github.com/InWork/is_filterable
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: is_filterable
76
+ rubygems_version: 1.8.15
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Simple AJAX filter to filter/search results a ActiveRecord Model
80
+ test_files: []