def stylesheet_link(*urls, **attrs): """Return CSS link tags for the specified stylesheet URLs. ``urls`` should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case. Examples:: >>> stylesheet_link('/stylesheets/style.css') literal(%(u)s'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />') >>> stylesheet_link('/stylesheets/dir/file.css', media='all') literal(%(u)s'<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />') """ if "href" in attrs: raise TypeError("keyword arg 'href' not allowed") attrs.setdefault("rel", "stylesheet") attrs.setdefault("type", "text/css") attrs.setdefault("media", "screen") tags = [] for url in urls: tag = HTML.link(href=url, **attrs) tags.append(tag) return literal('\n').join(tags)
def stylesheet_link(*urls, **attrs): """Return CSS link tags for the specified stylesheet URLs. ``urls`` should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case. Examples:: >>> stylesheet_link('/stylesheets/style.css') literal(u'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />') >>> stylesheet_link('/stylesheets/dir/file.css', media='all') literal(u'<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />') """ if "href" in attrs: raise TypeError("keyword arg 'href' not allowed") attrs.setdefault("rel", "stylesheet") attrs.setdefault("type", "text/css") attrs.setdefault("media", "screen") tags = [] for url in urls: tag = HTML.link(href=url, **attrs) tags.append(tag) return literal('\n').join(tags)
def onPostListBuilding(self, event): """ >>> from shimpy.ext.index import PostListBuildingEvent >>> from shimpy.core.page import Page >>> from mock import Mock >>> context.config = {"title": "Site Title"} >>> ri = RSSImages() >>> context.page = Page() >>> ri.onPostListBuilding(PostListBuildingEvent([])) >>> context.page.html_headers[0] literal(u'<link href="/rss/images/1" id="images" rel="alternate" title="Site Title - Images" type="application/rss+xml" />') >>> context.page = Page() >>> ri.onPostListBuilding(PostListBuildingEvent(["search", "terms"])) >>> context.page.html_headers[0] literal(u'<link href="/rss/images/search terms/1" id="images" rel="alternate" title="Site Title - Images with tags: search terms" type="application/rss+xml" />') """ title = context.config.get("title") if event.search_terms: search = " ".join(event.search_terms) feed_title = "%s - Images with tags: %s" % (title, search) link = make_link("rss/images/%s/1" % search) else: feed_title = "%s - Images" % title link = make_link("rss/images/1") context.page.add_html_header(HTML.link( id="images", rel="alternate", type="application/rss+xml", title=feed_title, href=link ))
def auto_discovery_link(url, feed_type="rss", **attrs): """Return a link tag allowing auto-detecting of RSS or ATOM feed. The auto-detection of feed for the current page is only for browsers and news readers that support it. ``url`` The URL of the feed. (This should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``feed_type`` The type of feed. Specifying 'rss' or 'atom' automatically translates to a type of 'application/rss+xml' or 'application/atom+xml', respectively. Otherwise the type is used as specified. Defaults to 'rss'. Examples:: >>> auto_discovery_link('http://feed.com/feed.xml') literal(%(u)s'<link href="http://feed.com/feed.xml" rel="alternate" title="RSS" type="application/rss+xml" />') >>> auto_discovery_link('http://feed.com/feed.xml', feed_type='atom') literal(%(u)s'<link href="http://feed.com/feed.xml" rel="alternate" title="ATOM" type="application/atom+xml" />') >>> auto_discovery_link('app.rss', feed_type='atom', title='atom feed') literal(%(u)s'<link href="app.rss" rel="alternate" title="atom feed" type="application/atom+xml" />') >>> auto_discovery_link('/app.html', feed_type='text/html') literal(%(u)s'<link href="/app.html" rel="alternate" title="" type="text/html" />') """ if "href" in attrs: raise TypeError("keyword arg 'href' is not allowed") if "type" in attrs: raise TypeError("keyword arg 'type' is not allowed") title = "" if feed_type.lower() in ('rss', 'atom'): title = feed_type.upper() feed_type = 'application/%s+xml' % feed_type.lower() attrs.setdefault("title", title) return HTML.link(rel="alternate", type=feed_type, href=url, **attrs)
def auto_discovery_link(url, feed_type="rss", **attrs): """Return a link tag allowing auto-detecting of RSS or ATOM feed. The auto-detection of feed for the current page is only for browsers and news readers that support it. ``url`` The URL of the feed. (This should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case.) ``feed_type`` The type of feed. Specifying 'rss' or 'atom' automatically translates to a type of 'application/rss+xml' or 'application/atom+xml', respectively. Otherwise the type is used as specified. Defaults to 'rss'. Examples:: >>> auto_discovery_link('http://feed.com/feed.xml') literal(u'<link href="http://feed.com/feed.xml" rel="alternate" title="RSS" type="application/rss+xml" />') >>> auto_discovery_link('http://feed.com/feed.xml', feed_type='atom') literal(u'<link href="http://feed.com/feed.xml" rel="alternate" title="ATOM" type="application/atom+xml" />') >>> auto_discovery_link('app.rss', feed_type='atom', title='atom feed') literal(u'<link href="app.rss" rel="alternate" title="atom feed" type="application/atom+xml" />') >>> auto_discovery_link('/app.html', feed_type='text/html') literal(u'<link href="/app.html" rel="alternate" title="" type="text/html" />') """ if "href" in attrs: raise TypeError("keyword arg 'href' is not allowed") if "type" in attrs: raise TypeError("keyword arg 'type' is not allowed") title = "" if feed_type.lower() in ('rss', 'atom'): title = feed_type.upper() feed_type = 'application/%s+xml' % feed_type.lower() attrs.setdefault("title", title) return HTML.link(rel="alternate", type=feed_type, href=url, **attrs)