|
10 | 10 | from collections import defaultdict, MutableMapping
|
11 | 11 |
|
12 | 12 | try:
|
13 |
| - from jinja2 import Template |
| 13 | + from jinja2 import Template, PackageLoader, Environment |
14 | 14 | except ImportError:
|
15 | 15 | msg = "pandas.Styler requires jinja2. "\
|
16 | 16 | "Please install with `conda install Jinja2`\n"\
|
|
34 | 34 | no_mpl_message = "{0} requires matplotlib."
|
35 | 35 |
|
36 | 36 |
|
| 37 | + |
37 | 38 | @contextmanager
|
38 | 39 | def _mpl(func):
|
39 | 40 | if has_mpl:
|
@@ -103,56 +104,10 @@ class Styler(object):
|
103 | 104 | --------
|
104 | 105 | pandas.DataFrame.style
|
105 | 106 | """
|
106 |
| - template = Template(""" |
107 |
| - <style type="text/css" > |
108 |
| - {% for s in table_styles %} |
109 |
| - #T_{{uuid}} {{s.selector}} { |
110 |
| - {% for p,val in s.props %} |
111 |
| - {{p}}: {{val}}; |
112 |
| - {% endfor %} |
113 |
| - } |
114 |
| - {% endfor %} |
115 |
| - {% for s in cellstyle %} |
116 |
| - #T_{{uuid}}{{s.selector}} { |
117 |
| - {% for p,val in s.props %} |
118 |
| - {{p}}: {{val}}; |
119 |
| - {% endfor %} |
120 |
| - } |
121 |
| - {% endfor %} |
122 |
| - </style> |
123 |
| -
|
124 |
| - <table id="T_{{uuid}}" {{ table_attributes }}> |
125 |
| - {% if caption %} |
126 |
| - <caption>{{caption}}</caption> |
127 |
| - {% endif %} |
128 |
| -
|
129 |
| - <thead> |
130 |
| - {% for r in head %} |
131 |
| - <tr> |
132 |
| - {% for c in r %} |
133 |
| - {% if c.is_visible != False %} |
134 |
| - <{{c.type}} class="{{c.class}}" {{ c.attributes|join(" ") }}> |
135 |
| - {{c.value}} |
136 |
| - {% endif %} |
137 |
| - {% endfor %} |
138 |
| - </tr> |
139 |
| - {% endfor %} |
140 |
| - </thead> |
141 |
| - <tbody> |
142 |
| - {% for r in body %} |
143 |
| - <tr> |
144 |
| - {% for c in r %} |
145 |
| - {% if c.is_visible != False %} |
146 |
| - <{{c.type}} id="T_{{uuid}}{{c.id}}" |
147 |
| - class="{{c.class}}" {{ c.attributes|join(" ") }}> |
148 |
| - {{ c.display_value }} |
149 |
| - {% endif %} |
150 |
| - {% endfor %} |
151 |
| - </tr> |
152 |
| - {% endfor %} |
153 |
| - </tbody> |
154 |
| - </table> |
155 |
| - """) |
| 107 | + env = Environment( |
| 108 | + loader=PackageLoader("pandas", "formats/templates") |
| 109 | + ) |
| 110 | + template = env.get_template("html.tpl") |
156 | 111 |
|
157 | 112 | def __init__(self, data, precision=None, table_styles=None, uuid=None,
|
158 | 113 | caption=None, table_attributes=None):
|
|
0 commit comments