Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
API/ENH: Styler template arguments #15649
Comments
chris-b1
added the
IO HTML
label
Mar 10, 2017
|
Are you familiar with Jinja's template inheritence? I wonder if we inserted some |
|
Oh, are these I think django gets around that problem by providing a |
|
In my case the I was actually just looking at how jinja does inheritance, - some |
|
@chris-b1 can you take a look at https://github.com/TomAugspurger/pandas/commit/aafba92e65389662be5265687f38f1cc04c4f79e and let me know if that would be sufficient? I moved it into it's own template file to make things easier to work on. I also added I'll add some tests and submit a PR, but it could be a bit. |
|
@TomAugspurger thanks! Made one inline comment on the blocks. My only question / thing needing docs would be how to actually extend that template. I understand the template syntax ( |
I'll look into this. I think the idea is to use a PrefixLoader or ChoiceLoader.
then if you make a file |
|
@chris-b1 http://nbviewer.jupyter.org/gist/anonymous/c84f30b41609fef7fd1c06b9fd748729 has an example (using my branch) I'll get things cleaned up and submitted as a PR this week. |
|
Very nice! Might be nice to wrap the subclassing into some kind of factory function to lessen the jinja2 knowledge required? Roughly def make_styler_subclass(template_folder, visible_template_name):
loader = ChoiceLoader([
FileSystemLoader(template_folder),
PackageLoader("pandas.formats")
])
class MyStyler(pd.formats.style.Styler):
env = Environment(loader=loader)
template = env.get_template(visible_template_name)
return MyStyler |
|
Closed by #15649 (I think solved everything, just forget to close it). |
chris-b1 commentedMar 10, 2017
Usecase - I have a
Stylersubclass with a new template that I want to pass some arbitrary stuff into - which currently there isn't a great way to do (right now I'm overriding and re-implementing.render()).Open to suggestions on the api, but I was thinking of adding
template_argsargument that would be passed to the template.xref #11610 (master tracker)
pandas 0.19.2