dimples 13.1.2 → 14.0.0
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 +10 -10
- data/lib/dimples/site.rb +2 -2
- data/lib/dimples/template.rb +2 -0
- 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: 0cd730bee9db2d40308b4d6d5154ce35244821b905902e7bd395452aaf726ec5
|
|
4
|
+
data.tar.gz: e04f9a1b4a538f9aab53ef2d4db00a9309f9cd6f8ac24372c23d908e21970a52
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 850ea7a7863edd50da38a88c485d3d09e3456581cabf3636a2751def1e5d099e8dc98ef4a49227018231754a59c9823cbaed39e59f04647137fe6c48316bdb12
|
|
7
|
+
data.tar.gz: 23d23a7c7b6ce4807f8b604043789fde1758782a7e2a5972d73a64b23a4a44e7cefa11bd9d3497d30d4e996b76d227dddf660204e014635308f19d8ce492bc15
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Dimples
|
|
4
|
-
# A class for paginating a collection of
|
|
4
|
+
# A class for paginating a collection of items.
|
|
5
5
|
class Pager
|
|
6
6
|
include Enumerable
|
|
7
7
|
|
|
@@ -9,17 +9,17 @@ module Dimples
|
|
|
9
9
|
|
|
10
10
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
|
11
11
|
|
|
12
|
-
def self.paginate(url:,
|
|
13
|
-
new(url: url,
|
|
12
|
+
def self.paginate(url:, items:, options: {}, payload: {}, &block)
|
|
13
|
+
new(url: url, items: items, options: options).paginate(payload: payload, &block)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def initialize(url:,
|
|
16
|
+
def initialize(url:, items:, options: {})
|
|
17
17
|
@url = url
|
|
18
18
|
@url << '/' unless @url[-1] == '/'
|
|
19
19
|
|
|
20
|
-
@
|
|
20
|
+
@items = items
|
|
21
21
|
@options = DEFAULT_OPTIONS.merge(options)
|
|
22
|
-
@page_count = (
|
|
22
|
+
@page_count = (items.length.to_f / @options[:per_page].to_i).ceil
|
|
23
23
|
|
|
24
24
|
step_to(1)
|
|
25
25
|
end
|
|
@@ -40,8 +40,8 @@ module Dimples
|
|
|
40
40
|
@current_page
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def
|
|
44
|
-
@
|
|
43
|
+
def items_at(page)
|
|
44
|
+
@items.slice((page - 1) * @options[:per_page], @options[:per_page])
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def previous_page?
|
|
@@ -90,11 +90,11 @@ module Dimples
|
|
|
90
90
|
|
|
91
91
|
def metadata
|
|
92
92
|
{
|
|
93
|
-
posts: posts_at(current_page),
|
|
94
93
|
pagination: Context.from_hash(
|
|
94
|
+
items: items_at(current_page),
|
|
95
95
|
current_page: @current_page,
|
|
96
96
|
page_count: @page_count,
|
|
97
|
-
|
|
97
|
+
item_count: @items.count,
|
|
98
98
|
previous_page: @previous_page,
|
|
99
99
|
next_page: @next_page,
|
|
100
100
|
urls: urls
|
data/lib/dimples/site.rb
CHANGED
|
@@ -96,7 +96,7 @@ module Dimples
|
|
|
96
96
|
|
|
97
97
|
url = @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/')
|
|
98
98
|
|
|
99
|
-
Pager.paginate(url: url,
|
|
99
|
+
Pager.paginate(url: url, items: posts, options: @config.pagination) do |url, payload|
|
|
100
100
|
templates[:posts].generate(
|
|
101
101
|
output_path: File.join(@config.build_paths[:root], url),
|
|
102
102
|
payload: payload
|
|
@@ -134,7 +134,7 @@ module Dimples
|
|
|
134
134
|
categories.each do |category, posts|
|
|
135
135
|
Pager.paginate(
|
|
136
136
|
url: "/categories/#{category}/",
|
|
137
|
-
|
|
137
|
+
items: posts,
|
|
138
138
|
payload: { title: category.capitalize, category: category },
|
|
139
139
|
options: @config.pagination
|
|
140
140
|
) do |url, payload|
|
data/lib/dimples/template.rb
CHANGED
data/lib/dimples/version.rb
CHANGED