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

issue #520: provide option to customize stock extensions #552

Merged
merged 4 commits into from
Dec 18, 2020

Conversation

pepperbob
Copy link
Contributor

This is a draft for #520 to allow for a customization of the default extensions.

  • refactored out the extension loading code from the PebbleEngine.Builder into the ExtensionRegistryFactory
  • provide a ExtensionCustomizer which basically allows to access extensions before loading

@pepperbob
Copy link
Contributor Author

So I came up with "ExtensionCustomizer" to allow filtering out or change whatever functionality is provided by an extension. It currently only targets the baked in extensions - not sure if it would make much sense on the user provided extensions anyway.

On the one hand it looks like it leaves the configuration API completely intact and doesn't degrade things like allowOverrideCoreOperators to an implementation detail.

On the other hand I'm not too happy with the current version as now other implementation details, e.g. how core functionality is split over extension classes (core, i18n, escaper) kind of leaks out as you have to know the extension class to apply the customizer.

Of course the whole target class thing can be dropped and there could be just one single customizer that is wrapped around every extension before it is loaded ... while thinking about it - i think this is would would provide the cleanest API and won't break things for users if stuff is re-organized internally at some point.. I'll rework it.

Feedback is much appreciated!

super(core);
}

@Override
public Map<String, Filter> getFilters() {
Map<String, Filter> filters = new HashMap<>(super.getFilters());
Map<String, Filter> filters = Optional.ofNullable(super.getFilters()).map(HashMap::new)
Copy link
Contributor Author

@pepperbob pepperbob Nov 29, 2020

Choose a reason for hiding this comment

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

just curious: is there a reason why null is acceptable over an empty map/list if filters and others are not provided?

@ebussieres
Copy link
Member

Can you provide some documentation for this new functionality ?

@pepperbob
Copy link
Contributor Author

@ebussieres Ok, I added further JavaDoc - is that okay so far?

@ebussieres
Copy link
Member

I mean add some documentation for pebble website. Doc is here : https://github.com/PebbleTemplates/pebble/tree/master/docs/src/orchid/resources

@pepperbob
Copy link
Contributor Author

Oh sure, I'll check this out!

@pepperbob pepperbob changed the title draft issue #520: provide option to customize stock extensions issue #520: provide option to customize stock extensions Dec 13, 2020
The following example removes the `ForTokenParser`, i.e. the ability to parse `{% for %}{{ ... }}{% endfor %}` constructs:

```java
class ExampleOptOuts extends ExntensionCustomizer {
Copy link
Member

Choose a reason for hiding this comment

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

there's a typo in ExntensionCustomizer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 fixed it :)

@ebussieres ebussieres added this to the 3.1.5 milestone Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to configure which core functionality is loaded per default?
2 participants