leaflet 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/leaflet/collection.rb +5 -4
- data/lib/leaflet/configuration.rb +2 -2
- data/lib/leaflet/version.rb +1 -1
- data/lib/leaflet.rb +0 -28
- metadata +18 -3
- data/spec/lib/leaflet_spec.rb +0 -46
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/bukowskis/leaflet.png)](https://travis-ci.org/bukowskis/leaflet)
|
2
|
+
|
1
3
|
# Leaflet
|
2
4
|
|
3
5
|
A very robust light-weight paginator based on [leaf](http://github.com/c7/leaf) which is based on [will_paginate](http://github.com/mislav/will_paginate).
|
data/lib/leaflet/collection.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'positify'
|
1
2
|
require 'leaflet/configuration'
|
2
3
|
|
3
4
|
module Leaflet
|
@@ -39,21 +40,21 @@ module Leaflet
|
|
39
40
|
# –––––––––––––––––––––––
|
40
41
|
|
41
42
|
def total_entries
|
42
|
-
|
43
|
+
Positify.it {
|
43
44
|
@total_entries ||= self.size
|
44
45
|
}
|
45
46
|
end
|
46
47
|
alias :total_count :total_entries # Kaminari
|
47
48
|
|
48
49
|
def per_page
|
49
|
-
|
50
|
+
Positify.it(max: Leaflet.config.max_per_page) {
|
50
51
|
@per_page ||= Leaflet.config.default_per_page
|
51
52
|
}
|
52
53
|
end
|
53
54
|
alias :limit_value :per_page # Kaminari
|
54
55
|
|
55
56
|
def current_page
|
56
|
-
|
57
|
+
Positify.it(max: total_pages) {
|
57
58
|
@current_page ||= 1
|
58
59
|
}
|
59
60
|
end
|
@@ -68,7 +69,7 @@ module Leaflet
|
|
68
69
|
alias :offset_value :offset # Kaminari
|
69
70
|
|
70
71
|
def total_pages
|
71
|
-
|
72
|
+
Positify.it {
|
72
73
|
total_entries.zero? ? 1 : (total_entries / per_page.to_f).ceil
|
73
74
|
}
|
74
75
|
end
|
@@ -6,13 +6,13 @@ module Leaflet
|
|
6
6
|
attr_writer :default_per_page, :max_per_page
|
7
7
|
|
8
8
|
def default_per_page
|
9
|
-
|
9
|
+
Positify.it {
|
10
10
|
@default_per_page ||= 20
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
14
|
def max_per_page
|
15
|
-
|
15
|
+
Positify.it {
|
16
16
|
@max_per_page ||= 30
|
17
17
|
}
|
18
18
|
end
|
data/lib/leaflet/version.rb
CHANGED
data/lib/leaflet.rb
CHANGED
@@ -3,33 +3,5 @@ require 'leaflet/collection'
|
|
3
3
|
require 'leaflet/version'
|
4
4
|
|
5
5
|
module Leaflet
|
6
|
-
|
7
|
-
def self.positify(*args, &block)
|
8
|
-
if block_given?
|
9
|
-
raise(ArgumentError, "You can only pass in one options Hash in block mode, not #{args.inspect}") if args.size > 1
|
10
|
-
object = block.call
|
11
|
-
options = args.shift || {}
|
12
|
-
else
|
13
|
-
case args.size
|
14
|
-
when 1
|
15
|
-
object = args.shift
|
16
|
-
options = {}
|
17
|
-
raise(ArgumentError, "You forgot the brackets in your call. Try: Leaflet.positify(...) do") if object.is_a?(Hash)
|
18
|
-
when 2
|
19
|
-
object = args.shift
|
20
|
-
options = args.shift
|
21
|
-
else
|
22
|
-
raise ArgumentError, "You must pass in an object and may pass in an options Hash, not #{args.inspect}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
options[:max] = positify(options[:max]) if options[:max]
|
27
|
-
|
28
|
-
return 1 unless object.respond_to?(:to_i)
|
29
|
-
result = object.to_i.abs > 0 ? object.to_i.abs : 1
|
30
|
-
result = options[:max] if options[:max] && options[:max] < result
|
31
|
-
result
|
32
|
-
end
|
33
|
-
|
34
6
|
end
|
35
7
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaflet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: positify
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.1
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rspec
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,7 +87,6 @@ files:
|
|
71
87
|
- lib/leaflet/version.rb
|
72
88
|
- lib/leaflet.rb
|
73
89
|
- spec/lib/leaflet/collection_spec.rb
|
74
|
-
- spec/lib/leaflet_spec.rb
|
75
90
|
- spec/spec_helper.rb
|
76
91
|
- README.md
|
77
92
|
homepage: https://github.com/bukowskis/leaflet
|
data/spec/lib/leaflet_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
describe Leaflet do
|
5
|
-
|
6
|
-
describe '.positify' do
|
7
|
-
it 'makes negative numbers positive' do
|
8
|
-
Leaflet.positify(-5).should == 5
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'turns 0 to 1' do
|
12
|
-
Leaflet.positify(0).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns 1 on non Fixnumerable objects' do
|
16
|
-
Leaflet.positify(OpenStruct.new).should == 1
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'chops Floats to Fixnums' do
|
20
|
-
Leaflet.positify(5.9).should == 5
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'sets a ceiling' do
|
24
|
-
Leaflet.positify(30, max: 22).should == 22
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'ignores the ceiling if the value is below it ' do
|
28
|
-
Leaflet.positify(30, max: 35).should == 30
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'block mode' do
|
32
|
-
it 'makes negative numbers positive' do
|
33
|
-
Leaflet.positify { -5 }.should == 5
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'sets a ceiling' do
|
37
|
-
Leaflet.positify(max: 25) { 30 }.should == 25
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'ignores the ceiling if the value is below it ' do
|
41
|
-
Leaflet.positify(max: 35) { 30 }.should == 30
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|