summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfunvit <funvit@gmail.com>2013-10-01 14:28:28 +0400
committerfunvit <funvit@gmail.com>2013-10-01 14:28:28 +0400
commit2160c7686f925b5e39d591fc1da52161a16292b8 (patch)
tree7badaaf6e260ed47f4f35dc7bdbf465aa71e141b
parent5f3f3dae30b6d349a9865142d04f0c1f82cb5164 (diff)
downloadpyscss-2160c7686f925b5e39d591fc1da52161a16292b8.tar.gz
woff mime changed, tests urls fixed
-rw-r--r--scss/functions/compass/helpers.py7
-rw-r--r--scss/tests/functions/compass/test_helpers.py26
2 files changed, 19 insertions, 14 deletions
diff --git a/scss/functions/compass/helpers.py b/scss/functions/compass/helpers.py
index 15d4e47..e5bb159 100644
--- a/scss/functions/compass/helpers.py
+++ b/scss/functions/compass/helpers.py
@@ -527,7 +527,12 @@ def _font_url(path, only_path=False, cache_buster=True, inline=False):
if not FONT_TYPES.get(font_type):
raise Exception('Could not determine font type for "%s"' % path.value)
- url = 'data:font/' + FONT_TYPES.get(font_type) + ';base64,' + base64.b64encode(file.read())
+ mime = FONT_TYPES.get(font_type)
+ if font_type == 'woff':
+ mime = 'application/font-woff'
+ elif font_type=='eot':
+ mime = 'application/vnd.ms-fontobject'
+ url = 'data:' + (mime if '/' in mime else 'font/%s' % mime) + ';base64,' + base64.b64encode(file.read())
file.close()
else:
url = '%s/%s' % (BASE_URL.rstrip('/'), filepath.lstrip('/'))
diff --git a/scss/tests/functions/compass/test_helpers.py b/scss/tests/functions/compass/test_helpers.py
index 7453ac3..9db1741 100644
--- a/scss/tests/functions/compass/test_helpers.py
+++ b/scss/tests/functions/compass/test_helpers.py
@@ -150,8 +150,8 @@ def test_pow(calc):
## Fonts
# font-url
def test_font_url(calc):
- assert calc('font-url("/some_path.woff")').render() == ('url(%(static_url)ssome_path.woff)' % {'static_url': config.STATIC_URL})
- assert calc('font-url("/some_path.woff") format("woff")').render() == ('url(%(static_url)ssome_path.woff) format("woff")' % {'static_url': config.STATIC_URL})
+ assert calc('font-url("/some_path.woff")').render() == ('url(%(static_url)ssome_path.woff)' % {'static_url': config.FONTS_URL})
+ assert calc('font-url("/some_path.woff") format("woff")').render() == ('url(%(static_url)ssome_path.woff) format("woff")' % {'static_url': config.FONTS_URL})
# font-files
@@ -161,15 +161,15 @@ def test_font_files(calc):
@note: adapted from compass / test / units / sass_extensions_test.rb
"""
assert '' == calc('font-files()').render()
- assert ('url(%(static_url)sfont/name.woff) format("woff"), url(%(static_url)sfonts/name.ttf) format("truetype"), url(%(static_url)sfonts/name.svg#fontpath) format("svg")' % {'static_url': config.STATIC_URL}) == calc('font-files("/font/name.woff", woff, "/fonts/name.ttf", truetype, "/fonts/name.svg#fontpath", svg)').render()
+ assert ('url(%(static_url)sfont/name.woff) format("woff"), url(%(static_url)sfonts/name.ttf) format("truetype"), url(%(static_url)sfonts/name.svg#fontpath) format("svg")' % {'static_url': config.FONTS_URL}) == calc('font-files("/font/name.woff", woff, "/fonts/name.ttf", truetype, "/fonts/name.svg#fontpath", svg)').render()
- assert ('url(%(static_url)sfont/with/right_ext.woff) format("woff")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/right_ext.woff")').render()
- assert ('url(%(static_url)sfont/with/wrong_ext.woff) format("svg")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/wrong_ext.woff", "svg")').render()
- assert ('url(%(static_url)sfont/with/no_ext) format("opentype")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/no_ext", "otf")').render()
- assert ('url(%(static_url)sfont/with/weird.ext) format("truetype")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/weird.ext", "truetype")').render()
+ assert ('url(%(static_url)sfont/with/right_ext.woff) format("woff")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/right_ext.woff")').render()
+ assert ('url(%(static_url)sfont/with/wrong_ext.woff) format("svg")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/wrong_ext.woff", "svg")').render()
+ assert ('url(%(static_url)sfont/with/no_ext) format("opentype")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/no_ext", "otf")').render()
+ assert ('url(%(static_url)sfont/with/weird.ext) format("truetype")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/weird.ext", "truetype")').render()
- assert ('url(%(static_url)sfont/with/right_ext.woff) format("woff"), url(%(static_url)sfont/with/right_ext_also.otf) format("opentype")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/right_ext.woff", "/font/with/right_ext_also.otf")').render()
- assert ('url(%(static_url)sfont/with/wrong_ext.woff) format("truetype"), url(%(static_url)sfont/with/right_ext.otf) format("opentype")' % {'static_url': config.STATIC_URL}) == calc('font_files("/font/with/wrong_ext.woff", "ttf", "/font/with/right_ext.otf")').render()
+ assert ('url(%(static_url)sfont/with/right_ext.woff) format("woff"), url(%(static_url)sfont/with/right_ext_also.otf) format("opentype")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/right_ext.woff", "/font/with/right_ext_also.otf")').render()
+ assert ('url(%(static_url)sfont/with/wrong_ext.woff) format("truetype"), url(%(static_url)sfont/with/right_ext.otf) format("opentype")' % {'static_url': config.FONTS_URL}) == calc('font_files("/font/with/wrong_ext.woff", "ttf", "/font/with/right_ext.otf")').render()
# inline-font-files
@@ -194,7 +194,7 @@ def test_inline_font_files(calc):
# for debugging uncomment next lines
-#if __name__=='__main__':
-# test_font_url(calc())
-# test_font_files(calc())
-# test_inline_font_files(calc()) \ No newline at end of file
+if __name__=='__main__':
+ test_font_url(calc())
+ test_font_files(calc())
+ test_inline_font_files(calc()) \ No newline at end of file