Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Jekyll3 Support #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in octopress-paginate.gemspec
gemspec
gem 'jekyll', '~> 3.0.0.alpha'
10 changes: 7 additions & 3 deletions lib/octopress-paginate.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require "octopress-hooks"
require "octopress-paginate/version"
require "octopress-paginate/hooks"

begin
require "octopress-debugger"
rescue LoadError; end


module Octopress
module Paginate
extend self
Expand Down Expand Up @@ -153,7 +157,7 @@ def collection(page)
def page_payload(payload, page)
config = page.data['paginate']
collection = collection(page)
{ 'paginator' => {
{
"#{config['collection']}" => items(payload, collection),
"page" => config['page_num'],
"per_page" => config['per_page'],
Expand All @@ -164,7 +168,7 @@ def page_payload(payload, page)
'previous_page_path' => config['previous_page_path'],
'next_page' => config['next_page'],
'next_page_path' => config['next_page_path']
}}
}
end

def items(payload, collection)
Expand Down
32 changes: 23 additions & 9 deletions lib/octopress-paginate/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
module Octopress
module Paginate
class SiteHook < Hooks::Site
priority :low

def post_read(site)
if defined?(Jekyll::Hooks)
Jekyll::Hooks.register :site, :post_read, priority: :low do |site|
site.pages.select {|p| p.data['paginate'] }.each do |page|
Octopress::Paginate.paginate(page)
end
end
end

class PageHook < Hooks::Page
def merge_payload(payload, page)
Jekyll::Hooks.register :page, :pre_render do |page, payload|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be :pages not :page

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshick technically that's a yes, but soon it's a no, we plan on having aliases and this will be one of them, unless @parkr changed his mind with my plan to add hook aliases to ease developer pain with hooks, his hooks will continue to work soon.

if page.data['paginate']
Octopress::Paginate.page_payload(payload, page)
payload['paginator'] = Octopress::Paginate.page_payload(payload, page)
end
end
else
require 'octopress-hooks'
class SiteHook < Hooks::Site
priority :low

def post_read(site)
site.pages.select {|p| p.data['paginate'] }.each do |page|
Octopress::Paginate.paginate(page)
end
end
end

class PageHook < Hooks::Page
def merge_payload(payload, page)
if page.data['paginate']
payload['paginator'] = Octopress::Paginate.page_payload(payload, page)
end
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions octopress-paginate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "octopress-hooks"
#spec.add_runtime_dependency "octopress-hooks"
spec.add_runtime_dependency "jekyll"

spec.add_development_dependency "clash"
spec.add_development_dependency "bundler", "~> 1.7"
Expand All @@ -26,6 +27,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "octopress"

if RUBY_VERSION >= "2"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "octopress-debugger"
end
end
Binary file added test/collection/.jekyll-metadata
Binary file not shown.
Binary file added test/filter-category/.jekyll-metadata
Binary file not shown.
Binary file added test/limit/.jekyll-metadata
Binary file not shown.
Binary file added test/multilingual/.jekyll-metadata
Binary file not shown.
Binary file added test/no-limit/.jekyll-metadata
Binary file not shown.
Binary file added test/site-config/.jekyll-metadata
Binary file not shown.
Binary file added test/standard/.jekyll-metadata
Binary file not shown.