asset_tag

Asset Tag Helpers

Provides functionality for linking an HTML page together with other assets, such as images, javascripts, stylesheets, and feeds.


Attributes

a javascript_builtins

('prototype.js', 'scriptaculous.js')

a javascript_path

'/Users/bbangert/Programming/Python/webhelpers/webhelpers/rails/javascripts'

Functions

f auto_discovery_link_tag(source, type='rss', **kwargs) ...

Returns a link tag allowing browsers and news readers (that support it) to auto-detect an RSS or ATOM feed for current page.

source
The URL of the feed. The URL is ultimately prepended with the environment's SCRIPT_NAME (the root path of the web application), unless the URL is fully-fledged (e.g. http://example.com).
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_tag('http://feed.com/feed.xml')
'<link href="http://feed.com/feed.xml" rel="alternate" title="RSS" type="application/rss+xml" />'

>>> auto_discovery_link_tag('http://feed.com/feed.xml', type='atom')
'<link href="http://feed.com/feed.xml" rel="alternate" title="ATOM" type="application/atom+xml" />'

>>> auto_discovery_link_tag('app.rss', type='atom', title='atom feed')
'<link href="app.rss" rel="alternate" title="atom feed" type="application/atom+xml" />'

>>> auto_discovery_link_tag('/app.html', type='text/html')
'<link href="/app.html" rel="alternate" title="" type="text/html" />'

f image_tag(source, alt=None, size=None, **options) ...

Returns an image tag for the specified source.

source
The source URL of the image. The URL is prepended with '/images/', unless its full path is specified. The URL is ultimately prepended with the environment's SCRIPT_NAME (the root path of the web application), unless the URL is fully-fledged (e.g. http://example.com).
alt
The img's alt tag. Defaults to the source's filename, title cased.
size
The img's size, specified in the format "XxY". "30x45" becomes width="30", height="45". "x20" becomes height="20".

Examples:

>>> image_tag('xml.png')
'<img alt="Xml" src="/images/xml.png" />'

>>> image_tag('rss.png', 'rss syndication')
'<img alt="rss syndication" src="/images/rss.png" />'

>>> image_tag("icon.png", size="16x10", alt="Edit Entry")
'<img alt="Edit Entry" height="10" src="/images/icon.png" width="16" />'

>>> image_tag("/icons/icon.gif", size="16x16")
'<img alt="Icon" height="16" src="/icons/icon.gif" width="16" />'

>>> image_tag("/icons/icon.gif", size="16x")
'<img alt="Icon" src="/icons/icon.gif" width="16" />'

f javascript_include_tag(*sources, **options) ...

Returns script include tags for the specified javascript sources.

Each source's URL path is prepended with '/javascripts/' unless their full path is specified. Each source's URL path is ultimately prepended with the environment's SCRIPT_NAME (the root path of the web application), unless the URL path is a full-fledged URL (e.g. http://example.com). Sources with no filename extension will be appended with the '.js' extension.

Optionally includes (prepended) WebHelpers' built-in javascripts when passed the builtins=True keyword argument.

Specify the keyword argument defer=True to enable the script defer attribute.

Examples:

>>> print javascript_include_tag(builtins=True)
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/javascripts/scriptaculous.js" type="text/javascript"></script>

>>> print javascript_include_tag(builtins=True, defer=True)
<script defer="defer" src="/javascripts/prototype.js" type="text/javascript"></script>
<script defer="defer" src="/javascripts/scriptaculous.js" type="text/javascript"></script>

>>> print javascript_include_tag('prototype', '/other-javascripts/util.js')
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/other-javascripts/util.js" type="text/javascript"></script>

>>> print javascript_include_tag('app', '/test/test.1.js', builtins=True)
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/javascripts/scriptaculous.js" type="text/javascript"></script>
<script src="/javascripts/app.js" type="text/javascript"></script>
<script src="/test/test.1.js" type="text/javascript"></script>

f stylesheet_link_tag(*sources, **options) ...

Returns CSS link tags for the specified stylesheet sources.

Each source's URL path is prepended with '/stylesheets/' unless their full path is specified. Each source's URL path is ultimately prepended with the environment's SCRIPT_NAME (the root path of the web application), unless the URL path is a full-fledged URL (e.g. http://example.com). Sources with no filename extension will be appended with the '.css' extension.

Examples:

>>> stylesheet_link_tag('style')
'<link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />'

>>> stylesheet_link_tag('dir/file', media='all')
'<link href="/stylesheets/dir/file.css" media="all" rel="Stylesheet" type="text/css" />'

>>> stylesheet_link_tag('/dir/file', media='all')
'<link href="/dir/file.css" media="all" rel="Stylesheet" type="text/css" />'

See the source for more information.