Skip to content

Commit

Permalink
Support Jekyll 3.1.x
Browse files Browse the repository at this point in the history
For Jekyll versions 3.0 or greater, use the new Jekyll hooks
functionality rather than relying on monkey-patching Jekyll rendering
internals. This fixes the incompatibilities with the changes introduced
in Jekyll 3.1.
  • Loading branch information
Rusty Geldmacher committed Feb 25, 2016
1 parent 4f82361 commit 5d9f075
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.1.1
4 changes: 4 additions & 0 deletions Appraisals
Expand Up @@ -49,3 +49,7 @@ end
appraise "jekyll-3.0.3" do
gem "jekyll", "3.0.3"
end

appraise "jekyll-3.1.2" do
gem "jekyll", "3.1.2"
end
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'jekyll', '> 1.0.0'
gem 'jekyll', '3.1.2'
gem 'appraisal', '1.0.2'

gem 'pry'
Expand Down
14 changes: 4 additions & 10 deletions README.md
@@ -1,4 +1,3 @@
# NOTE: Currently does not work with Jekyll 3.1.x -- for a temporary fix, please try using Jekyll 3.0.3
# jekyll-contentblocks

Gives you a mechanism in Jekyll to pass content up from pages into their parent
Expand All @@ -10,23 +9,18 @@ layouts. It's kind of like having Rails' content_for available for Jekyll.

Add this line to your Jekyll project's `Gemfile`:
```ruby
gem 'jekyll-contentblocks'
group :jekyll_plugins do
gem 'jekyll-contentblocks'
end
```

Then execute:
```bash
$ bundle install
```

Make sure your have a plugin that initializes Bundler:
```ruby
# _plugins/bundler.rb
require "rubygems"
require "bundler/setup"
Bundler.require(:default)
```

### Standalone

Execute:
```bash
$ gem install jekyll-contentblocks
Expand Down
12 changes: 12 additions & 0 deletions gemfiles/jekyll_3.1.2.gemfile
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "jekyll", "3.1.2"
gem "appraisal", "1.0.2"
gem "pry"
gem "pry-byebug"
gem "rspec", "~> 3.3.0"
gem "nokogiri", "~> 1.6.6.0"

gemspec :path => "../"
15 changes: 12 additions & 3 deletions lib/jekyll-contentblocks.rb
Expand Up @@ -10,9 +10,18 @@ def self.supports_collections?
end
end

require 'jekyll/content_blocks/convertible'
unless Jekyll.version_less_than?('2.0.0')
require 'jekyll/content_blocks/renderer'
if Jekyll.version_less_than?('3.0.0')
require 'jekyll/content_blocks/convertible'
unless Jekyll.version_less_than?('2.0.0')
require 'jekyll/content_blocks/renderer'
end
else
require 'jekyll/content_blocks/pre_render_hook'
[:documents, :pages, :posts].each do |content_type|
Jekyll::Hooks.register content_type, :pre_render do |doc, payload|
Jekyll::ContentBlocks::PreRenderHook.call(doc, payload)
end
end
end

require 'jekyll/content_blocks/version'
Expand Down
13 changes: 13 additions & 0 deletions lib/jekyll/content_blocks/pre_render_hook.rb
@@ -0,0 +1,13 @@
module Jekyll
module ContentBlocks
class PreRenderHook
def self.call(document, payload)
payload['converters'] = document.site.converters.select do |converter|
file_extension = File.extname(document.path)
converter.matches(file_extension)
end
payload['contentblocks'] = {}
end
end
end
end
2 changes: 1 addition & 1 deletion lib/jekyll/content_blocks/version.rb
@@ -1,6 +1,6 @@
module Jekyll
module ContentBlocks
VERSION = "1.1.0"
VERSION = "1.2.0"
end
end

4 changes: 0 additions & 4 deletions test/_plugins/bundler.rb

This file was deleted.

2 changes: 2 additions & 0 deletions test/_plugins/require.rb
@@ -0,0 +1,2 @@
require 'jekyll-contentblocks'

0 comments on commit 5d9f075

Please sign in to comment.