sorted 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +2 -0
- data/README.rdoc +19 -3
- data/Rakefile +2 -17
- data/lib/sorted/sorter.rb +17 -16
- data/lib/sorted/version.rb +3 -0
- data/sorted.gemspec +18 -53
- metadata +66 -25
- data/VERSION +0 -1
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -4,10 +4,12 @@ Sorted is a simple object that will take an sql order string and a url sort stri
|
|
4
4
|
|
5
5
|
Using Rails master it will create a `sorted` scope and a two view helpers
|
6
6
|
|
7
|
-
gem install sorted
|
8
|
-
|
9
7
|
== Example
|
10
8
|
|
9
|
+
=== Gemfile
|
10
|
+
|
11
|
+
gem sorted
|
12
|
+
|
11
13
|
=== The view:
|
12
14
|
|
13
15
|
link_to_sorted "Email", :email
|
@@ -26,7 +28,9 @@ This will initially sort by email ascending:
|
|
26
28
|
|
27
29
|
@users = User.sorted(:order => "email ASC", :sort => params[:sort]).paginate(:page => params[:page])
|
28
30
|
|
29
|
-
|
31
|
+
Or you can just clone the example app https://github.com/mynameisrufus/sorted_app
|
32
|
+
|
33
|
+
== Presentation
|
30
34
|
|
31
35
|
You might want to roll your own link_to_sorted method to use jQuery ui css classes for example, all you need is the sorted object.
|
32
36
|
|
@@ -44,6 +48,18 @@ You might want to roll your own link_to_sorted method to use jQuery ui css class
|
|
44
48
|
link_to(content_tag(:span, nil, {:class => css_class}) + name, sorter.params)
|
45
49
|
end
|
46
50
|
|
51
|
+
Tables are best displayed with alternating shades for each row, so put this in your helper:
|
52
|
+
|
53
|
+
def odd_even
|
54
|
+
@odd_even ||= 0
|
55
|
+
@odd_even += 1
|
56
|
+
(@odd_even % 2) == 1 ? 'odd' : 'even'
|
57
|
+
end
|
58
|
+
|
59
|
+
Then in your table do something like this:
|
60
|
+
|
61
|
+
<tr class="<%= odd_even %>">
|
62
|
+
|
47
63
|
== Rails 2.3.x
|
48
64
|
|
49
65
|
This gem works with rails 2.3.x but you will have to roll your own scope and view helper.
|
data/Rakefile
CHANGED
@@ -1,17 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "sorted"
|
8
|
-
gem.summary = %Q{sort a table}
|
9
|
-
gem.description = %Q{lets you sort large data sets using view helpers and a scope}
|
10
|
-
gem.email = "rufuspost@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/mynameisrufus/sorted"
|
12
|
-
gem.authors = ["Rufus Post"]
|
13
|
-
end
|
14
|
-
Jeweler::GemcutterTasks.new
|
15
|
-
rescue LoadError
|
16
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/lib/sorted/sorter.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Sorted
|
2
2
|
class Sorter
|
3
|
-
def initialize(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def initialize(order, params = nil)
|
4
|
+
if order.is_a?(String) || order.is_a?(Symbol)
|
5
|
+
parse_order(order)
|
6
|
+
end
|
7
|
+
if params.is_a?(Hash)
|
8
|
+
@params = params
|
9
|
+
if @params[:sort].is_a?(String)
|
8
10
|
parse_sort @params[:sort]
|
9
11
|
end
|
10
12
|
end
|
11
|
-
self
|
12
13
|
end
|
13
14
|
|
14
15
|
def parse_sort(sort_string)
|
@@ -88,16 +89,16 @@ module Sorted
|
|
88
89
|
end
|
89
90
|
|
90
91
|
private
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
sorts_new
|
97
|
-
end
|
98
|
-
|
99
|
-
def array
|
100
|
-
@array ||= default
|
92
|
+
def default
|
93
|
+
sorts_new = sorts.dup
|
94
|
+
orders.each do |order|
|
95
|
+
sorts_new << order unless sorts_new.flatten.include?(order[0])
|
101
96
|
end
|
97
|
+
sorts_new
|
98
|
+
end
|
99
|
+
|
100
|
+
def array
|
101
|
+
@array ||= default
|
102
|
+
end
|
102
103
|
end
|
103
104
|
end
|
data/sorted.gemspec
CHANGED
@@ -1,60 +1,25 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/sorted/version", __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
5
|
+
s.name = "sorted"
|
6
|
+
s.version = Example::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Rufus Post"]
|
9
|
+
s.email = ["rufuspost@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/sorted"
|
11
|
+
s.summary = "sort data with a database"
|
12
|
+
s.description = "lets you sort large data sets using view helpers and a scope"
|
9
13
|
|
10
|
-
s.required_rubygems_version =
|
11
|
-
s.
|
12
|
-
s.date = %q{2010-09-10}
|
13
|
-
s.description = %q{lets you sort large data sets using view helpers and a scope}
|
14
|
-
s.email = %q{rufuspost@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/sorted.rb",
|
27
|
-
"lib/sorted/finders/active_record.rb",
|
28
|
-
"lib/sorted/railtie.rb",
|
29
|
-
"lib/sorted/sorter.rb",
|
30
|
-
"lib/sorted/toggler.rb",
|
31
|
-
"lib/sorted/view_helpers/action_view.rb",
|
32
|
-
"sorted.gemspec",
|
33
|
-
"spec/sorted_spec.rb",
|
34
|
-
"spec/sorter_spec.rb",
|
35
|
-
"spec/spec_helper.rb",
|
36
|
-
"spec/toggler_spec.rb"
|
37
|
-
]
|
38
|
-
s.homepage = %q{http://github.com/mynameisrufus/sorted}
|
39
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
-
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.3.7}
|
42
|
-
s.summary = %q{sort a table}
|
43
|
-
s.test_files = [
|
44
|
-
"spec/spec_helper.rb",
|
45
|
-
"spec/sorter_spec.rb",
|
46
|
-
"spec/toggler_spec.rb",
|
47
|
-
"spec/sorted_spec.rb"
|
48
|
-
]
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "sorted"
|
49
16
|
|
50
|
-
|
51
|
-
|
52
|
-
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "rails", ">= 3.0.0"
|
19
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
53
20
|
|
54
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
-
else
|
56
|
-
end
|
57
|
-
else
|
58
|
-
end
|
59
|
-
end
|
60
21
|
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Rufus Post
|
@@ -15,31 +14,76 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-16 00:00:00 +11:00
|
19
18
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rails
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 2
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
version: 2.0.0
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
22
65
|
description: lets you sort large data sets using view helpers and a scope
|
23
|
-
email:
|
66
|
+
email:
|
67
|
+
- rufuspost@gmail.com
|
24
68
|
executables: []
|
25
69
|
|
26
70
|
extensions: []
|
27
71
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
30
|
-
- README.rdoc
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
31
74
|
files:
|
32
75
|
- .document
|
33
76
|
- .gitignore
|
77
|
+
- Gemfile
|
34
78
|
- LICENSE
|
35
79
|
- README.rdoc
|
36
80
|
- Rakefile
|
37
|
-
- VERSION
|
38
81
|
- lib/sorted.rb
|
39
82
|
- lib/sorted/finders/active_record.rb
|
40
83
|
- lib/sorted/railtie.rb
|
41
84
|
- lib/sorted/sorter.rb
|
42
85
|
- lib/sorted/toggler.rb
|
86
|
+
- lib/sorted/version.rb
|
43
87
|
- lib/sorted/view_helpers/action_view.rb
|
44
88
|
- sorted.gemspec
|
45
89
|
- spec/sorted_spec.rb
|
@@ -47,12 +91,12 @@ files:
|
|
47
91
|
- spec/spec_helper.rb
|
48
92
|
- spec/toggler_spec.rb
|
49
93
|
has_rdoc: true
|
50
|
-
homepage: http://
|
94
|
+
homepage: http://rubygems.org/gems/sorted
|
51
95
|
licenses: []
|
52
96
|
|
53
97
|
post_install_message:
|
54
|
-
rdoc_options:
|
55
|
-
|
98
|
+
rdoc_options: []
|
99
|
+
|
56
100
|
require_paths:
|
57
101
|
- lib
|
58
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -60,7 +104,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
104
|
requirements:
|
61
105
|
- - ">="
|
62
106
|
- !ruby/object:Gem::Version
|
63
|
-
hash: 3
|
64
107
|
segments:
|
65
108
|
- 0
|
66
109
|
version: "0"
|
@@ -69,19 +112,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
112
|
requirements:
|
70
113
|
- - ">="
|
71
114
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
115
|
segments:
|
74
|
-
-
|
75
|
-
|
116
|
+
- 1
|
117
|
+
- 3
|
118
|
+
- 6
|
119
|
+
version: 1.3.6
|
76
120
|
requirements: []
|
77
121
|
|
78
|
-
rubyforge_project:
|
122
|
+
rubyforge_project: sorted
|
79
123
|
rubygems_version: 1.3.7
|
80
124
|
signing_key:
|
81
125
|
specification_version: 3
|
82
|
-
summary: sort a
|
83
|
-
test_files:
|
84
|
-
|
85
|
-
- spec/sorter_spec.rb
|
86
|
-
- spec/toggler_spec.rb
|
87
|
-
- spec/sorted_spec.rb
|
126
|
+
summary: sort data with a database
|
127
|
+
test_files: []
|
128
|
+
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.5
|