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

prototype of jekyll hooks, encapsulated #3553

Merged
merged 4 commits into from May 10, 2015
Merged

Conversation

stevecrozz
Copy link
Contributor

This is a second attempt at #3498 (adding hooks to Jekyll). In my last attempt @envygeeks had some complaints about the lack of encapsulation. This PR is an attempt to address those concerns and try out a new idea. This is definitely not ready to merge, but I wanted to get some eyes on it before I implement and write tests for the whole thing. The hooks concept is inspired by, but in this instance not perfectly compatible with octopress-hooks, so it's a bit of a departure from #3392 by @parkr, but I think it nicely encapsulates the hook logic.

Here's a practical example of how you could use one of these hooks to do something useful: https://github.com/stevecrozz/featherblade

@parkr
Copy link
Member

parkr commented Mar 8, 2015

Don't worry about the circleci failure.

This looks pretty good! @envygeeks?

@envygeeks
Copy link
Contributor

👍 I like it!

@envygeeks
Copy link
Contributor

Sorry about the 👎 I actually meant to do 👍

@stevecrozz
Copy link
Contributor Author

Great. I'll flesh out the rest of it and add some test coverage.

@stevecrozz
Copy link
Contributor Author

This is a bit more fleshed out now, although still lacking in tests and docs. I did do some one-off tests and it all seems to be working pretty well. Every hook receives the object being "hooked into" as the first argument.

One major difference from octopress-hooks worth pointing out is how I'm dealing with the payload objects just before rendering.

In octopress-hooks, there's a special hook for merging in new payload params. But I took a different approach and just pass the payload as an argument to each of the pre_render hooks. Anyone who implements a pre_render hook will receive the payload object and can modify it there if necessary as well as do any other things that need doing before rendering. pre_render is the only hook that receives a second argument at the moment. @imathis: let me know if you have any thoughts on this, especially if you already rejected this idea for some reason.

Next up is tests and docs, but I'll give this PR a few days to bake in case there's more feedback.

@stevecrozz stevecrozz force-pushed the jekyll-hooks branch 3 times, most recently from 3dd9a3a to 960960e Compare March 14, 2015 04:15
@stevecrozz
Copy link
Contributor Author

I'm working on cucumber tests now. How thorough do these tests need to be? Do we want each hook for every container to have its own test scenario?

@envygeeks
Copy link
Contributor

I say just write them and if there is a problem we'll point it out!

@stevecrozz stevecrozz force-pushed the jekyll-hooks branch 3 times, most recently from 8e42949 to c63551c Compare March 14, 2015 20:31
@stevecrozz
Copy link
Contributor Author

@envygeeks / @parkr I've got cucumber tests and docs written. Do you have any feedback?

@@ -469,6 +469,179 @@ module Jekyll
end
{% endhighlight %}

## Hooks

Copy link
Member

Choose a reason for hiding this comment

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

Can you add an "unreleased" note here? Check out #3556 for an example.

@parkr
Copy link
Member

parkr commented Mar 16, 2015

Unless you have some thoughts, @envygeeks, let's merge and get this out there in a new beta so people can start building for it. Best way to fix bugs is through actual use of the platform.

@stevecrozz
Copy link
Contributor Author

Amended commit to include "unreleased" note in the docs

@parkr parkr mentioned this pull request Mar 16, 2015
7 tasks
@parkr parkr added this to the 3.0 milestone Mar 16, 2015
@alfredxing
Copy link
Member

👍 Nice work on this! We're missing hooks for Documents but that shouldn't be a huge issue.

@imathis
Copy link
Contributor

imathis commented Mar 17, 2015

I'm sorry I'm a bit late to this.

Unless I've overlooked it, this does not include:

  • Site: pre_read, merge_payload
  • Page/Post: merge_payload

For reference here's Octopress's hook timeline.

@stevecrozz
Copy link
Contributor Author

@imathis That's correct. I removed pre_read from my PR while writing the test cases because I couldn't come up with a use case to test that wasn't already covered. There may be some good ones, but I didn't think of any.

As for merge_payload, I did depart from the octopress-hooks approach which is why I was interested in your feedback. I tried to cover the use case of altering the payload using pre_render which passes the payload to the callback as its second parameter. There's less code and less to test in this approach and it seems more flexible, but I'd be interested to know if I missed a good reason to implement it the way you already did.

@parkr
Copy link
Member

parkr commented Mar 30, 2015

@imathis ^^?

