doc/classes/AssetHatHelper.html in asset_hat-0.3.1 vs doc/classes/AssetHatHelper.html in asset_hat-0.4.0

- old
+ new

@@ -29,11 +29,11 @@ <span class='type'>Module</span> AssetHatHelper </h1> <ol class='paths'> <li> - <a href="../files/app/helpers/asset_hat_helper_rb.html">app/helpers/asset_hat_helper.rb</a> + <a href="../files/lib/asset_hat_helper_rb.html">lib/asset_hat_helper.rb</a> </li> </ol> </div> <div id='content'> <div id='text'> @@ -45,12 +45,13 @@ </div> <div id='method-list'> <h2>Methods</h2> <h3>public instance</h3> <ol> - <li><a href="#M000027">include_css</a></li> - <li><a href="#M000028">include_js</a></li> + <li><a href="#M000032">asset_path</a></li> + <li><a href="#M000030">include_css</a></li> + <li><a href="#M000031">include_js</a></li> </ol> </div> <div id='section'> <div id='constants-list'> <h2>Constants</h2> @@ -64,75 +65,118 @@ </table> </div> </div> <div id='methods'> <h2>Public instance methods</h2> - <div class='method public-instance' id='method-M000027'> - <a name='M000027'></a> + <div class='method public-instance' id='method-M000032'> + <a name='M000032'></a> <div class='synopsis'> + <span class='name'>asset_path</span> + <span class='arguments'>(type, source)</span> + </div> + <div class='description'> + <p> + Returns the public URL path to the given source file. + </p> + <p> + <tt>type</tt> argument: <tt>:css</tt> or <tt>:js</tt> + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000032-source'); return false"> + [show source] + </a> + <pre id='M000032-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 368</span>&#x000A;368: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">asset_path</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">source</span>)&#x000A;369: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_sym</span>&#x000A;370: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:css</span> ; <span class="ruby-identifier">stylesheet_path</span>(<span class="ruby-identifier">source</span>)&#x000A;371: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:js</span> ; <span class="ruby-identifier">javascript_path</span>(<span class="ruby-identifier">source</span>)&#x000A;372: <span class="ruby-keyword kw">else</span>&#x000A;373: <span class="ruby-identifier">raise</span> <span class="ruby-node">%{Unknown type &quot;#{type}&quot;; should be one of: #{TYPES.join(', ')}.}</span>&#x000A;374: <span class="ruby-keyword kw">end</span>&#x000A;375: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000030'> + <a name='M000030'></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#M000027">include_css</a></tt> is a smart + <tt><a href="AssetHatHelper.html#M000030">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: + Include a single, minified stylesheet: </p> <pre>include_css 'diagnostics'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/diagnostics.min.css&quot; media=&quot;screen,projection&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</pre> <p> - Include a single unminified stylesheet: + Include a single, unminified stylesheet: </p> <pre>include_css 'diagnostics.css'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/diagnostics.css&quot; media=&quot;screen,projection&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;</pre> <p> Include a bundle of stylesheets (i.e., a concatenated set of stylesheets; configure in config/assets.yml): </p> <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> + <pre>include_css 'reset', 'application'&#x000A;=&gt; &lt;link href=&quot;/stylesheets/reset.min.css&quot; ... /&gt;&#x000A; &lt;link href=&quot;/stylesheets/application.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> + <p> + Get the URL for a single, minified stylesheet: + </p> + <pre>include_css 'diagnostics', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/diagnostics.min.css'</pre> + <p> + Get the URL for a single, unminified stylesheet: + </p> + <pre>include_css 'diagnostics.css', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/diagnostics.css'</pre> + <p> + Get the URL for a bundle of stylesheets when environment <b>enables</b> + caching (e.g., staging, production): + </p> + <pre>include_css :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; '/stylesheets/bundles/application.min.css'</pre> + <p> + Get URLs for a bundle of stylesheets when environment <b>disables</b> + caching (e.g., development, test): + </p> + <pre>include_css :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; ['/stylesheets/reset.css', '/stylesheets/common.css', ...]</pre> + <p> + Get URLs for multiple stylesheets manually: + </p> + <pre>include_css 'reset', 'application', :only_url =&gt; true&#x000A;=&gt; ['/stylesheets/reset.css', '/stylesheets/application.css']</pre> </div> <div class='source'> - <a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false"> + <a class='source-toggle' href='#' onclick="toggleCode('M000030-source'); return false"> [show source] </a> - <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> + <pre id='M000030-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 159</span>&#x000A;159: <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;160: <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;161: &#x000A;162: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;163: <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;164: &#x000A;165: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;166: <span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys!</span>.<span class="ruby-identifier">reverse_merge!</span>(&#x000A;167: <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;168: <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;169: &#x000A;170: <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;171: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;172: <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;173: <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;174: <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;175: <span class="ruby-keyword kw">end</span>&#x000A;176: &#x000A;177: <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;178: <span class="ruby-identifier">html</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:html_safe</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">html</span>.<span class="ruby-identifier">html_safe</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">html</span>&#x000A;179: <span class="ruby-keyword kw">end</span></pre> </div> </div> - <div class='method public-instance' id='method-M000028'> - <a name='M000028'></a> + <div class='method public-instance' id='method-M000031'> + <a name='M000031'></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#M000028">include_js</a></tt> is a smart + <tt><a href="AssetHatHelper.html#M000031">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: + Include a single, minified JS file: </p> <pre>include_js 'application'&#x000A;=&gt; &lt;script src=&quot;/javascripts/application.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre> <p> - Include a single JS unminified file: + Include a single, unminified JS file: </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># 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> + <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.6.0'`.</pre> <p> Include a bundle of JS files (i.e., a concatenated set of files; configure 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> @@ -142,15 +186,46 @@ <pre>include_js :bundles =&gt; %w[plugins common]&#x000A;=&gt; &lt;script src=&quot;/javascripts/bundles/plugins.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script src=&quot;/javascripts/bundles/common.min.js&quot; ...&gt;&lt;/script&gt;</pre> <p> 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> + <p> + Get the URL for a single, minified JS file: + </p> + <pre>include_js 'application', :only_url =&gt; true&#x000A;=&gt; '/javascripts/application.min.js'</pre> + <p> + Get the URL for a single, unminified JS file: + </p> + <pre>include_js 'application.js', :only_url =&gt; true&#x000A;=&gt; '/javascripts/application.js', :only_url =&gt; true</pre> + <p> + Get the URL for jQuery: + </p> + <pre># Development/test environment:&#x000A;include_js :jquery, :only_url =&gt; true&#x000A;=&gt; '/javascripts/jquery-VERSION.min.js'&#x000A;&#x000A;# Staging/production environment:&#x000A;include_js :jquery, :only_url =&gt; true&#x000A;=&gt; 'http://ajax.googleapis.com/.../jquery.min.js'</pre> + <p> + Get the URL for a bundle of JS files when environment <b>enables</b> + caching (e.g., staging, production): + </p> + <pre>include_js :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; '/javascripts/bundles/application.min.js'</pre> + <p> + Get URLs for a bundle of JS files when environment <b>disables</b> caching + (e.g., development, test): + </p> + <pre>include_js :bundle =&gt; 'application', :only_url =&gt; true&#x000A;=&gt; ['/javascripts/jquery.plugin-foo.js',&#x000A; '/javascripts/jquery.plugin-bar.min.js',&#x000A; '/javascripts/json2.js',&#x000A; ...]</pre> + <p> + Get URLs for multiple JS files manually: + </p> + <pre>include_js 'json2', 'application', :only_url =&gt; true&#x000A;=&gt; ['/javascripts/json2.js', '/javascripts/application.js']</pre> + <p> + Load JS files with <a href="http://labjs.com">LABjs</a> (hosted either from + cdnjs or your own web server, if found in <tt>public/javascripts/</tt>): + </p> + <pre># config/assets.yml:&#x000A;js:&#x000A; vendors:&#x000A; lab_js:&#x000A; version: 1.x.x&#x000A;&#x000A;# Usage:&#x000A;include_js :jquery, :bundle =&gt; 'application', :loader =&gt; :lab_js&#x000A;=&gt; &lt;script src=&quot;http://ajax.cdnjs.com/.../1.x.x/LAB.min.js&quot; ...&gt;&lt;/script&gt;&#x000A; &lt;script type=&quot;text/javascript&quot;&gt;&#x000A; window.$LABinst=$LAB.&#x000A; script('http://ajax.googleapis.com/.../jquery.min.js').wait().&#x000A; script('/javascripts/bundles/application.min.js').wait();&#x000A; &lt;/script&gt;&#x000A;&#x000A;# For advanced fine-tuning, build the LABjs calls manually (based on&#x000A;# example from http://labjs.com/documentation.php ):&#x000A;&lt;script&gt;&#x000A; window.$LABinst = $LAB.&#x000A; script('&lt;%= include_js 'framework', :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js 'plugin.framework.js',&#x000A; :only_url =&gt; true %&gt;').&#x000A; script('&lt;%= include_js 'myplugin.framework.js',&#x000A; :only_url =&gt; true %&gt;').wait().&#x000A; script('&lt;%= include_js 'init.js', :only_url =&gt; true %&gt;').wait();&#x000A;&lt;/script&gt;&#x000A;&#x000A;# If you want to execute an inline &lt;script&gt; block that relies on any&#x000A;# of these dependencies, use the JS variable `window.$LABinst`.&#x000A;# Example (using jQuery to handle when DOM is ready):&#x000A;&lt;script&gt;&#x000A;window.$LABinst(function(){&#x000A; console.log('JS dependencies are ready');&#x000A; $(function(){&#x000A; console.log('DOM is ready');&#x000A; });&#x000A;});&#x000A;&lt;/script&gt;</pre> </div> <div class='source'> - <a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false"> + <a class='source-toggle' href='#' onclick="toggleCode('M000031-source'); return false"> [show source] </a> - <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> + <pre id='M000031-source'> <span class="ruby-comment cmt"># File lib/asset_hat_helper.rb, line 295</span>&#x000A;295: <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;296: <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;297: &#x000A;298: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">html_cache</span> <span class="ruby-operator">||=</span> {}&#x000A;299: <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;300: &#x000A;301: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>&#x000A;302: <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;303: <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;304: &#x000A;305: <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;306: <span class="ruby-comment cmt"># Generate HTML and write to cache</span>&#x000A;307: &#x000A;308: <span class="ruby-identifier">htmls</span> = []&#x000A;309: <span class="ruby-identifier">include_assets_options</span> = <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;310: <span class="ruby-identifier">loader</span> = <span class="ruby-keyword kw">nil</span>&#x000A;311: &#x000A;312: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:loader</span>].<span class="ruby-identifier">present?</span>&#x000A;313: <span class="ruby-identifier">loader</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:loader</span>)&#x000A;314: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">:only_url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>)&#x000A;315: <span class="ruby-keyword kw">end</span>&#x000A;316: &#x000A;317: <span class="ruby-comment cmt"># Get vendor HTML/URLs</span>&#x000A;318: <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;319: &#x000A;320: <span class="ruby-comment cmt"># Add HTML inclusions for vendors</span>&#x000A;321: <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;322: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">vendor</span>&#x000A;323: <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;324: <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;325: <span class="ruby-identifier">htmls</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>,&#x000A;326: <span class="ruby-identifier">include_assets_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:cache</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>).&#x000A;327: <span class="ruby-identifier">except</span>(<span class="ruby-identifier">:bundle</span>, <span class="ruby-identifier">:bundles</span>))&#x000A;328: <span class="ruby-keyword kw">end</span>&#x000A;329: &#x000A;330: <span class="ruby-comment cmt"># Get non-vendor HTML/URLs</span>&#x000A;331: <span class="ruby-identifier">htmls</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">include_assets_options</span>]))&#x000A;332: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">reject!</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:blank?</span>)&#x000A;333: &#x000A;334: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">loader</span>&#x000A;335: <span class="ruby-comment cmt"># `htmls` actually contains URLs; convert to an HTML/JS block</span>&#x000A;336: <span class="ruby-identifier">urls</span> = <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">flatten</span>&#x000A;337: <span class="ruby-identifier">htmls</span> = []&#x000A;338: &#x000A;339: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">loader</span>&#x000A;340: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:lab_js</span>&#x000A;341: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">include_js</span>(<span class="ruby-identifier">:lab_js</span>)&#x000A;342: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;script type=&quot;text/javascript&quot;&gt;'</span>&#x000A;343: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</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">loader_js</span>(<span class="ruby-identifier">:lab_js</span>, <span class="ruby-identifier">:urls</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">urls</span>)&#x000A;344: <span class="ruby-identifier">htmls</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;/script&gt;'</span>&#x000A;345: <span class="ruby-keyword kw">end</span>&#x000A;346: <span class="ruby-keyword kw">end</span>&#x000A;347: &#x000A;348: <span class="ruby-comment cmt"># Convert to a URL (string), array of URLs, or one long HTML string</span>&#x000A;349: <span class="ruby-identifier">html</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only_url</span>]&#x000A;350: <span class="ruby-comment cmt"># Return one URL (string) or multiple (array of strings).</span>&#x000A;351: <span class="ruby-comment cmt"># Not actually HTML.</span>&#x000A;352: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">flatten!</span>&#x000A;353: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">htmls</span>&#x000A;354: <span class="ruby-keyword kw">else</span>&#x000A;355: <span class="ruby-comment cmt"># Return one long string of HTML</span>&#x000A;356: <span class="ruby-identifier">htmls</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>).<span class="ruby-identifier">strip</span>&#x000A;357: <span class="ruby-keyword kw">end</span>&#x000A;358: <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;359: <span class="ruby-keyword kw">end</span>&#x000A;360: &#x000A;361: <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;362: <span class="ruby-identifier">html</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:html_safe</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">html</span>.<span class="ruby-identifier">html_safe</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">html</span>&#x000A;363: <span class="ruby-keyword kw">end</span></pre> </div> </div> </div> </div> </div>