philtre-rails 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 +23 -0
- data/.travis.yml +7 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +129 -0
- data/Rakefile +2 -0
- data/TODO +8 -0
- data/lib/philtre-rails/order_link.rb +35 -0
- data/lib/philtre-rails/philtre_model.rb +38 -0
- data/lib/philtre-rails/philtre_view_helpers.rb +45 -0
- data/lib/philtre-rails/railtie.rb +37 -0
- data/lib/philtre-rails/version.rb +3 -0
- data/lib/philtre-rails.rb +2 -0
- data/philtre-rails.gemspec +28 -0
- data/spec/philtre_model_spec.rb +60 -0
- data/spec/philtre_view_helpers_spec.rb +79 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf689090e57a974c0eeb8c7e1c975def2021a4b2
|
4
|
+
data.tar.gz: 94dc25ac6aca1555d86a91663bc252fcaffb9d04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1d170e78c1757a486a6fcb19776a00bd7c18581dc1c4ee0008841b06514fa560abda0cc08ccdc2c840433cfe938fa5a1ce62cd33c3b461d7152ff2bc3331c46
|
7
|
+
data.tar.gz: 886ea0681ac1133b0b2e34ab67d19c2545d1563c84170b7a7be9779ec3c6248bf05ce99220867db781e93d96a9a3a43ba5ba6b0efc94b3f879b1917e67a2f800
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.ruby-gemset
|
19
|
+
.ruby-version
|
20
|
+
*.sublime-project
|
21
|
+
*.sublime-workspace
|
22
|
+
.floo
|
23
|
+
.flooignore
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in philtre-rails.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
if (local_philtre = Pathname("#{ENV['HOME']}/projects/philtre")).exist?
|
7
|
+
gem 'philtre', path: local_philtre
|
8
|
+
gem 'pry'
|
9
|
+
gem 'pry-byebug'
|
10
|
+
gem 'simplecov'
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 John Anderson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# philtre-rails [](http://badge.fury.io/rb/philtre-rails)
|
2
|
+
|
3
|
+
It's the [Sequel](http://sequel.jeremyevans.net) equivalent for Ransack, Metasearch, Searchlogic. If
|
4
|
+
this doesn't make you fall in love, I don't know what will :-p
|
5
|
+
|
6
|
+
Parse the predicates on the end of field names, and round-trip the
|
7
|
+
search fields between incoming params, controller and views.
|
8
|
+
|
9
|
+
Start with the docs for [philtre](http://github.com/djellemah/philtre) and
|
10
|
+
then look here for rails integration.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'philtre-rails'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install philtre-rails
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Filter form
|
31
|
+
|
32
|
+
Your controller would have something like this (you could also use the more
|
33
|
+
common ```@filter``` and ```@results``` as well if you like):
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
helper_method def filter
|
37
|
+
@filter ||= Philtre.new philtre_params
|
38
|
+
end
|
39
|
+
|
40
|
+
helper_method def results
|
41
|
+
# where Result is a Sequel::Model subclass, or actually any kind of dataset.
|
42
|
+
@results ||= filter.apply Result
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Note that by default your parameters will be in ```params[:philtre]```, for
|
47
|
+
which ```philtre_params``` is a convenience accessor.
|
48
|
+
|
49
|
+
And your filter form would look something like this:
|
50
|
+
|
51
|
+
``` haml
|
52
|
+
.filter
|
53
|
+
= form_for philtre.for_form, url: params.slice(:controller,:action), method: 'get' do |f|
|
54
|
+
= f.hidden_field :order
|
55
|
+
= f.text_field :title_like, placeholder: 'Fancy Title'
|
56
|
+
= f.select :birth_year, (Date.today.year-90 .. Date.today.year).map( &:to_s), include_blank: 'Year'
|
57
|
+
= f.submit 'Filter', name: nil, class: 'btn'
|
58
|
+
```
|
59
|
+
|
60
|
+
The ```for_form``` method is clunky. But ```ActiveModel``` seems to only use the result of ```to_model```
|
61
|
+
for naming and route generation, and then reverts to the object for the actual values.
|
62
|
+
I'm hoping I'm wrong, or they had a good reason to do it that way...
|
63
|
+
|
64
|
+
Don't forget the ```:order``` field. It will be important to hold the ordering state once you hook up ordering links.
|
65
|
+
|
66
|
+
Speaking of which...
|
67
|
+
|
68
|
+
### Basic Ordering links
|
69
|
+
|
70
|
+
``` haml
|
71
|
+
%table.results
|
72
|
+
%thead
|
73
|
+
%tr
|
74
|
+
%th.party= order_by filter, :party
|
75
|
+
%th.station= order_by filter, :station, label: 'Voting Station'
|
76
|
+
%th.ra.votes= order_by filter, :votes, order_link_class: MyOrderLink
|
77
|
+
|
78
|
+
-# not really ordering, but someone might find this useful
|
79
|
+
%tbody
|
80
|
+
- results.each do |result|
|
81
|
+
%tr
|
82
|
+
%td.party= result.party
|
83
|
+
%td.station= result.station
|
84
|
+
%td.ra.votes= result.votes
|
85
|
+
```
|
86
|
+
|
87
|
+
### Custom Ordering links
|
88
|
+
|
89
|
+
1) You can specify the ```order_link_class``` parameter to ```order_by```.
|
90
|
+
|
91
|
+
The ```OrderLink``` class defines:
|
92
|
+
|
93
|
+
* the icons (ie little chunks of html) that are displayed next to the order links
|
94
|
+
|
95
|
+
* the CSS class for the <a...> tag
|
96
|
+
|
97
|
+
* the ordering name which shows up in the filter parameters.
|
98
|
+
|
99
|
+
For example:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
class MyOrderLink < PhiltreRails::OrderLink
|
103
|
+
def icon
|
104
|
+
if active
|
105
|
+
expr.descending ? '^' : 'v'
|
106
|
+
else
|
107
|
+
# optionally have a no-order icon
|
108
|
+
'-'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
2) If you don't want to specify ```:order_link_class``` repeatedly, you can also
|
115
|
+
replace the ```default_order_link_class``` method in a helper.
|
116
|
+
|
117
|
+
## Specs
|
118
|
+
|
119
|
+
Nothing fancy. Just:
|
120
|
+
|
121
|
+
$ rspec spec
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
1. Fork it ( https://github.com/djellemah/philtre-rails/fork )
|
126
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
127
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
128
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
129
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/TODO
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
philtre-rails:
|
2
|
+
☐ report bug for ActiveModel?
|
3
|
+
|
4
|
+
___________________
|
5
|
+
Archive:
|
6
|
+
✔ specs @done (14-08-18 12:53) @project(philtre-rails)
|
7
|
+
✔ railties so it can just be included @done (14-08-18 11:27) @project(philtre-rails)
|
8
|
+
✔ place to put sort headers @done (14-08-18 11:27) @project(philtre-rails)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PhiltreRails
|
2
|
+
# Used by order_by helper to generate ordering links.
|
3
|
+
class OrderLink
|
4
|
+
# expr is a Sequel::SQL::OrderedExpression
|
5
|
+
def initialize( expr, active: false )
|
6
|
+
@expr = expr
|
7
|
+
@active = active
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :expr, :active
|
11
|
+
|
12
|
+
# appended to the label
|
13
|
+
def icon
|
14
|
+
if active
|
15
|
+
expr.descending ? '▼' : '▲'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# class of the generated <a...>
|
20
|
+
def css_class
|
21
|
+
if active
|
22
|
+
expr.descending ? 'descending' : 'ascending'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# this value ends up in the order array of the parameter hash
|
27
|
+
def name
|
28
|
+
if active
|
29
|
+
expr.descending ? "#{expr.expression}_desc" : "#{expr.expression}_asc"
|
30
|
+
else
|
31
|
+
expr.expression
|
32
|
+
end.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'philtre/filter.rb'
|
3
|
+
|
4
|
+
class Philtre::Filter
|
5
|
+
# These define the interface as used by the views.
|
6
|
+
# So this class is available for custom predicates.
|
7
|
+
class Model < OpenStruct
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
|
10
|
+
# Name this as 'filter', so the parameters come back from the form as that.
|
11
|
+
def self.model_name; ActiveModel::Name.new(Philtre); end
|
12
|
+
|
13
|
+
# Rest of ActiveModel compliance, because
|
14
|
+
# include ActiveModel::Model
|
15
|
+
# messes with initialize, which breaks OpenStruct
|
16
|
+
def persisted?; false; end
|
17
|
+
def to_key; nil; end
|
18
|
+
def to_param; nil; end
|
19
|
+
def errors; @errors ||= ActiveModel::Errors.new(self); end
|
20
|
+
def to_partial_path; self.class.model_name.param_key; end
|
21
|
+
def to_model; self; end
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO If your model does not act like an Active Model object, then you
|
25
|
+
# should define :to_model yourself returning a proxy object that wraps your
|
26
|
+
# object with Active Model compliant methods.
|
27
|
+
#
|
28
|
+
# 07-May-2014 Nice idea, except that (at least from 4.0.2) rails uses to_model only in some
|
29
|
+
# cases to get naming, and the original object gets passed to the FormBuilder.
|
30
|
+
# Which is a bit stoopid.
|
31
|
+
def to_model
|
32
|
+
raise "Use for_form, you can't pass #{self} directly into a form_for call."
|
33
|
+
end
|
34
|
+
|
35
|
+
def for_form
|
36
|
+
Model.new filter_parameters.reject{|k,v| v.blank?}
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# http://api.rubyonrails.org/classes/Rails/Railtie.html
|
2
|
+
module PhiltreRails
|
3
|
+
module PhiltreViewHelpers
|
4
|
+
# There is a nicer way to do this, but it means monkey-patching Array.
|
5
|
+
# Which upsets some folks.
|
6
|
+
def unify_array( ary )
|
7
|
+
case ary.size
|
8
|
+
when 0; nil
|
9
|
+
when 1; ary.first
|
10
|
+
else; ary
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# can be overridden
|
15
|
+
def default_order_link_class
|
16
|
+
OrderLink
|
17
|
+
end
|
18
|
+
|
19
|
+
# Heavily modified from SearchLogic.
|
20
|
+
def order_by( filter, *fields, label: fields.first.to_s.titleize, order_link_class: default_order_link_class )
|
21
|
+
return label if filter.nil?
|
22
|
+
|
23
|
+
# current ordering from the filter
|
24
|
+
# each expr is a Sequel::SQL::Expression
|
25
|
+
exprs = Hash[ filter.order_expressions ]
|
26
|
+
|
27
|
+
# Invert each ordering for the generated link. Current sort order will be displayed.
|
28
|
+
order_links = fields.map do |field|
|
29
|
+
if exprs[field]
|
30
|
+
order_link_class.new exprs[field].invert, active: true
|
31
|
+
else
|
32
|
+
order_link_class.new Sequel.asc(field)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# filter params must have order in the right format
|
37
|
+
filter_params = filter.filter_parameters.dup
|
38
|
+
filter_params[:order] = unify_array( order_links.map( &:name ) )
|
39
|
+
|
40
|
+
params_hash = {filter.class::Model.model_name.param_key.to_sym => filter_params}
|
41
|
+
link_text = raw( [label, order_links.first.andand.icon].compact.join(' ') )
|
42
|
+
link_to link_text, params_hash, {class: order_links.first.andand.css_class}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# http://api.rubyonrails.org/classes/Rails/Railtie.html
|
2
|
+
module PhiltreRails
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "philtre-rails.action_controller" do
|
5
|
+
ActiveSupport.on_load(:action_controller) do
|
6
|
+
send :define_method, :philtre_params do
|
7
|
+
params[Philtre::Filter::Model.model_name.param_key.to_sym]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer "philtre-rails.configure_rails_initialization" do |app|
|
13
|
+
# not sure about this?
|
14
|
+
# Sequel.extension :core_extensions
|
15
|
+
|
16
|
+
# and the code to do filtering and Sequel::Dataset manipulation
|
17
|
+
require 'philtre.rb'
|
18
|
+
require 'philtre/sequel_extensions.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
initializer "philtre-rails.active_model" do |app|
|
22
|
+
require 'philtre-rails/philtre_model.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
initializer "philtre-rails.view_helpers" do
|
26
|
+
require 'philtre-rails/order_link.rb'
|
27
|
+
require 'philtre-rails/philtre_view_helpers.rb'
|
28
|
+
ActionView::Base.send :include, PhiltreViewHelpers
|
29
|
+
end
|
30
|
+
|
31
|
+
config.to_prepare do
|
32
|
+
# Called once in production, on each request during development
|
33
|
+
# Seems to be fine without it.
|
34
|
+
# require 'philtre_model.rb'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'philtre-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "philtre-rails"
|
8
|
+
spec.version = PhiltreRails::VERSION
|
9
|
+
spec.authors = ["John Anderson"]
|
10
|
+
spec.email = ["panic@semiosix.com"]
|
11
|
+
spec.summary = %q{Filtering for Sequel on rails}
|
12
|
+
spec.description = %q{The Sequel equivalent for Ransack, Metasearch, Searchlogic}
|
13
|
+
spec.homepage = "http://github.com/djellemah/philtre-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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 "philtre"
|
22
|
+
spec.add_dependency "activemodel"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'faker'
|
28
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'faker'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
require 'philtre/filter.rb'
|
6
|
+
|
7
|
+
require_relative '../lib/philtre-rails/philtre_model.rb'
|
8
|
+
|
9
|
+
# spec/support/active_model_lint.rb
|
10
|
+
# adapted from rspec-rails:
|
11
|
+
# http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
|
12
|
+
shared_examples_for "ActiveModel" do
|
13
|
+
require 'minitest'
|
14
|
+
require 'active_model/lint'
|
15
|
+
|
16
|
+
# needed by MiniTest::Assertions
|
17
|
+
def assertions; @assertions ||= 0 end
|
18
|
+
def assertions=( rhs ); @assertions = rhs end
|
19
|
+
|
20
|
+
include MiniTest::Assertions
|
21
|
+
|
22
|
+
include ActiveModel::Lint::Tests
|
23
|
+
|
24
|
+
ActiveModel::Lint::Tests
|
25
|
+
.public_instance_methods
|
26
|
+
.grep(/^test/)
|
27
|
+
.each do |test_method|
|
28
|
+
example test_method.to_s.gsub('_',' ') do
|
29
|
+
send test_method
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# needed for MiniTest::Assertions
|
34
|
+
def model; subject end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe Philtre::Filter do
|
38
|
+
|
39
|
+
describe '#to_model' do
|
40
|
+
subject{ Philtre::Filter.new( one: 1, two: 2 ) }
|
41
|
+
|
42
|
+
it 'should raise exception' do
|
43
|
+
->{subject.to_model}.should raise_error(/use for_form/i)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#for_form' do
|
48
|
+
subject{ Philtre::Filter.new( one: 1, two: 2 ).for_form }
|
49
|
+
|
50
|
+
it_should_behave_like("ActiveModel")
|
51
|
+
|
52
|
+
it 'nil for not present' do
|
53
|
+
subject.three.should be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'value for present' do
|
57
|
+
subject.two.should == 2
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../lib/philtre-rails/philtre_view_helpers.rb'
|
2
|
+
require_relative '../lib/philtre-rails/order_link.rb'
|
3
|
+
|
4
|
+
describe PhiltreRails::PhiltreViewHelpers do
|
5
|
+
def subject
|
6
|
+
@subject ||= begin
|
7
|
+
obj = Object.new.extend( described_class )
|
8
|
+
class << obj
|
9
|
+
def raw(str); str end
|
10
|
+
def link_to(text, params, html_options)
|
11
|
+
html_options.merge(href: params.inspect)
|
12
|
+
html_attrs = html_options.map{|k,v| %Q{#{k}="#{v}"}}.join(' ')
|
13
|
+
%Q{<a #{html_attrs}>#{text}</a>}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#order_by' do
|
21
|
+
def filter
|
22
|
+
@filter ||= Philtre::Filter.new order: [:first, :second]
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns label for no filter' do
|
26
|
+
subject.order_by( nil, :first ).should == 'First'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'inverts no order' do
|
30
|
+
link_str = subject.order_by( filter, :first )
|
31
|
+
link_str.should =~ />First.*?</
|
32
|
+
link_str.should =~ /class="descending/
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'inverts ascending order' do
|
36
|
+
filter = self.filter.clone(:order => :first_asc)
|
37
|
+
link_str = subject.order_by( filter, :first )
|
38
|
+
link_str.should =~ />First.*?</
|
39
|
+
link_str.should =~ /class="descending/
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'inverts descending order' do
|
43
|
+
filter = self.filter.clone(:order => :first_desc)
|
44
|
+
link_str = subject.order_by( filter, :first )
|
45
|
+
link_str.should =~ />First.*?</
|
46
|
+
link_str.should =~ /class="ascending/
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'OrderLink' do
|
50
|
+
class CustomOrderLink < PhiltreRails::OrderLink
|
51
|
+
def css_class
|
52
|
+
if active
|
53
|
+
expr.descending ? 'going_down' : 'going_up'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'uses custom order link' do
|
59
|
+
link_str = subject.order_by filter, :first, order_link_class: CustomOrderLink
|
60
|
+
link_str.should =~ />First.*?</
|
61
|
+
link_str.should =~ /class="going_down/
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'changes default order link' do
|
65
|
+
# don't modify the class definition
|
66
|
+
subject = self.subject.clone
|
67
|
+
class << subject
|
68
|
+
def default_order_link_class
|
69
|
+
CustomOrderLink
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
link_str = subject.order_by filter, :first, order_link_class: CustomOrderLink
|
74
|
+
link_str.should =~ />First.*?</
|
75
|
+
link_str.should =~ /class="going_down/
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: philtre-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: philtre
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faker
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: The Sequel equivalent for Ransack, Metasearch, Searchlogic
|
98
|
+
email:
|
99
|
+
- panic@semiosix.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- TODO
|
111
|
+
- lib/philtre-rails.rb
|
112
|
+
- lib/philtre-rails/order_link.rb
|
113
|
+
- lib/philtre-rails/philtre_model.rb
|
114
|
+
- lib/philtre-rails/philtre_view_helpers.rb
|
115
|
+
- lib/philtre-rails/railtie.rb
|
116
|
+
- lib/philtre-rails/version.rb
|
117
|
+
- philtre-rails.gemspec
|
118
|
+
- spec/philtre_model_spec.rb
|
119
|
+
- spec/philtre_view_helpers_spec.rb
|
120
|
+
homepage: http://github.com/djellemah/philtre-rails
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.2.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Filtering for Sequel on rails
|
144
|
+
test_files:
|
145
|
+
- spec/philtre_model_spec.rb
|
146
|
+
- spec/philtre_view_helpers_spec.rb
|