Jan-Jaap Driessen avatar Jan-Jaap Driessen committed 34eea6a

Add print css renderer.

Comments (0)

Files changed (3)

 - Cherry picked pull request #1 "support-wsgi-apps-not-mounted-at-/",
   thanks to Éric Lemoine.
 
+- Add print css renderer.
+
 0.11.4 (2012-01-14)
 ===================
 

fanstatic/core.py

 
 
 def render_ico(url):
-    return ('<link rel="shortcut icon" type="image/x-icon" href="%s"/>' % url)
+    return '<link rel="shortcut icon" type="image/x-icon" href="%s"/>' % (url,)
 
 
 def render_css(url):
-    return ('<link rel="stylesheet" type="text/css" href="%s" />' % url)
+    return '<link rel="stylesheet" type="text/css" href="%s" />' % (url,)
 
 
 def render_js(url):
-    return ('<script type="text/javascript" src="%s"></script>' % url)
+    return '<script type="text/javascript" src="%s"></script>' % (url,)
+
+
+def render_print_css(url):
+    return (
+        '<link rel="stylesheet" type="text/css" href="%s" '
+        'media="print" />') % (url,)
+
+
+def render_screen_css(url):
+    return (
+        '<link rel="stylesheet" type="text/css" media="screen" '
+        'href="%s" />') % (url,)
+
 
 register_inclusion_renderer('.css', render_css, 10)
 

fanstatic/test_core.py

 def test_html_bottom_safe_used_with_minified():
     foo = Library('foo', '')
     a = Resource(foo, 'a.js', minified='a-minified.js', bottom=True)
-    
+
     needed = NeededResources(minified=True, bottom=True)
     needed.need(a)
 
 
 def test_custom_renderer_for_resource():
     foo = Library('foo', '')
-
-    def render_print_css(url):
-        return ('<link rel="stylesheet" type="text/css" href="%s" media="print"/>' %
-                url)
+    from fanstatic.core import render_print_css
 
     a = Resource(foo, 'printstylesheet.css', renderer=render_print_css)
     needed = NeededResources()
     needed.need(a)
     assert needed.render() == """\
-<link rel="stylesheet" type="text/css" href="/fanstatic/foo/printstylesheet.css" media="print"/>"""
+<link rel="stylesheet" type="text/css" href="/fanstatic/foo/printstylesheet.css" media="print" />"""
 
     def render_unknown(url):
         return '<unknown href="%s"/>' % url
     b = Resource(foo, 'nothing.unknown', renderer=render_unknown)
     needed.need(b)
     assert needed.render() == """\
-<link rel="stylesheet" type="text/css" href="/fanstatic/foo/printstylesheet.css" media="print"/>
+<link rel="stylesheet" type="text/css" href="/fanstatic/foo/printstylesheet.css" media="print" />
 <unknown href="/fanstatic/foo/nothing.unknown"/>"""
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.