alphabetical_paginate 0.2.3 → 0.2.4
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/.alphabetical_paginate.gemspec.swp +0 -0
- data/alphabetical_paginate.gemspec +2 -0
- data/lib/.alphabetical_paginate.rb.swp +0 -0
- data/lib/alphabetical_paginate/.array.rb.swp +0 -0
- data/lib/alphabetical_paginate/.engine.rb.swp +0 -0
- data/lib/alphabetical_paginate/.railtie.rb.swp +0 -0
- data/lib/alphabetical_paginate/.view_helpers.rb.swp +0 -0
- data/lib/alphabetical_paginate/array.rb +29 -2
- data/lib/alphabetical_paginate/engine.rb +3 -1
- data/lib/alphabetical_paginate/version.rb +1 -1
- data/lib/alphabetical_paginate/view_helpers.rb +14 -3
- data/spec/.alpha_example.rb.swp +0 -0
- data/spec/.alphabetical_paginate_spec.rb.swp +0 -0
- data/spec/alpha_example.rb +15 -0
- data/spec/alphabetical_paginate_spec.rb +53 -0
- data/spec/support/.helpers.rb.swp +0 -0
- data/spec/support/helpers.rb +3 -0
- metadata +53 -3
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,5 +1,32 @@
|
|
1
1
|
class Array
|
2
|
-
def
|
3
|
-
|
2
|
+
def alpha_paginate current_field, enumerate=false
|
3
|
+
output = []
|
4
|
+
params = {}
|
5
|
+
availableLetters = {}
|
6
|
+
if current_field == nil
|
7
|
+
current_field = this.sort[0].to_s[0]
|
8
|
+
end
|
9
|
+
self.each do |x|
|
10
|
+
field_val = block_given? ? yield(x) : x.id.to_s
|
11
|
+
field_letter = field_val.force_encoding(Encoding::ASCII_8BIT)[0]
|
12
|
+
case current_field
|
13
|
+
when /[a-z]/
|
14
|
+
availableLetters[field_letter] = true if !availableLetters.has_key? field_letter
|
15
|
+
output << x if field_letter == current_field
|
16
|
+
when "number"
|
17
|
+
availableLetters['numbers'] = true if !availableLetters.has_key? 'numbers'
|
18
|
+
output << x if field_letter =~ /[0-9]/
|
19
|
+
when enumerate && /[0-9]/
|
20
|
+
availableLetters[field_letter] = true if !availableLetters.has_key? field_letter
|
21
|
+
output << x if field_letter == current_field
|
22
|
+
when "other"
|
23
|
+
availableLetters['other'] = true if !availableLetters.has_key? 'other'
|
24
|
+
output << x if !field_letter =~ /[0-9a-z]/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
params[:availableLetters] = availableLetters.collect{|k,v| k.to_s}
|
28
|
+
params[:currentField] = current_field
|
29
|
+
params[:enumerate] = enumerate
|
30
|
+
return output, params
|
4
31
|
end
|
5
32
|
end
|
@@ -1,8 +1,19 @@
|
|
1
1
|
module AlphabeticalPaginate
|
2
2
|
module ViewHelpers
|
3
|
-
def alphabetical_paginate
|
4
|
-
output = javascript_include_tag 'alphabetical_paginate'
|
5
|
-
|
3
|
+
def alphabetical_paginate params, bootstrap=true
|
4
|
+
output = javascript_include_tag 'alphabetical_paginate' + " \n"
|
5
|
+
|
6
|
+
params[:availableLetters].each do |l|
|
7
|
+
links += '<li><a href="#" data-letter="' + l + '">' + l + "</a></li>\n"
|
8
|
+
|
9
|
+
end
|
10
|
+
pagination = '<div class="pagination">\n' +
|
11
|
+
"<ul>\n" +
|
12
|
+
"%s" % links +
|
13
|
+
"</ul\n" +
|
14
|
+
"</div>"
|
15
|
+
|
16
|
+
output += pagination
|
6
17
|
end
|
7
18
|
end
|
8
19
|
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'alpha_example'
|
2
|
+
require 'alphabetical_paginate'
|
3
|
+
|
4
|
+
module AlphabeticalPaginate
|
5
|
+
|
6
|
+
describe AlphabeticalPaginate do
|
7
|
+
|
8
|
+
describe "#alpha_paginate" do
|
9
|
+
before :each do
|
10
|
+
@list = ["aa", "ab", "ac",
|
11
|
+
"ba", "bb", "bg",
|
12
|
+
"ca", "cd", "ce"].map do |x|
|
13
|
+
AlphaExample.new(x)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should paginate by id automatically" do
|
18
|
+
expectedCollection = ["ba", "bb", "bg"].map do |x|
|
19
|
+
AlphaExample.new(x)
|
20
|
+
end
|
21
|
+
expectedParams = {
|
22
|
+
availableLetters: ["a", "b", "c"],
|
23
|
+
currentField: "b",
|
24
|
+
enumerate: false,
|
25
|
+
}
|
26
|
+
collection, params = @list.alpha_paginate("b")
|
27
|
+
collection.to_s.should ==
|
28
|
+
expectedCollection.to_s
|
29
|
+
params.to_s.should ==
|
30
|
+
expectedParams.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should paginate by block when needed" do
|
34
|
+
expectedCollection = ["ab", "bb"].map do |x|
|
35
|
+
AlphaExample.new(x)
|
36
|
+
end
|
37
|
+
expectedParams = {
|
38
|
+
availableLetters: ["a", "b", "c", "g", "d", "e"],
|
39
|
+
currentField: "b",
|
40
|
+
enumerate: false,
|
41
|
+
}
|
42
|
+
collection, params = @list.alpha_paginate("b") do |x|
|
43
|
+
x.word
|
44
|
+
end
|
45
|
+
collection.to_s.should ==
|
46
|
+
expectedCollection.to_s
|
47
|
+
params.to_s.should ==
|
48
|
+
expectedParams.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphabetical_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: Alphabetical Pagination
|
47
79
|
email:
|
48
80
|
- lz781@nyu.edu
|
@@ -50,18 +82,30 @@ executables: []
|
|
50
82
|
extensions: []
|
51
83
|
extra_rdoc_files: []
|
52
84
|
files:
|
85
|
+
- .alphabetical_paginate.gemspec.swp
|
53
86
|
- .gitignore
|
54
87
|
- Gemfile
|
55
88
|
- LICENSE.txt
|
56
89
|
- README.md
|
57
90
|
- Rakefile
|
58
91
|
- alphabetical_paginate.gemspec
|
92
|
+
- lib/.alphabetical_paginate.rb.swp
|
59
93
|
- lib/alphabetical_paginate.rb
|
94
|
+
- lib/alphabetical_paginate/.array.rb.swp
|
95
|
+
- lib/alphabetical_paginate/.engine.rb.swp
|
96
|
+
- lib/alphabetical_paginate/.railtie.rb.swp
|
97
|
+
- lib/alphabetical_paginate/.view_helpers.rb.swp
|
60
98
|
- lib/alphabetical_paginate/array.rb
|
61
99
|
- lib/alphabetical_paginate/engine.rb
|
62
100
|
- lib/alphabetical_paginate/railtie.rb
|
63
101
|
- lib/alphabetical_paginate/version.rb
|
64
102
|
- lib/alphabetical_paginate/view_helpers.rb
|
103
|
+
- spec/.alpha_example.rb.swp
|
104
|
+
- spec/.alphabetical_paginate_spec.rb.swp
|
105
|
+
- spec/alpha_example.rb
|
106
|
+
- spec/alphabetical_paginate_spec.rb
|
107
|
+
- spec/support/.helpers.rb.swp
|
108
|
+
- spec/support/helpers.rb
|
65
109
|
- vendor/assets/javascripts/alphabetical_paginate.js
|
66
110
|
- vendor/assets/javascripts/index.js
|
67
111
|
homepage: http://google.com
|
@@ -89,4 +133,10 @@ rubygems_version: 1.8.25
|
|
89
133
|
signing_key:
|
90
134
|
specification_version: 3
|
91
135
|
summary: Pagination
|
92
|
-
test_files:
|
136
|
+
test_files:
|
137
|
+
- spec/.alpha_example.rb.swp
|
138
|
+
- spec/.alphabetical_paginate_spec.rb.swp
|
139
|
+
- spec/alpha_example.rb
|
140
|
+
- spec/alphabetical_paginate_spec.rb
|
141
|
+
- spec/support/.helpers.rb.swp
|
142
|
+
- spec/support/helpers.rb
|