dimples 11.0.0 → 11.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 +4 -4
- data/lib/dimples/pager.rb +11 -12
- data/lib/dimples/site.rb +3 -2
- data/lib/dimples/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f1d981c9f939077c2f4adc12e16ab8247cd3265eb9fcdef78bbe8b98edbd9a8b
|
|
4
|
+
data.tar.gz: 59ee25fcbed829882e7da7f590cb52124f00e49ea6ed13a8e6c0c3a6227cd645
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b099e52f6d5940af4ba514ef72333d09b71de7b00804980455ef2b17f7078b6ded70e5852aed00c863c87d0f35a58028ffa98ad20bed338084c8598e83cdaaa
|
|
7
|
+
data.tar.gz: 2dcaade059713c73f0d690a7a483cb5f21761164be764cdf3ebe8deffa411b0151e98fb4deb38402220c1556cb0c339e084c50f4082cf1268c5cc6ecacd55082
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -5,22 +5,21 @@ module Dimples
|
|
|
5
5
|
class Pager
|
|
6
6
|
include Enumerable
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
DEFAULT_OPTIONS = { per_page: 5, page_prefix: 'page_' }.freeze
|
|
9
9
|
|
|
10
10
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
|
11
11
|
|
|
12
|
-
def self.paginate(url:, posts:,
|
|
13
|
-
new(url: url, posts: posts).paginate(context: context, &block)
|
|
12
|
+
def self.paginate(url:, posts:, options: {}, context: {}, &block)
|
|
13
|
+
new(url: url, posts: posts, options: options).paginate(context: context, &block)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def initialize(url:, posts:,
|
|
16
|
+
def initialize(url:, posts:, options: {})
|
|
17
17
|
@url = url
|
|
18
18
|
@url << '/' unless @url[-1] == '/'
|
|
19
19
|
|
|
20
20
|
@posts = posts
|
|
21
|
-
|
|
22
|
-
@
|
|
23
|
-
@page_count = (posts.length.to_f / @per_page.to_i).ceil
|
|
21
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
|
22
|
+
@page_count = (posts.length.to_f / @options[:per_page].to_i).ceil
|
|
24
23
|
|
|
25
24
|
step_to(1)
|
|
26
25
|
end
|
|
@@ -42,7 +41,7 @@ module Dimples
|
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
def posts_at(page)
|
|
45
|
-
@posts.slice((page - 1) * @per_page, @per_page)
|
|
44
|
+
@posts.slice((page - 1) * @options[:per_page], @options[:per_page])
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def previous_page?
|
|
@@ -58,7 +57,7 @@ module Dimples
|
|
|
58
57
|
end
|
|
59
58
|
|
|
60
59
|
def current_page_url
|
|
61
|
-
@current_page == 1 ? @url : "#{@url}
|
|
60
|
+
@current_page == 1 ? @url : "#{@url}#{@options[:page_prefix]}#{@current_page}"
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
def first_page_url
|
|
@@ -66,17 +65,17 @@ module Dimples
|
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
def last_page_url
|
|
69
|
-
@page_count == 1 ? @url : "#{@url}
|
|
68
|
+
@page_count == 1 ? @url : "#{@url}#{@options[:page_prefix]}#{@page_count}"
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
def previous_page_url
|
|
73
72
|
return unless @previous_page
|
|
74
73
|
|
|
75
|
-
@previous_page == 1 ? @url : "#{@url}
|
|
74
|
+
@previous_page == 1 ? @url : "#{@url}#{@options[:page_prefix]}#{@previous_page}"
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
def next_page_url
|
|
79
|
-
"#{@url}
|
|
78
|
+
"#{@url}#{@options[:page_prefix]}#{@next_page}" if @next_page
|
|
80
79
|
end
|
|
81
80
|
|
|
82
81
|
def urls
|
data/lib/dimples/site.rb
CHANGED
|
@@ -70,7 +70,7 @@ module Dimples
|
|
|
70
70
|
|
|
71
71
|
url = @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/')
|
|
72
72
|
|
|
73
|
-
Pager.paginate(url: url, posts: posts) do |url, page_context|
|
|
73
|
+
Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url, page_context|
|
|
74
74
|
generate_entry(
|
|
75
75
|
entry: templates[:posts],
|
|
76
76
|
output_path: File.join(@config.build_paths[:root], url),
|
|
@@ -110,7 +110,8 @@ module Dimples
|
|
|
110
110
|
Pager.paginate(
|
|
111
111
|
url: "/categories/#{category}/",
|
|
112
112
|
posts: posts,
|
|
113
|
-
context: context
|
|
113
|
+
context: context,
|
|
114
|
+
options: @config.pagination
|
|
114
115
|
) do |url, page_context|
|
|
115
116
|
generate_entry(
|
|
116
117
|
entry: templates[:posts],
|
data/lib/dimples/version.rb
CHANGED