@imathis
Copy link
Contributor

imathis commented Mar 31, 2015

I'm going to create a branch of octopress-hooks that translates hooks to be based on this. If my tests pass. 👍 Let's see how long this takes :)

@envygeeks
Copy link
Contributor

Can we focus more on what we need and less on what we have?

@imathis
Copy link
Contributor

imathis commented Mar 31, 2015

@envygeeks I'm focusing on what I need. I built the features in Octopress hooks because I needed them. If I can keep that functionality, I'll be good to go. Otherwise I'll have to keep monkey patching my own hooks.

@envygeeks
Copy link
Contributor

@imathis Well if you run into trouble then please do post the hooks that are failing and where they originate and are used at so I might be able to help you two come to compromise by possibly reworking both sides to see if we can fit your hooks into his hook system or if we need to truly have him change his hook system.

@stevecrozz
Copy link
Contributor Author

This should address all the feedback @imathis. Just in time for JekyllConf!

@@ -175,11 +175,15 @@ def destination(base_directory)
#
# Returns nothing.
def write(dest)
Jekyll::Hooks.trigger self, :post_render
Copy link
Member

Choose a reason for hiding this comment

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

Why not put this at the end of render?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine with me. It's here just to match the behavior of octopress hooks:
https://github.com/octopress/hooks/blob/master/lib/octopress-hooks.rb#L256

I'm fine with moving it though. Do you still want me to do that?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think it'd make more sense. :)

@parkr
Copy link
Member

parkr commented May 2, 2015

Thanks for all your work on this, @stevecrozz!! ✨

Any other thoughts, @jekyll/core and @imathis?

@envygeeks
Copy link
Contributor

My only complaint is that defaults aren't on the surface API, we are seeping nil through the stack into internal API's and then setting defaults. I think that's obscure design and we should surface every default we have on the layer that is public making everything obvious.

@parkr
Copy link
Member

parkr commented May 2, 2015

I would tend to agree, Jordon! Which defaults, specifically?

- change site:reset to site:after_reset
- raise an exception when registering uncallable hook
- set default hook priority at the public API level
@envygeeks
Copy link
Contributor

@parkr it was originally on line 53 of hooks.rb but it looks @stevecrozz caught what I meant and correct it so 🎉 I'm liking this so far!

@imathis
Copy link
Contributor

imathis commented May 3, 2015

Lookin' good! I'll give another go at rebuilding some plugins based on this.

@parkr
Copy link
Member

parkr commented May 3, 2015

@gjtorikian: would you mind trying out this branch on a big site you have access to? Interested in performance change, if any. ❤️

@stevecrozz
Copy link
Contributor Author

@imathis You could potentially author a shim to make your current octopress-hooks based plugins work with these new hooks. Here's a totally untested start at something like that.
https://gist.github.com/stevecrozz/ca294104609efd8205bb

@imathis
Copy link
Contributor

imathis commented May 4, 2015

@stevecrozz I'll give it a try, thanks for the guidance.

@gjtorikian
Copy link
Member

would you mind trying out this branch on a big site you have access to? Interested in performance change, if any.

I kept trying it out and thought it would be a quick discovery, but kept running into problem. First, most plugins aren't Jekyll 3 compatible yet; I've logged a few issues for them. But even with them commented out, I discovered so of my own plugins/hacks are incompatible, too. It'll take me some time to upgrade those, in order to be able to test performance on Jekyll 3/this branch.

@parkr
Copy link
Member

parkr commented May 9, 2015

@stevecrozz Is this ready to go?

@parkr
Copy link
Member

parkr commented May 10, 2015

Merging. Feel free to add further feedback as we approach the final release!

parkr added a commit that referenced this pull request May 10, 2015
@parkr parkr merged commit ce9fcfa into jekyll:master May 10, 2015
parkr added a commit that referenced this pull request May 10, 2015
@imathis
Copy link
Contributor

imathis commented May 10, 2015

I just pushed an octopress-multilingual pull-request for merging Jekyll hooks support. It worked really well and was nice to integrate. Thanks for your work on this @stevecrozz and everyone else who helped! 👍

@parkr
Copy link
Member

parkr commented May 10, 2015

Hooray!!! 🎉

@stevecrozz
Copy link
Contributor Author

Very cool. Thanks for all the help, everyone. I know there were a bunch of other ideas up there that didn't make it into this first round but it doesn't have to end here. I'll look forward to seeing and reviewing more hook-related work.

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants