diff --git a/Gemfile b/Gemfile index d82aae8..1c6d736 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,4 @@ source 'https://rubygems.org' # Specify your gem's dependencies in octopress-paginate.gemspec gemspec +gem 'jekyll', '~> 3.0.0.alpha' diff --git a/lib/octopress-paginate.rb b/lib/octopress-paginate.rb index d868d1b..a34e1da 100644 --- a/lib/octopress-paginate.rb +++ b/lib/octopress-paginate.rb @@ -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 @@ -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'], @@ -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) diff --git a/lib/octopress-paginate/hooks.rb b/lib/octopress-paginate/hooks.rb index 722d12b..63e06ef 100644 --- a/lib/octopress-paginate/hooks.rb +++ b/lib/octopress-paginate/hooks.rb @@ -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| 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 diff --git a/octopress-paginate.gemspec b/octopress-paginate.gemspec index c8c9c0f..9b2ffa6 100644 --- a/octopress-paginate.gemspec +++ b/octopress-paginate.gemspec @@ -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" @@ -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 diff --git a/test/collection/.jekyll-metadata b/test/collection/.jekyll-metadata new file mode 100644 index 0000000..4bbf510 Binary files /dev/null and b/test/collection/.jekyll-metadata differ diff --git a/test/filter-category/.jekyll-metadata b/test/filter-category/.jekyll-metadata new file mode 100644 index 0000000..9f31eb5 Binary files /dev/null and b/test/filter-category/.jekyll-metadata differ diff --git a/test/limit/.jekyll-metadata b/test/limit/.jekyll-metadata new file mode 100644 index 0000000..12bac8e Binary files /dev/null and b/test/limit/.jekyll-metadata differ diff --git a/test/multilingual/.jekyll-metadata b/test/multilingual/.jekyll-metadata new file mode 100644 index 0000000..e5618e2 Binary files /dev/null and b/test/multilingual/.jekyll-metadata differ diff --git a/test/no-limit/.jekyll-metadata b/test/no-limit/.jekyll-metadata new file mode 100644 index 0000000..ad6dfe9 Binary files /dev/null and b/test/no-limit/.jekyll-metadata differ diff --git a/test/site-config/.jekyll-metadata b/test/site-config/.jekyll-metadata new file mode 100644 index 0000000..e02970b Binary files /dev/null and b/test/site-config/.jekyll-metadata differ diff --git a/test/standard/.jekyll-metadata b/test/standard/.jekyll-metadata new file mode 100644 index 0000000..0daf70d Binary files /dev/null and b/test/standard/.jekyll-metadata differ