doc/classes/AssetHat/CSS.html in asset_hat-0.2.1 vs doc/classes/AssetHat/CSS.html in asset_hat-0.3.0
- old
+ new
@@ -44,14 +44,14 @@
</div>
<div id='method-list'>
<h2>Methods</h2>
<h3>public class</h3>
<ol>
- <li><a href="#M000014">add_asset_commit_ids</a></li>
- <li><a href="#M000015">add_asset_hosts</a></li>
- <li><a href="#M000012">min_filepath</a></li>
- <li><a href="#M000013">minify</a></li>
+ <li><a href="#M000018">add_asset_commit_ids</a></li>
+ <li><a href="#M000019">add_asset_hosts</a></li>
+ <li><a href="#M000016">min_filepath</a></li>
+ <li><a href="#M000017">minify</a></li>
</ol>
</div>
<div id='section'>
<div id='class-list'>
<h2>Classes and Modules</h2>
@@ -74,70 +74,79 @@
</table>
</div>
</div>
<div id='methods'>
<h2>Public class methods</h2>
- <div class='method public-class' id='method-M000014'>
- <a name='M000014'></a>
+ <div class='method public-class' id='method-M000018'>
+ <a name='M000018'></a>
<div class='synopsis'>
<span class='name'>add_asset_commit_ids</span>
<span class='arguments'>(css)</span>
</div>
<div class='description'>
<p>
Given a string containing <a href="CSS.html">CSS</a>, appends each
referenced asset’s last commit ID to its URL, e.g., <tt>background:
- url(/images/foo.png?ab12cd34e)</tt>. This enables cache busting: If the
+ url(/images/foo.png?ab12cd3)</tt>. This enables cache busting: If the
user’s browser has cached a copy of foo.png from a previous
deployment, this new URL forces the browser to ignore that cache and
request the latest version.
</p>
</div>
<div class='source'>
- <a class='source-toggle' href='#' onclick="toggleCode('M000014-source'); return false">
+ <a class='source-toggle' href='#' onclick="toggleCode('M000018-source'); return false">
[show source]
</a>
- <pre id='M000014-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 43</span>
43: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_asset_commit_ids</span>(<span class="ruby-identifier">css</span>)
44: <span class="ruby-identifier">css</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/url[\s]*\((\/(images|htc)\/[^)]+)\)/</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
45: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">$1</span>
46: 
47: <span class="ruby-comment cmt"># Get absolute path</span>
48: <span class="ruby-identifier">filepath</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">ASSETS_DIR</span>, <span class="ruby-identifier">src</span>)
49: 
50: <span class="ruby-comment cmt"># Convert to relative path</span>
51: <span class="ruby-identifier">filepath</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-node">/^#{FileUtils.pwd}#{File::SEPARATOR}/</span>, <span class="ruby-value str">''</span>)
52: 
53: <span class="ruby-identifier">commit_id</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">last_commit_id</span>(<span class="ruby-identifier">filepath</span>)
54: <span class="ruby-identifier">commit_id</span>.<span class="ruby-identifier">present?</span> <span class="ruby-value">? </span><span class="ruby-node">"url(#{src}?#{commit_id})"</span> <span class="ruby-operator">:</span> <span class="ruby-node">"url(#{src})"</span>
55: <span class="ruby-keyword kw">end</span>
56: <span class="ruby-keyword kw">end</span></pre>
+ <pre id='M000018-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 43</span>
43: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_asset_commit_ids</span>(<span class="ruby-identifier">css</span>)
44: <span class="ruby-identifier">update_css_urls</span>(<span class="ruby-identifier">css</span>, <span class="ruby-node">%w[images htc]</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">src</span>, <span class="ruby-identifier">quote</span><span class="ruby-operator">|</span>
45: <span class="ruby-comment cmt"># Get absolute path</span>
46: <span class="ruby-identifier">filepath</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">ASSETS_DIR</span>, <span class="ruby-identifier">src</span>)
47: 
48: <span class="ruby-comment cmt"># Convert to relative path</span>
49: <span class="ruby-identifier">filepath</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-node">/^#{FileUtils.pwd}#{File::SEPARATOR}/</span>, <span class="ruby-value str">''</span>)
50: 
51: <span class="ruby-identifier">commit_id</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">last_commit_id</span>(<span class="ruby-identifier">filepath</span>)
52: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">commit_id</span>.<span class="ruby-identifier">present?</span>
53: <span class="ruby-node">"url(#{quote}#{src}#{src =~ /\?/ ? '&' : '?'}#{commit_id}#{quote})"</span>
54: <span class="ruby-keyword kw">else</span>
55: <span class="ruby-node">"url(#{quote}#{src}#{quote})"</span>
56: <span class="ruby-keyword kw">end</span>
57: <span class="ruby-keyword kw">end</span>
58: <span class="ruby-keyword kw">end</span></pre>
</div>
</div>
- <div class='method public-class' id='method-M000015'>
- <a name='M000015'></a>
+ <div class='method public-class' id='method-M000019'>
+ <a name='M000019'></a>
<div class='synopsis'>
<span class='name'>add_asset_hosts</span>
- <span class='arguments'>(css, asset_host)</span>
+ <span class='arguments'>(css, asset_host, options={})</span>
</div>
<div class='description'>
<p>
Arguments:
</p>
<ul>
<li>A string containing <a href="CSS.html">CSS</a>;
</li>
<li>A string containing the app’s asset host, e.g.,
- ‘http://assets%d.example.com’. This value is typically taken
- from <tt>config.action_controller.asset_host</tt> in the app’s
+ ‘http://cdn%d.example.com’. This value is typically taken from
+ <tt>config.action_controller.asset_host</tt> in the app’s
<tt>config/environments/production.rb</tt>.
</li>
</ul>
<p>
An asset host is added to every image URL in the <a
href="CSS.html">CSS</a>, e.g., <tt>background:
- url(http://assets2.example.com/images/foo.png)</tt>; if <tt>%d</tt> in the
+ url(http://cdn2.example.com/images/foo.png)</tt>; if <tt>%d</tt> in the
asset host, it is replaced with an arbitrary number in 0-3, inclusive.
</p>
+ <p>
+ Options:
+ </p>
+ <dl>
+ <dt>ssl</dt><dd>Set to <tt>true</tt> to simulate a request via SSL. Defaults to
+ <tt>false</tt>.
+
+ </dd>
+ </dl>
</div>
<div class='source'>
- <a class='source-toggle' href='#' onclick="toggleCode('M000015-source'); return false">
+ <a class='source-toggle' href='#' onclick="toggleCode('M000019-source'); return false">
[show source]
</a>
- <pre id='M000015-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 70</span>
70: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_asset_hosts</span>(<span class="ruby-identifier">css</span>, <span class="ruby-identifier">asset_host</span>)
71: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">asset_host</span>.<span class="ruby-identifier">blank?</span>
72: <span class="ruby-identifier">css</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/url[\s]*\((\/images\/[^)]+)\)/</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
73: <span class="ruby-comment cmt"># N.B.: The `/htc/` directory is excluded because IE 6, by default,</span>
74: <span class="ruby-comment cmt"># refuses to run .htc files (e.g., TwinHelix's iepngfix.htc) from</span>
75: <span class="ruby-comment cmt"># other domains, including CDN subdomains.</span>
76: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">$1</span>
77: <span class="ruby-node">"url(#{(asset_host =~ /%d/) ? asset_host % (src.hash % 4) : asset_host}#{src})"</span>
78: <span class="ruby-keyword kw">end</span>
79: <span class="ruby-keyword kw">end</span></pre>
+ <pre id='M000019-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 77</span>
77: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">add_asset_hosts</span>(<span class="ruby-identifier">css</span>, <span class="ruby-identifier">asset_host</span>, <span class="ruby-identifier">options</span>={})
78: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">css</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">asset_host</span>.<span class="ruby-identifier">blank?</span>
79: 
80: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>)
81: 
82: <span class="ruby-identifier">update_css_urls</span>(<span class="ruby-identifier">css</span>, <span class="ruby-node">%w[images]</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">src</span>, <span class="ruby-identifier">quote</span><span class="ruby-operator">|</span>
83: <span class="ruby-identifier">computed_asset_host</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">compute_asset_host</span>(
84: <span class="ruby-identifier">asset_host</span>, <span class="ruby-identifier">src</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">:ssl</span>))
85: <span class="ruby-node">"url(#{quote}#{computed_asset_host}#{src}#{quote})"</span>
86: <span class="ruby-keyword kw">end</span>
87: <span class="ruby-keyword kw">end</span></pre>
</div>
</div>
- <div class='method public-class' id='method-M000012'>
- <a name='M000012'></a>
+ <div class='method public-class' id='method-M000016'>
+ <a name='M000016'></a>
<div class='synopsis'>
<span class='name'>min_filepath</span>
<span class='arguments'>(filepath)</span>
</div>
<div class='description'>
@@ -146,18 +155,18 @@
href="CSS.html">CSS</a> asset:
</p>
<pre>AssetHat::CSS.min_filepath('public/stylesheets/bundles/application.css')
 # => 'public/stylesheets/bundles/application.min.css'</pre>
</div>
<div class='source'>
- <a class='source-toggle' href='#' onclick="toggleCode('M000012-source'); return false">
+ <a class='source-toggle' href='#' onclick="toggleCode('M000016-source'); return false">
[show source]
</a>
- <pre id='M000012-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 14</span>
14: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">min_filepath</span>(<span class="ruby-identifier">filepath</span>)
15: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">min_filepath</span>(<span class="ruby-identifier">filepath</span>, <span class="ruby-value str">'css'</span>)
16: <span class="ruby-keyword kw">end</span></pre>
+ <pre id='M000016-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 14</span>
14: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">min_filepath</span>(<span class="ruby-identifier">filepath</span>)
15: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">min_filepath</span>(<span class="ruby-identifier">filepath</span>, <span class="ruby-value str">'css'</span>)
16: <span class="ruby-keyword kw">end</span></pre>
</div>
</div>
- <div class='method public-class' id='method-M000013'>
- <a name='M000013'></a>
+ <div class='method public-class' id='method-M000017'>
+ <a name='M000017'></a>
<div class='synopsis'>
<span class='name'>minify</span>
<span class='arguments'>(input_string, options={})</span>
</div>
<div class='description'>
@@ -166,20 +175,20 @@
href="CSS.html">CSS</a> minified. Options:
</p>
<dl>
<dt>engine</dt><dd>Default is <tt>:cssmin</tt>; see <a
href=CSS/Engines.html#method-c-cssmin><a
- href="CSS/Engines.html#M000017">Engines.cssmin</a></a>. Allowed values are
+ href="CSS/Engines.html#M000021">Engines.cssmin</a></a>. Allowed values are
in ENGINES.
</dd>
</dl>
</div>
<div class='source'>
- <a class='source-toggle' href='#' onclick="toggleCode('M000013-source'); return false">
+ <a class='source-toggle' href='#' onclick="toggleCode('M000017-source'); return false">
[show source]
</a>
- <pre id='M000013-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 23</span>
23: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">minify</span>(<span class="ruby-identifier">input_string</span>, <span class="ruby-identifier">options</span>={})
24: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">:engine</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:cssmin</span>)
25: 
26: <span class="ruby-identifier">engine</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:engine</span>].<span class="ruby-identifier">to_sym</span>
27: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">ENGINES</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">engine</span>)
28: <span class="ruby-identifier">raise</span> <span class="ruby-node">%Q{
29: Unknown CSS minification engine '#{engine}'.
30: Allowed: #{ENGINES.map{ |e| "'#{e}'" }.join(', ')}
31: }</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\s+/</span>, <span class="ruby-value str">' '</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">return</span>
32: <span class="ruby-keyword kw">end</span>
33: 
34: <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">CSS</span><span class="ruby-operator">::</span><span class="ruby-constant">Engines</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">engine</span>, <span class="ruby-identifier">input_string</span>)
35: <span class="ruby-keyword kw">end</span></pre>
+ <pre id='M000017-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 23</span>
23: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">minify</span>(<span class="ruby-identifier">input_string</span>, <span class="ruby-identifier">options</span>={})
24: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">:engine</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:cssmin</span>)
25: 
26: <span class="ruby-identifier">engine</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:engine</span>].<span class="ruby-identifier">to_sym</span>
27: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">ENGINES</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">engine</span>)
28: <span class="ruby-identifier">raise</span> <span class="ruby-node">%{
29: Unknown CSS minification engine '#{engine}'.
30: Allowed: #{ENGINES.map{ |e| "'#{e}'" }.join(', ')}
31: }</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\s+/</span>, <span class="ruby-value str">' '</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">return</span>
32: <span class="ruby-keyword kw">end</span>
33: 
34: <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">CSS</span><span class="ruby-operator">::</span><span class="ruby-constant">Engines</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">engine</span>, <span class="ruby-identifier">input_string</span>).<span class="ruby-identifier">strip</span>
35: <span class="ruby-keyword kw">end</span></pre>
</div>
</div>
</div>
</div>
</div>