leaf 0.1.0 → 0.1.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.
- data/README.rdoc +36 -8
- data/lib/leaf/version.rb +1 -1
- data/lib/leaf/view_helpers/base.rb +0 -67
- metadata +7 -25
- data/locales/en.yml +0 -11
- data/locales/sv.yml +0 -11
data/README.rdoc
CHANGED
@@ -1,18 +1,46 @@
|
|
1
1
|
= Leaf
|
2
2
|
|
3
|
-
A _really_ simple pagination library
|
3
|
+
A _really_ simple pagination library, heavily based on the agnostic branch of
|
4
|
+
{will_paginate}[http://github.com/mislav/will_paginate/tree/agnostic].
|
5
|
+
|
6
|
+
= Description
|
7
|
+
|
8
|
+
Leaf supports pagination for collections responding to +total_pages+,
|
9
|
+
+per_page+, +previous_page+ and +total_entries+ in Sinatra views out of the box.
|
4
10
|
|
5
11
|
== Installation
|
6
|
-
|
7
|
-
The recommended way is that you get the gem
|
8
12
|
|
9
13
|
gem install leaf
|
10
|
-
|
14
|
+
|
11
15
|
== Example usage
|
12
16
|
|
17
|
+
require 'rubygems'
|
18
|
+
require 'sinatra'
|
19
|
+
require 'leaf'
|
20
|
+
|
21
|
+
include Leaf::ViewHelpers::Base
|
22
|
+
|
23
|
+
# Needed to paginate any array, you’ll probably use something else.
|
24
|
+
require 'leaf/array'
|
25
|
+
|
26
|
+
get '/' do
|
27
|
+
page = (params[:page]) ? params[:page] : 1
|
28
|
+
array = ('a'..'z').to_a
|
29
|
+
|
30
|
+
haml :index, :locals => {
|
31
|
+
:collection => array.paginate({:page => page, :per_page => 5})
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
__END__
|
36
|
+
@@ index
|
37
|
+
= leaf(collection)
|
38
|
+
%ul
|
39
|
+
- collection.each do |letter|
|
40
|
+
%li= letter
|
41
|
+
|
13
42
|
== Authors and credits
|
14
43
|
|
15
|
-
Leaf is
|
16
|
-
|
17
|
-
|
18
|
-
development to Mislav Marohnić. (The library was completely rewritten since then.)
|
44
|
+
Leaf is based on {will_paginate}[http://github.com/mislav/will_paginate/] which
|
45
|
+
was originally written by PJ Hyett, who later handed over development to Mislav
|
46
|
+
Marohnić. (The library was completely rewritten since then.)
|
data/lib/leaf/version.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
require 'i18n'
|
2
1
|
require 'leaf/core_ext'
|
3
2
|
require 'leaf/view_helpers'
|
4
3
|
|
5
|
-
# REPLACE WITH REAL CODE :)
|
6
|
-
['sv', 'en'].each do |locale|
|
7
|
-
I18n.load_path << "locales/#{locale}.yml"
|
8
|
-
end
|
9
|
-
|
10
4
|
module Leaf
|
11
5
|
module ViewHelpers
|
12
6
|
# = The main view helpers module
|
@@ -63,67 +57,6 @@ module Leaf
|
|
63
57
|
renderer.prepare collection, options, self
|
64
58
|
renderer.to_html
|
65
59
|
end
|
66
|
-
|
67
|
-
# Renders a helpful message with numbers of displayed vs. total entries.
|
68
|
-
# You can use this as a blueprint for your own, similar helpers.
|
69
|
-
#
|
70
|
-
# <%= page_entries_info @posts %>
|
71
|
-
# #-> Displaying posts 6 - 10 of 26 in total
|
72
|
-
#
|
73
|
-
# By default, the message will use the humanized class name of objects
|
74
|
-
# in collection: for instance, "project types" for ProjectType models.
|
75
|
-
# Override this to your liking with the <tt>:entry_name</tt> parameter:
|
76
|
-
#
|
77
|
-
# <%= page_entries_info @posts, :entry_name => 'item' %>
|
78
|
-
# #-> Displaying items 6 - 10 of 26 in total
|
79
|
-
#
|
80
|
-
# Entry name is entered in singular and pluralized with
|
81
|
-
# <tt>String#pluralize</tt> method from ActiveSupport. If it isn't
|
82
|
-
# loaded, specify plural with <tt>:plural_name</tt> parameter:
|
83
|
-
#
|
84
|
-
# <%= page_entries_info @posts, :entry_name => 'item', :plural_name => 'items' %>
|
85
|
-
#
|
86
|
-
# By default, this method produces HTML output. You can trigger plain
|
87
|
-
# text output by passing <tt>:html => false</tt> in options.
|
88
|
-
def page_entries_info(collection, options = {})
|
89
|
-
entry_name = options[:entry_name] || (collection.empty?? 'entry' :
|
90
|
-
collection.first.class.name.underscore.gsub('_', ' '))
|
91
|
-
|
92
|
-
plural_name = if options[:plural_name]
|
93
|
-
options[:plural_name]
|
94
|
-
elsif entry_name == 'entry'
|
95
|
-
plural_name = 'entries'
|
96
|
-
elsif entry_name.respond_to? :pluralize
|
97
|
-
plural_name = entry_name.pluralize
|
98
|
-
else
|
99
|
-
entry_name + 's'
|
100
|
-
end
|
101
|
-
|
102
|
-
unless options[:html] == false
|
103
|
-
b = '<b>'
|
104
|
-
eb = '</b>'
|
105
|
-
sp = ' '
|
106
|
-
else
|
107
|
-
b = eb = ''
|
108
|
-
sp = ' '
|
109
|
-
end
|
110
|
-
|
111
|
-
if collection.total_pages < 2
|
112
|
-
case collection.size
|
113
|
-
when 0; I18n::t('leaf.page_entries_info.one_page.nothing', :plural_name => plural_name)
|
114
|
-
when 1; I18n::t('leaf.page_entries_info.one_page.one', :b => b, :eb => eb, :entry_name => entry_name)
|
115
|
-
else; I18n::t('leaf.page_entries_info.one_page.many', :b => b, :collection_size => collection.size, :eb => eb, :plural_name => plural_name)
|
116
|
-
end
|
117
|
-
else
|
118
|
-
I18n::t('leaf.page_entries_info.default',
|
119
|
-
:plural_name => plural_name,
|
120
|
-
:b => b, :sp => sp, :eb => eb,
|
121
|
-
:from_number => (collection.offset + 1),
|
122
|
-
:to_number => (collection.offset + collection.length),
|
123
|
-
:total_entries => collection.total_entries
|
124
|
-
)
|
125
|
-
end
|
126
|
-
end
|
127
60
|
end
|
128
61
|
end
|
129
62
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Hellberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-28 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,23 +34,7 @@ dependencies:
|
|
34
34
|
version: 1.2.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
-
|
38
|
-
name: i18n
|
39
|
-
prerelease: false
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 15
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 4
|
49
|
-
- 0
|
50
|
-
version: 0.4.0
|
51
|
-
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
description: A really simple pagination library for Sinatra
|
37
|
+
description: A really simple pagination library, heavily based on the agnostic branch of will_paginate
|
54
38
|
email: peter@c7.se
|
55
39
|
executables: []
|
56
40
|
|
@@ -73,13 +57,11 @@ files:
|
|
73
57
|
- lib/leaf/view_helpers/sinatra.rb
|
74
58
|
- lib/leaf/view_helpers.rb
|
75
59
|
- lib/leaf.rb
|
76
|
-
- locales/en.yml
|
77
|
-
- locales/sv.yml
|
78
60
|
- MIT-LICENSE
|
79
61
|
- Rakefile
|
80
62
|
- README.rdoc
|
81
63
|
has_rdoc: true
|
82
|
-
homepage: http://github.com/
|
64
|
+
homepage: http://c7.github.com/leaf/
|
83
65
|
licenses:
|
84
66
|
- MIT-LICENSE
|
85
67
|
post_install_message:
|
@@ -113,6 +95,6 @@ rubyforge_project: leaf
|
|
113
95
|
rubygems_version: 1.3.7
|
114
96
|
signing_key:
|
115
97
|
specification_version: 3
|
116
|
-
summary: Simple
|
98
|
+
summary: Simple pagination library
|
117
99
|
test_files: []
|
118
100
|
|
data/locales/en.yml
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# English
|
2
|
-
en:
|
3
|
-
leaf:
|
4
|
-
next_label: "Next →"
|
5
|
-
previous_label: "← Previous"
|
6
|
-
page_entries_info:
|
7
|
-
one_page:
|
8
|
-
nothing: "No %{plural_name} found"
|
9
|
-
one: "Displaying %{b}1%{eb} %{entry_name}"
|
10
|
-
many: "Displaying %{b}all %{collection_size}%{eb} %{plural_name}"
|
11
|
-
default: "Displaying %{plural_name} %{b}%{from_number}%{sp}-%{sp}%{to_number}%{eb} of %{b}%{total_entries}%{eb} in total"
|
data/locales/sv.yml
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# Swedish
|
2
|
-
sv:
|
3
|
-
leaf:
|
4
|
-
next_label: "Nästa →"
|
5
|
-
previous_label: "← Föregående"
|
6
|
-
page_entries_info:
|
7
|
-
one_page:
|
8
|
-
nothing: "Hittade inga %{plural_name}"
|
9
|
-
one: "Visar %{b}1%{eb} %{entry_name}"
|
10
|
-
many: "Visar %{b}alla %{collection_size}%{eb} %{plural_name}"
|
11
|
-
default: "Visar %{plural_name} %{b}%{from_number}%{sp}-%{sp}%{to_number}%{eb} av totalt %{b}%{total_entries}%{eb}"
|