-
Notifications
You must be signed in to change notification settings - Fork 84
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
Adding new extension hooks #462
Adding new extension hooks #462
Conversation
There are three new extension hooks in place now: * before_extensions + All extensions added via this method, following the same extension rules, will be run before any other extensions loaded with `extension`. * after_extensions + All extensions added via this method, following the same extension rules, will be run after any other extensions loaded with `extension`. * after_generation + All extensions added via this method, following the same extension rules, will be run after the page generation is completed. This will only run on the first generation, not on reloads. Extensions will now be notified if they are being reloaded. To be notified of this an extension must have an `on_reload(site)` method, which will be called if there is a change. An extension is then free to re-run an initialization logic, clean-up the site variable, or create new state needed for a re-run of the `execute(site)` method.
@aslakknutsen Care to play around with this and see if it will fit your needs? |
@LightGuard Will do. before/after sounds nice for a 'load/store cache' |
on_reload(site, changed_file) would be useful. Then we know what was updated and can clear disk cache. |
Ah. I was thinking you'd want a notification of the extension being rerun. On Saturday, April 11, 2015, Aslak Knutsen notifications@github.com wrote:
Jason Porter |
@LightGuard technically yes, but.. currently you're just calling on_reload on all extensions. And you don't really know which extension to reload, unless the extension it self, which you don't track, is being reloaded. Any way.. the changed file could be a class/file used by an extension. At that point, only the extension it self knows if it needs to redo something based on this change. |
The naming is a bit off to me; before_pipeline_extension and after_pipeline_extension It's part of the pipeline so it's not really before/after pipeline . Maybe just before/after? |
perhaps add support for the extension to register these hooks as we do with transformers: module TestExtension
class MyBigExtension
def transform(transformers)
transformers << MyTrans.new
end
def before(befores)
befores << MyBefore.new
end
def after(afters)
afters << MyAfter.new
end
def execute(site)
# do something
end
end
class MyTrans
def transform(site, page, rendered)
# wrap_page_with_custom_x(rendered)
end
end
class MyBefore
def execute(site)
# site.my_data = load_data()
end
end
class MyAfter
def execute(site)
# store_data(my_data)
end
end
end
Awestruct::Extensions::Pipeline.new do
extension TestExtension::MyBigExtension.new
end |
We do currently workaround this by passing pipeline as an argument, .. which might be just as clean and easier to be honest.. It just looks a bit different registering one of these extensions compared with the others. e.g. module TestExtension
class MyBigExtension
def initialize(pipeline)
pipline.transformer MyTrans.new
pipline.before MyBefore.new
pipline.after MyAfter.new
pipline.extension self
end
def execute(site)
# do something
end
end
class MyTrans
def transform(site, page, rendered)
# wrap_page_with_custom_x(rendered)
end
end
class MyBefore
def execute(site)
# site.my_data = load_data()
end
end
class MyAfter
def execute(site)
# store_data(my_data)
end
end
end
Awestruct::Extensions::Pipeline.new do
TestExtension::MyBigExtension.new self
end |
Well, it actually is run before/after all the extensions, but I couldn't find a good name for it. Do you have any suggestions? |
The new hooks (before_extensions, after_extensions, after_generation) may now be added by including those methods on extensions and simply including the extension as normal (`extension MyExtension.new`).
There are three new extension hooks in place now:
will be run before any other extensions loaded with
extension
.will be run after any other extensions loaded with
extension
.will be run after the page generation is completed. This will only run on the
first generation, not on reloads.
Extensions will now be notified if they are being reloaded. To be notified of
this an extension must have an
on_reload(site)
method, which will be calledif there is a change. An extension is then free to re-run an initialization
logic, clean-up the site variable, or create new state needed for a re-run of
the
execute(site)
method.