octopress-paginate 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e51b533c9a6bd3891a2ebb123e591dbe2cd9b4d
4
- data.tar.gz: 824b2087235013b04bea4392847660c9486e5696
3
+ metadata.gz: beb5d4ee3e941d744aee3f99b22c7723a20685c4
4
+ data.tar.gz: b87404e4acae09cc52761909ae5076a4d3132695
5
5
  SHA512:
6
- metadata.gz: d374f7bd5aaf4570dd6137ef8c3f53b335b689aa533668a03352c55aba1d46480af3ab4faa8c9a86a1709b3d0c2c790e22d46857bf432ff456f8dbcc13f58004
7
- data.tar.gz: 072069d8e94b0d55c029a0ba6a41b6fdfdf95750a942ede3f379c7683d2ade00bf3f078d847484a5bc124fa866e1af9a1bb6a8a62c6f33eb4bc9e13c3be5d9f9
6
+ metadata.gz: ada480c93b4a62c44eae073690f13d8d35aa057f4febf88436882430e2136e572bcf9843943359d4e0bb55c29ee6c5d879c81f12c81efae62ca5e3ad99f40115
7
+ data.tar.gz: 16e17a538b19aaaba378524f8cdfa99605260a7d7ab4bbc759cc604a7bf2ec5fb1a28ac7eaeff4df314e746bc6365841b879e4a13d5ac687c6195325da9ad823
@@ -20,6 +20,12 @@ module Octopress
20
20
  # Simple Page class override
21
21
  class PaginationPage < Jekyll::Page
22
22
  attr_accessor :dir, :name
23
+
24
+ def relative_asset_path
25
+ site_source = Pathname.new Octopress.site.source
26
+ page_source = Pathname.new @base
27
+ page_source.relative_path_from(site_source).to_s
28
+ end
23
29
  end
24
30
 
25
31
  def paginate(page)
@@ -57,19 +63,17 @@ module Octopress
57
63
 
58
64
  pages.times do |i|
59
65
  index = i+2
60
- new_page = PaginationPage.new(page.site, page.site.source, File.dirname(page.path), File.basename(page.path))
61
- new_page.process('index.html')
62
- new_page.data.delete('permalink')
63
-
64
- new_page.data.merge!({'paginate' => page.data['paginate'].clone})
65
- new_page.data['paginate']['page_num'] = index
66
66
 
67
- title = page.data['title'].clone || page.data['paginate']['collection'].capitalize
68
- title << page.data['paginate']['title_suffix'].sub(/:num/, index.to_s)
69
- new_page.data['title'] = title
70
-
71
- subdir = page.data['paginate']['permalink'].clone.sub(':num', index.to_s)
72
- new_page.dir = File.join(page.dir, subdir)
67
+ # If page is generated by an Octopress Ink plugin, use the built in
68
+ # methods for cloning the page
69
+ #
70
+ if page.respond_to?(:asset) && page.asset.to_s.match('Octopress::Ink')
71
+ new_page = page.asset.new_page(page_data(page, index))
72
+ else
73
+ new_page = PaginationPage.new(page.site, page.site.source, File.dirname(page.path), File.basename(page.path))
74
+ new_page.data.merge!(page_data(page, index))
75
+ new_page.process('index.html')
76
+ end
73
77
 
74
78
  new_pages << new_page
75
79
  end
@@ -93,10 +97,41 @@ module Octopress
93
97
  page.site.pages.concat new_pages
94
98
  end
95
99
 
100
+ def page_data(page, index)
101
+ {
102
+ 'paginate' => paginate_data(page, index),
103
+ 'permalink' => page_permalink(page, index),
104
+ 'title' => page_title(page, index),
105
+ }
106
+ end
107
+
108
+ def page_permalink(page, index)
109
+ subdir = page.data['paginate']['permalink'].clone.sub(':num', index.to_s)
110
+ File.join(page.dir, subdir)
111
+ end
112
+
113
+ def paginate_data(page, index)
114
+ paginate_data = page.data['paginate'].clone
115
+ paginate_data['page_num'] = index
116
+ paginate_data
117
+ end
118
+
119
+ def page_title(page, index)
120
+ title = if page.data['title']
121
+ page.data['title']
122
+ else
123
+ page.data['paginate']['collection'].capitalize
124
+ end
125
+
126
+ title += page.data['paginate']['title_suffix'].sub(/:num/, index.to_s)
127
+
128
+ title
129
+ end
130
+
96
131
  def collection(page)
97
132
  collection = if page['paginate']['collection'] == 'posts'
98
133
  if defined?(Octopress::Multilingual) && page.lang
99
- page.site.posts_by_language[page.lang]
134
+ page.site.posts_by_language(page.lang)
100
135
  else
101
136
  page.site.posts.reverse
102
137
  end
@@ -1,6 +1,8 @@
1
1
  module Octopress
2
2
  module Paginate
3
3
  class SiteHook < Hooks::Site
4
+ priority :low
5
+
4
6
  def post_read(site)
5
7
  site.pages.select {|p| p.data['paginate'] }.each do |page|
6
8
  Octopress::Paginate.paginate(page)
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Paginate
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-27 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octopress-hooks