/usr/share/doc/python-webassets-doc/html/bundles.html is in python-webassets-doc 3:0.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bundles — webassets 0.9 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.9',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="webassets 0.9 documentation" href="index.html" />
<link rel="next" title="Command Line Interface" href="script.html" />
<link rel="prev" title="The environment" href="environment.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="script.html" title="Command Line Interface"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="environment.html" title="The environment"
accesskey="P">previous</a> |</li>
<li><a href="index.html">webassets 0.9 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="bundles">
<span id="id1"></span><h1>Bundles<a class="headerlink" href="#bundles" title="Permalink to this headline">¶</a></h1>
<p>A bundle is simply a collection of files that you would like to group
together, with some properties attached to tell <tt class="docutils literal"><span class="pre">webassets</span></tt>
how to do its job. Such properties include the filters which should
be applied, or the location where the output file should be stored.</p>
<p>Note that all filenames and paths considered to be relative to the
<tt class="docutils literal"><span class="pre">directory</span></tt> setting of your <a class="reference internal" href="environment.html"><em>environment</em></a>, and
generated urls will be relative to the <tt class="docutils literal"><span class="pre">url</span></tt> setting.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Bundle</span><span class="p">(</span><span class="s">'common/inheritance.js'</span><span class="p">,</span> <span class="s">'portal/js/common.js'</span><span class="p">,</span>
<span class="s">'portal/js/plot.js'</span><span class="p">,</span> <span class="s">'portal/js/ticker.js'</span><span class="p">,</span>
<span class="n">filters</span><span class="o">=</span><span class="s">'jsmin'</span><span class="p">,</span>
<span class="n">output</span><span class="o">=</span><span class="s">'gen/packed.js'</span><span class="p">)</span>
</pre></div>
</div>
<p>A bundle takes any number of filenames, as well as the following keyword
arguments:</p>
<ul>
<li><p class="first"><tt class="docutils literal"><span class="pre">filters</span></tt> -
One or multiple filters to apply. If no filters are specified, the
source files will merely be merged into the output file. Filters are
applied in the order in which they are given.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">output</span></tt> - Name/path of the output file. All source files will be merged
and the result stored at this location. A <tt class="docutils literal"><span class="pre">%(version)s</span></tt> placeholder is
supported here, which will be replaced with the version of the file. See
<a class="reference internal" href="expiring.html"><em>URL Expiry (cache busting)</em></a>.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">depends</span></tt> - Additional files that will be watched to determine if the
bundle needs to be rebuilt. This is usually necessary if you are using
compilers thhat allow <tt class="docutils literal"><span class="pre">@import</span></tt> instructions. Commonly, one would use a
glob instruction here for simplicity:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">Bundle</span><span class="p">(</span><span class="n">depends</span><span class="o">=</span><span class="p">(</span><span class="s">'**/*.scss'</span><span class="p">))</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Currently, using <tt class="docutils literal"><span class="pre">depends</span></tt> disables caching for a bundle.</p>
</div>
</li>
</ul>
<div class="section" id="nested-bundles">
<h2>Nested bundles<a class="headerlink" href="#nested-bundles" title="Permalink to this headline">¶</a></h2>
<p>Bundles may also contain other bundles:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">webassets</span> <span class="kn">import</span> <span class="n">Bundle</span>
<span class="n">all_js</span> <span class="o">=</span> <span class="n">Bundle</span><span class="p">(</span>
<span class="c"># jQuery</span>
<span class="n">Bundle</span><span class="p">(</span><span class="s">'common/libs/jquery/jquery.js'</span><span class="p">,</span>
<span class="s">'common/libs/jquery/jquery.ajaxQueue.js'</span><span class="p">,</span>
<span class="s">'common/libs/jquery/jquery.bgiframe.js'</span><span class="p">,),</span>
<span class="c"># jQuery Tools</span>
<span class="n">Bundle</span><span class="p">(</span><span class="s">'common/libs/jqtools/tools.tabs.js'</span><span class="p">,</span>
<span class="s">'common/libs/jqtools/tools.tabs.history.js'</span><span class="p">,</span>
<span class="s">'common/libs/jqtools/tools.tabs.slideshow.js'</span><span class="p">),</span>
<span class="c"># Our own stuff</span>
<span class="n">Bundle</span><span class="p">(</span><span class="s">'common/inheritance.js'</span><span class="p">,</span> <span class="s">'portal/js/common.js'</span><span class="p">,</span>
<span class="s">'portal/js/plot.js'</span><span class="p">,</span> <span class="s">'portal/js/ticker.js'</span><span class="p">),</span>
<span class="n">filters</span><span class="o">=</span><span class="s">'jsmin'</span><span class="p">,</span>
<span class="n">output</span><span class="o">=</span><span class="s">'gen/packed.js'</span><span class="p">)</span>
</pre></div>
</div>
<p>Here, the use of nested <tt class="docutils literal"><span class="pre">Bundle</span></tt> objects to group the JavaScript files
together is purely aesthetical. You could just as well pass all files as
a flat list. However, there are some more serious application as well.
One of them is the use of <a class="reference internal" href="css_compilers.html"><em>CSS compilers</em></a>.
Another would be dealing with pre-compressed files:</p>
<p>If you are using a JavaScript library like <a class="reference external" href="http://jquery.com/">jQuery</a>,
you might find yourself with a file like <tt class="docutils literal"><span class="pre">jquery.min.js</span></tt> in your media
directory, i.e. it is already minified - no reason to do it again.</p>
<p>While I would recommend always using the raw source files, and letting
<tt class="docutils literal"><span class="pre">webassets</span></tt> do the compressing, if you do have minified files that you
need to merge together with uncompressed ones, you could do it like so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">register</span><span class="p">(</span><span class="s">'js-all'</span><span class="p">,</span>
<span class="s">'jquery.min.js'</span><span class="p">,</span>
<span class="n">Bundle</span><span class="p">(</span><span class="n">filters</span><span class="o">=</span><span class="s">'jsmin'</span><span class="p">,</span> <span class="s">'uncompressed.js'</span><span class="p">))</span>
</pre></div>
</div>
<p>Generally speaking, nested bundles allow you to apply different sets of
filters to different groups of files, but still everything together
into a single output file.</p>
<p>Some things to consider when nesting bundles:</p>
<ul class="simple">
<li>Duplicate filters are only applied once (the leaf filter is applied).</li>
<li>If a bundle that is supposed to be processed to a file does not define
an output target, it simply serves as a container of its sub-bundles,
which in turn will be processed into their respective output files.
In this case it must not have any files of its own.</li>
</ul>
</div>
<div class="section" id="building-bundles">
<h2>Building bundles<a class="headerlink" href="#building-bundles" title="Permalink to this headline">¶</a></h2>
<p>Once a bundle is defined, the thing you want to do is build it, and then
include a link to the final merged and compressed output file in your
site.</p>
<p>There are different approaches.</p>
<div class="section" id="in-code">
<h3>In Code<a class="headerlink" href="#in-code" title="Permalink to this headline">¶</a></h3>
<p>For starters, you can simply call the bundle’s <tt class="docutils literal"><span class="pre">urls()</span></tt> method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">env</span><span class="p">[</span><span class="s">'all_js'</span><span class="p">]</span><span class="o">.</span><span class="n">urls</span><span class="p">()</span>
<span class="go">('/media/gen/packed.js',)</span>
</pre></div>
</div>
<p>Depending on the value of <tt class="docutils literal"><span class="pre">environment.debug</span></tt>. it will either return
a list of all the bundle’s source files, or the merged file pointed to
by the bundle’s <tt class="docutils literal"><span class="pre">output</span></tt> option - all relative to the
<tt class="docutils literal"><span class="pre">environment.url</span></tt> setting.</p>
<p><tt class="docutils literal"><span class="pre">urls()</span></tt> will always ensure that the files behind the urls it returns
actually exist. That is, it will merge and compress the source files in
production mode when first called, and update the compressed assets when
it detects changes. This behavior can be customized using various
<a class="reference internal" href="environment.html#environment-configuration"><em>environment configuration values</em></a>.</p>
<p>Call <tt class="docutils literal"><span class="pre">urls()</span></tt> once per request, and pass the resulting list of urls to
your template, and you’re good to go.</p>
</div>
<div class="section" id="in-templates">
<h3>In templates<a class="headerlink" href="#in-templates" title="Permalink to this headline">¶</a></h3>
<p>For <a class="reference internal" href="integration/index.html"><em>some template languages</em></a>, webassets
includes extensions which allow you to access the bundles you defined.
Further, they usually allow you to define bundles on-the-fly, so you can
reference your assets directly from within your templates, rather than
predefining them in code.</p>
<p>For example, there is a template tag for <a class="reference internal" href="integration/jinja2.html"><em>Jinja2</em></a>,
which allows you do something like this:</p>
<div class="highlight-jinja"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">assets</span> <span class="nv">filters</span><span class="o">=</span><span class="s2">"cssmin,datauri"</span><span class="o">,</span> <span class="nv">output</span><span class="o">=</span><span class="s2">"gen/packed.css"</span><span class="o">,</span> <span class="s2">"common/jquery.css"</span><span class="o">,</span> <span class="s2">"site/base.css"</span><span class="o">,</span> <span class="s2">"site/widgets.css"</span> <span class="cp">%}</span><span class="x"></span>
<span class="x">...</span>
</pre></div>
</div>
</div>
<div class="section" id="management-command">
<h3>Management command<a class="headerlink" href="#management-command" title="Permalink to this headline">¶</a></h3>
<p>In some cases you might prefer to cause a manual build of your bundles
from the command line. See <a class="reference internal" href="script.html"><em>Command Line Interface</em></a> for more information.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Bundles</a><ul>
<li><a class="reference internal" href="#nested-bundles">Nested bundles</a></li>
<li><a class="reference internal" href="#building-bundles">Building bundles</a><ul>
<li><a class="reference internal" href="#in-code">In Code</a></li>
<li><a class="reference internal" href="#in-templates">In templates</a></li>
<li><a class="reference internal" href="#management-command">Management command</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="environment.html"
title="previous chapter">The environment</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="script.html"
title="next chapter">Command Line Interface</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/bundles.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="script.html" title="Command Line Interface"
>next</a> |</li>
<li class="right" >
<a href="environment.html" title="The environment"
>previous</a> |</li>
<li><a href="index.html">webassets 0.9 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2009, 2010, Michael Elsdörfer.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b3.
</div>
</body>
</html>
|