python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.72k stars 2.21k forks source link

Add custom Template class with tojavascript filter #1912

Closed Conengmo closed 1 month ago

Conengmo commented 2 months ago

Based on https://github.com/python-visualization/folium/pull/1856, split off from the more complete version in https://github.com/python-visualization/folium/pull/1895.

Add a custom Template class that contains the tojavascript template filter that converts Python objects to Javascript notation. This may include Javascript object references or functions.

Instead of applying this template everywhere at once, we'll adopt is gradually where it is useful. This is mainly when one of the arguments is a Javascript function or when we want to reference another Folium object in the Javascript template.

Conengmo commented 1 month ago

@hansthen want to do a final review of this one?

Conengmo commented 1 month ago

As a future enhancement, I think the to_javascript filter may benefit from pretty indentation, but that should not block this change.

Good idea!

And thanks for the review!