doc/classes/AssetHatHelper.html in asset_hat-0.2.1 vs doc/classes/AssetHatHelper.html in asset_hat-0.3.0

- old
+ new

@@ -45,12 +45,12 @@ </div> <div id='method-list'> <h2>Methods</h2> <h3>public instance</h3> <ol> - <li><a href="#M000023">include_css</a></li> - <li><a href="#M000024">include_js</a></li> + <li><a href="#M000027">include_css</a></li> + <li><a href="#M000028">include_js</a></li> </ol> </div> <div id='section'> <div id='constants-list'> <h2>Constants</h2> @@ -64,19 +64,19 @@ </table> </div> </div> <div id='methods'> <h2>Public instance methods</h2> - <div class='method public-instance' id='method-M000023'> - <a name='M000023'></a> + <div class='method public-instance' id='method-M000027'> + <a name='M000027'></a> <div class='synopsis'> <span class='name'>include_css</span> <span class='arguments'>(*args)</span> </div> <div class='description'> <p> - <tt><a href="AssetHatHelper.html#M000023">include_css</a></tt> is a smart + <tt><a href="AssetHatHelper.html#M000027">include_css</a></tt> is a smart wrapper for Rails&#8217; <tt>stylesheet_link_tag</tt>. The two can be used together while migrating to <a href="AssetHat.html">AssetHat</a>. </p> <p> Include a single stylesheet: @@ -93,27 +93,31 @@ <pre>include_css :bundle =&gt; 'application'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/bundles/application.min.css&quot; ... /&gt;</pre> <p> Include multiple stylesheets separately (not as cool): </p> <pre>include_css 'reset', 'application', 'clearfix'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/reset.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/application.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/clearfix.min.css&quot; ... /&gt;</pre> + <p> + Include a stylesheet with extra media types: + </p> + <pre>include_css 'mobile', :media =&gt; 'handheld,screen,projection'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/mobile.min.css&quot;&#x000A; media=&quot;handheld,screen,projection&quot; ... /&gt;</pre> </div> <div class='source'> - <a class='source-toggle' href='#' onclick="toggleCode('M000023-source'); return false"> + <a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false"> [show source] </a> - <pre id='M000023-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 122</span>&#x000A;122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_css</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;123: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;124: &#x000A;125: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;126: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>] <span class="ruby-operator">||=</span> {}&#x000A;127: <span class="ruby-identifier">cache_key</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">inspect</span>&#x000A;128: &#x000A;129: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;130: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;131: <span class="ruby-identifier">html</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>] = <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:css</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;132: <span class="ruby-keyword kw">end</span>&#x000A;133: &#x000A;134: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;135: <span class="ruby-identifier">html</span>&#x000A;136: <span class="ruby-keyword kw">end</span></pre> + <pre id='M000027-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 129</span>&#x000A;129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_css</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;130: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;131: &#x000A;132: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;133: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>] <span class="ruby-operator">||=</span> {}&#x000A;134: &#x000A;135: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;136: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(&#x000A;137: <span class="ruby-identifier">:media</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'screen,projection'</span>, <span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>)&#x000A;138: <span class="ruby-identifier">cache_key</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]).<span class="ruby-identifier">inspect</span>&#x000A;139: &#x000A;140: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;141: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;142: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ssl</span>] <span class="ruby-operator">&amp;&amp;=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">ssl_asset_host_differs?</span>&#x000A;143: <span class="ruby-identifier">html</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>] =&#x000A;144: <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:css</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]))&#x000A;145: <span class="ruby-keyword kw">end</span>&#x000A;146: &#x000A;147: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:css</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;148: <span class="ruby-identifier">html</span>&#x000A;149: <span class="ruby-keyword kw">end</span></pre> </div> </div> - <div class='method public-instance' id='method-M000024'> - <a name='M000024'></a> + <div class='method public-instance' id='method-M000028'> + <a name='M000028'></a> <div class='synopsis'> <span class='name'>include_js</span> <span class='arguments'>(*args)</span> </div> <div class='description'> <p> - <tt><a href="AssetHatHelper.html#M000024">include_js</a></tt> is a smart + <tt><a href="AssetHatHelper.html#M000028">include_js</a></tt> is a smart wrapper for Rails&#8217; <tt>javascript_include_tag</tt>. The two can be used together while migrating to <a href="AssetHat.html">AssetHat</a>. </p> <p> Include a single JS file: @@ -124,14 +128,14 @@ </p> <pre>include_js 'application.js'&#x000A;=&gt; &lt;script src=&quot;/javascripts/application.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre> <p> Include jQuery: </p> - <pre>include_js :jquery # Development/test environment&#x000A;=&gt; &lt;script src=&quot;/javascripts/jquery-VERSION.min.js&quot; ...&gt;&lt;/script&gt;&#x000A;include_js :jquery # Staging/production environment&#x000A;=&gt; &lt;script src=&quot;http://ajax.googleapis.com/.../jquery.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; # Set jQuery versions either in `config/assets.yml`, or by using&#x000A; # `include_js :jquery, :version =&gt; '1.4'`.</pre> + <pre># Development/test environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;/javascripts/jquery-VERSION.min.js&quot; ...&gt;&lt;/script&gt;&#x000A;&#x000A;# Staging/production environment:&#x000A;include_js :jquery&#x000A;=&gt; &lt;script src=&quot;http://ajax.googleapis.com/.../jquery.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; # Set jQuery versions either in `config/assets.yml`, or by using&#x000A; # `include_js :jquery, :version =&gt; '1.4'`.</pre> <p> Include a bundle of JS files (i.e., a concatenated set of files; configure - in config/assets.yml): + in <tt>config/assets.yml</tt>): </p> <pre>include_js :bundle =&gt; 'application'&#x000A;=&gt; &lt;script src=&quot;/javascripts/bundles/application.min.js&quot; ...&gt;&lt;/script&gt;</pre> <p> Include multiple bundles of JS files: </p> @@ -140,13 +144,13 @@ Include multiple JS files separately (not as cool): </p> <pre>include_js 'bloombox', 'jquery.cookie', 'jquery.json.min'&#x000A;=&gt; &lt;script src=&quot;/javascripts/bloombox.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script src=&quot;/javascripts/jquery.cookie.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script src=&quot;/javascripts/jquery.json.min.js&quot; ...&gt;&lt;/script&gt;</pre> </div> <div class='source'> - <a class='source-toggle' href='#' onclick="toggleCode('M000024-source'); return false"> + <a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false"> [show source] </a> - <pre id='M000024-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 173</span>&#x000A;173: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;174: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;175: &#x000A;176: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;177: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>] <span class="ruby-operator">||=</span> {}&#x000A;178: <span class="ruby-identifier">cache_key</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">inspect</span>&#x000A;179: &#x000A;180: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;181: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;182: &#x000A;183: <span class="ruby-identifier">html</span> = []&#x000A;184: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;185: &#x000A;186: <span class="ruby-identifier">included_vendors</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">&amp;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">VENDORS</span>)&#x000A;187: <span class="ruby-identifier">included_vendors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vendor</span><span class="ruby-operator">|</span>&#x000A;188: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;189: <span class="ruby-identifier">src</span> = <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">source_for</span>(<span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">:version</span>))&#x000A;190: <span class="ruby-identifier">html</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-identifier">src</span>, <span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)&#x000A;191: <span class="ruby-keyword kw">end</span>&#x000A;192: &#x000A;193: <span class="ruby-identifier">html</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]))&#x000A;194: <span class="ruby-identifier">html</span> = <span class="ruby-identifier">html</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;195: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>] = <span class="ruby-identifier">html</span>&#x000A;196: <span class="ruby-keyword kw">end</span>&#x000A;197: &#x000A;198: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;199: <span class="ruby-identifier">html</span>&#x000A;200: <span class="ruby-keyword kw">end</span></pre> + <pre id='M000028-source'> <span class="ruby-comment cmt"># File app/helpers/asset_hat_helper.rb, line 189</span>&#x000A;189: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;190: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">blank?</span>&#x000A;191: &#x000A;192: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;193: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>] <span class="ruby-operator">||=</span> {}&#x000A;194: &#x000A;195: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;196: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(<span class="ruby-identifier">:ssl</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">ssl?</span>)&#x000A;197: <span class="ruby-identifier">cache_key</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]).<span class="ruby-identifier">inspect</span>&#x000A;198: &#x000A;199: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">cache?</span> <span class="ruby-operator">||</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>].<span class="ruby-identifier">blank?</span>&#x000A;200: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;201: &#x000A;202: <span class="ruby-identifier">html</span> = []&#x000A;203: <span class="ruby-identifier">included_vendors</span> = (<span class="ruby-identifier">args</span> <span class="ruby-operator">&amp;</span> <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">VENDORS</span>)&#x000A;204: <span class="ruby-identifier">included_vendors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">vendor</span><span class="ruby-operator">|</span>&#x000A;205: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;206: <span class="ruby-identifier">src</span> = <span class="ruby-constant">AssetHat</span><span class="ruby-operator">::</span><span class="ruby-constant">JS</span><span class="ruby-operator">::</span><span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">source_for</span>(&#x000A;207: <span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>))&#x000A;208: <span class="ruby-identifier">html</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-identifier">src</span>, <span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)&#x000A;209: <span class="ruby-keyword kw">end</span>&#x000A;210: &#x000A;211: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except!</span> <span class="ruby-identifier">:ssl</span>, <span class="ruby-identifier">:version</span>&#x000A;212: &#x000A;213: <span class="ruby-identifier">html</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_assets</span>(<span class="ruby-identifier">:js</span>, <span class="ruby-operator">*</span>(<span class="ruby-identifier">args</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">options</span>]))&#x000A;214: <span class="ruby-identifier">html</span> = <span class="ruby-identifier">html</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;215: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>] = <span class="ruby-identifier">html</span>&#x000A;216: <span class="ruby-keyword kw">end</span>&#x000A;217: &#x000A;218: <span class="ruby-identifier">html</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span>[<span class="ruby-identifier">:js</span>][<span class="ruby-identifier">cache_key</span>]&#x000A;219: <span class="ruby-identifier">html</span>&#x000A;220: <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> </div> </div>