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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c840b0dffbd13241c53322349b2d4d8cc27702fd24e23e634f8aa3c68ccb7ef
4
- data.tar.gz: a84f8dd4b99af20ad44a60bc42e4155731ed34aadd245987552f105cbc744ad2
3
+ metadata.gz: f1d981c9f939077c2f4adc12e16ab8247cd3265eb9fcdef78bbe8b98edbd9a8b
4
+ data.tar.gz: 59ee25fcbed829882e7da7f590cb52124f00e49ea6ed13a8e6c0c3a6227cd645
5
5
  SHA512:
6
- metadata.gz: 81dfeb441b90d5861bb75353317e71f9e528a6d6008f221f65af1b5ab98529d0046afc0fdf4bcb2cbb7507d94546784dea360366e427a0394664cbecf19c8f7b
7
- data.tar.gz: f66eaa19302fe7c177160fb935fdab210d6e6c02afbeee936ae80880b1a225de94c3432433cee4773b3d4667d111903aaf552d6e7c0955b8f5662e22b1e28209
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
- DEFAULT_PER_PAGE = 5
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:, per_page: DEFAULT_PER_PAGE, context: {}, &block)
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:, per_page: DEFAULT_PER_PAGE)
16
+ def initialize(url:, posts:, options: {})
17
17
  @url = url
18
18
  @url << '/' unless @url[-1] == '/'
19
19
 
20
20
  @posts = posts
21
-
22
- @per_page = per_page
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}page_#{@current_page}"
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}page_#{@page_count}"
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}page_#{@previous_page}"
74
+ @previous_page == 1 ? @url : "#{@url}#{@options[:page_prefix]}#{@previous_page}"
76
75
  end
77
76
 
78
77
  def next_page_url
79
- "#{@url}page_#{@next_page}" if @next_page
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],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '11.0.0'
4
+ VERSION = '11.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.0
4
+ version: 11.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan