Browse Source

Add inline css + css tests

pull/98/head
Florian Mounier 11 years ago
parent
commit
0a481165f0
  1. 2
      pygal/graph/datey.py
  2. 27
      pygal/svg.py
  3. 26
      pygal/test/test_config.py

2
pygal/graph/datey.py

@ -51,7 +51,7 @@ class DateY(XY):
def _todate(self, d):
""" Converts a number to a date """
currDateTime = self._offset + datetime.timedelta(seconds=d or 0)
return currDateTime.strftime( self.x_label_format )
return currDateTime.strftime(self.x_label_format)
def _tonumber(self, d):
""" Converts a date to a number """

27
pygal/svg.py

@ -74,18 +74,21 @@ class Svg(object):
etree.PI(
u('xml-stylesheet'), u('href="%s"' % css)))
else:
if not os.path.exists(css):
css = os.path.join(
os.path.dirname(__file__), 'css', css)
with io.open(css, encoding='utf-8') as f:
css_text = template(
f.read(),
style=self.graph.config.style,
colors=colors,
font_sizes=self.graph.config.font_sizes(),
id=self.id)
if not self.graph.pretty_print:
css_text = minify_css(css_text)
if css.startswith('inline:'):
css_text = css[len('inline:'):]
else:
if not os.path.exists(css):
css = os.path.join(
os.path.dirname(__file__), 'css', css)
with io.open(css, encoding='utf-8') as f:
css_text = template(
f.read(),
style=self.graph.config.style,
colors=colors,
font_sizes=self.graph.config.font_sizes(),
id=self.id)
if not self.graph.pretty_print:
css_text = minify_css(css_text)
all_css.append(css_text)
self.node(
self.defs, 'style', type='text/css').text = '\n'.join(all_css)

26
pygal/test/test_config.py

@ -288,3 +288,29 @@ def test_include_x_axis(Chart):
chart.include_x_axis = True
q = chart.render_pyquery()
assert '0.0' in q(yaxis).map(texts)
def test_css(Chart):
css = "{{ id }}text { fill: #bedead; }\n"
css_file = '/tmp/pygal_custom_style.css'
with open(css_file, 'w') as f:
f.write(css)
config = Config()
config.css.append(css_file)
chart = Chart(config)
chart.add('/', [10, 1, 5])
svg = chart.render().decode('utf-8')
assert '#bedead' in svg
def test_inline_css(Chart):
css = "{{ id }}text { fill: #bedead; }\n"
config = Config()
config.css.append('inline:' + css)
chart = Chart(config)
chart.add('/', [10, 1, 5])
svg = chart.render().decode('utf-8')
assert '#bedead' in svg

Loading…
Cancel
Save