asset_hat 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +37 -0
- data/HISTORY +10 -0
- data/README.rdoc +117 -75
- data/Rakefile +4 -4
- data/VERSION.yml +2 -2
- data/asset_hat.gemspec +69 -7
- data/config/assets.yml +46 -24
- data/doc/classes/AssetHat.html +183 -118
- data/doc/classes/AssetHat/CSS.html +21 -21
- data/doc/classes/AssetHat/CSS/Engines.html +10 -10
- data/doc/classes/AssetHat/JS.html +13 -13
- data/doc/classes/AssetHat/JS/Engines.html +10 -10
- data/doc/classes/AssetHat/JS/Vendors.html +85 -22
- data/doc/classes/AssetHatHelper.html +94 -19
- data/doc/created.rid +1 -1
- data/doc/files/HISTORY.html +20 -2
- data/doc/files/LICENSE.html +1 -1
- data/doc/files/README_rdoc.html +87 -31
- data/doc/files/lib/asset_hat/capistrano_rb.html +1 -1
- data/doc/files/lib/asset_hat/css_rb.html +1 -1
- data/doc/files/lib/asset_hat/initializers/action_view_rb.html +49 -0
- data/doc/files/lib/asset_hat/initializers/cache_last_commit_ids_rb.html +49 -0
- data/doc/files/lib/asset_hat/js/vendors_rb.html +1 -1
- data/doc/files/lib/asset_hat/js_rb.html +1 -1
- data/doc/files/lib/asset_hat/railtie_rb.html +61 -0
- data/doc/files/lib/asset_hat/tasks/css_rb.html +1 -1
- data/doc/files/lib/asset_hat/tasks/js_rb.html +1 -1
- data/doc/files/lib/asset_hat/tasks_rb.html +2 -1
- data/doc/files/lib/asset_hat/unicorn_rb.html +58 -0
- data/doc/files/lib/asset_hat/vcs_rb.html +1 -1
- data/doc/files/lib/asset_hat/version_rb.html +1 -1
- data/doc/files/{app/helpers → lib}/asset_hat_helper_rb.html +3 -3
- data/doc/files/lib/asset_hat_rb.html +9 -1
- data/doc/files/lib/tasks/asset_hat_rake.html +54 -0
- data/doc/fr_file_index.html +6 -1
- data/doc/fr_method_index.html +60 -52
- data/lib/asset_hat.rb +104 -59
- data/lib/asset_hat/initializers/action_view.rb +1 -0
- data/lib/asset_hat/initializers/cache_last_commit_ids.rb +1 -0
- data/lib/asset_hat/js/vendors.rb +198 -72
- data/lib/asset_hat/railtie.rb +19 -0
- data/lib/asset_hat/tasks.rb +5 -2
- data/lib/asset_hat/unicorn.rb +9 -0
- data/lib/asset_hat/vcs.rb +3 -2
- data/{app/helpers → lib}/asset_hat_helper.rb +184 -29
- data/{tasks → lib/tasks}/asset_hat.rake +0 -0
- data/rails/init.rb +2 -2
- data/test/asset_hat_helper_test.rb +731 -148
- data/test/asset_hat_test.rb +23 -2
- data/test/test_helper.rb +4 -8
- metadata +311 -30
@@ -46,10 +46,10 @@
|
|
46
46
|
<h2>Methods</h2>
|
47
47
|
<h3>public class</h3>
|
48
48
|
<ol>
|
49
|
-
<li><a href="#
|
50
|
-
<li><a href="#
|
51
|
-
<li><a href="#
|
52
|
-
<li><a href="#
|
49
|
+
<li><a href="#M000021">add_asset_commit_ids</a></li>
|
50
|
+
<li><a href="#M000022">add_asset_hosts</a></li>
|
51
|
+
<li><a href="#M000019">min_filepath</a></li>
|
52
|
+
<li><a href="#M000020">minify</a></li>
|
53
53
|
</ol>
|
54
54
|
</div>
|
55
55
|
<div id='section'>
|
@@ -76,8 +76,8 @@
|
|
76
76
|
</div>
|
77
77
|
<div id='methods'>
|
78
78
|
<h2>Public class methods</h2>
|
79
|
-
<div class='method public-class' id='method-
|
80
|
-
<a name='
|
79
|
+
<div class='method public-class' id='method-M000021'>
|
80
|
+
<a name='M000021'></a>
|
81
81
|
<div class='synopsis'>
|
82
82
|
<span class='name'>add_asset_commit_ids</span>
|
83
83
|
<span class='arguments'>(css)</span>
|
@@ -93,14 +93,14 @@
|
|
93
93
|
</p>
|
94
94
|
</div>
|
95
95
|
<div class='source'>
|
96
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
96
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000021-source'); return false">
|
97
97
|
[show source]
|
98
98
|
</a>
|
99
|
-
<pre id='
|
99
|
+
<pre id='M000021-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>
|
100
100
|
</div>
|
101
101
|
</div>
|
102
|
-
<div class='method public-class' id='method-
|
103
|
-
<a name='
|
102
|
+
<div class='method public-class' id='method-M000022'>
|
103
|
+
<a name='M000022'></a>
|
104
104
|
<div class='synopsis'>
|
105
105
|
<span class='name'>add_asset_hosts</span>
|
106
106
|
<span class='arguments'>(css, asset_host, options={})</span>
|
@@ -137,14 +137,14 @@
|
|
137
137
|
</dl>
|
138
138
|
</div>
|
139
139
|
<div class='source'>
|
140
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
140
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000022-source'); return false">
|
141
141
|
[show source]
|
142
142
|
</a>
|
143
|
-
<pre id='
|
143
|
+
<pre id='M000022-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>
|
144
144
|
</div>
|
145
145
|
</div>
|
146
|
-
<div class='method public-class' id='method-
|
147
|
-
<a name='
|
146
|
+
<div class='method public-class' id='method-M000019'>
|
147
|
+
<a name='M000019'></a>
|
148
148
|
<div class='synopsis'>
|
149
149
|
<span class='name'>min_filepath</span>
|
150
150
|
<span class='arguments'>(filepath)</span>
|
@@ -157,14 +157,14 @@
|
|
157
157
|
<pre>AssetHat::CSS.min_filepath('public/stylesheets/bundles/application.css')
 # => 'public/stylesheets/bundles/application.min.css'</pre>
|
158
158
|
</div>
|
159
159
|
<div class='source'>
|
160
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
160
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000019-source'); return false">
|
161
161
|
[show source]
|
162
162
|
</a>
|
163
|
-
<pre id='
|
163
|
+
<pre id='M000019-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>
|
164
164
|
</div>
|
165
165
|
</div>
|
166
|
-
<div class='method public-class' id='method-
|
167
|
-
<a name='
|
166
|
+
<div class='method public-class' id='method-M000020'>
|
167
|
+
<a name='M000020'></a>
|
168
168
|
<div class='synopsis'>
|
169
169
|
<span class='name'>minify</span>
|
170
170
|
<span class='arguments'>(input_string, options={})</span>
|
@@ -177,17 +177,17 @@
|
|
177
177
|
<dl>
|
178
178
|
<dt>engine</dt><dd>Default is <tt>:cssmin</tt>; see <a
|
179
179
|
href=CSS/Engines.html#method-c-cssmin><a
|
180
|
-
href="CSS/Engines.html#
|
180
|
+
href="CSS/Engines.html#M000024">Engines.cssmin</a></a>. Allowed values are
|
181
181
|
in ENGINES.
|
182
182
|
|
183
183
|
</dd>
|
184
184
|
</dl>
|
185
185
|
</div>
|
186
186
|
<div class='source'>
|
187
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
187
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000020-source'); return false">
|
188
188
|
[show source]
|
189
189
|
</a>
|
190
|
-
<pre id='
|
190
|
+
<pre id='M000020-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>
|
191
191
|
</div>
|
192
192
|
</div>
|
193
193
|
</div>
|
@@ -47,15 +47,15 @@
|
|
47
47
|
<h2>Methods</h2>
|
48
48
|
<h3>public class</h3>
|
49
49
|
<ol>
|
50
|
-
<li><a href="#
|
51
|
-
<li><a href="#
|
50
|
+
<li><a href="#M000024">cssmin</a></li>
|
51
|
+
<li><a href="#M000023">weak</a></li>
|
52
52
|
</ol>
|
53
53
|
</div>
|
54
54
|
<div id='section'>
|
55
55
|
<div id='methods'>
|
56
56
|
<h2>Public class methods</h2>
|
57
|
-
<div class='method public-class' id='method-
|
58
|
-
<a name='
|
57
|
+
<div class='method public-class' id='method-M000024'>
|
58
|
+
<a name='M000024'></a>
|
59
59
|
<div class='synopsis'>
|
60
60
|
<span class='name'>cssmin</span>
|
61
61
|
<span class='arguments'>(input_string)</span>
|
@@ -79,14 +79,14 @@
|
|
79
79
|
</ul>
|
80
80
|
</div>
|
81
81
|
<div class='source'>
|
82
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
82
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000024-source'); return false">
|
83
83
|
[show source]
|
84
84
|
</a>
|
85
|
-
<pre id='
|
85
|
+
<pre id='M000024-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 116</span>
116: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cssmin</span>(<span class="ruby-identifier">input_string</span>)
117: <span class="ruby-identifier">output</span> = <span class="ruby-constant">CSSMin</span>.<span class="ruby-identifier">minify</span>(<span class="ruby-identifier">input_string</span>)
118: 
119: <span class="ruby-comment cmt"># Remove rules that have empty declaration blocks</span>
120: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\}([^\}]+\{;\}){1,}/</span>, <span class="ruby-value str">'}'</span>)
121: 
122: <span class="ruby-identifier">output</span>
123: <span class="ruby-keyword kw">end</span></pre>
|
86
86
|
</div>
|
87
87
|
</div>
|
88
|
-
<div class='method public-class' id='method-
|
89
|
-
<a name='
|
88
|
+
<div class='method public-class' id='method-M000023'>
|
89
|
+
<a name='M000023'></a>
|
90
90
|
<div class='synopsis'>
|
91
91
|
<span class='name'>weak</span>
|
92
92
|
<span class='arguments'>(input_string)</span>
|
@@ -100,10 +100,10 @@
|
|
100
100
|
</p>
|
101
101
|
</div>
|
102
102
|
<div class='source'>
|
103
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
103
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000023-source'); return false">
|
104
104
|
[show source]
|
105
105
|
</a>
|
106
|
-
<pre id='
|
106
|
+
<pre id='M000023-source'> <span class="ruby-comment cmt"># File lib/asset_hat/css.rb, line 94</span>
 94: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">weak</span>(<span class="ruby-identifier">input_string</span>)
 95: <span class="ruby-identifier">input</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input_string</span>)
 96: <span class="ruby-identifier">output</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
 97: 
 98: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
 99: <span class="ruby-comment cmt"># Remove indentation and trailing whitespace (including line breaks)</span>
100: <span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip!</span>
101: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">blank?</span>
102: 
103: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">line</span>
104: <span class="ruby-keyword kw">end</span>
105: 
106: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">rewind</span>
107: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">read</span>
108: <span class="ruby-keyword kw">end</span></pre>
|
107
107
|
</div>
|
108
108
|
</div>
|
109
109
|
</div>
|
@@ -31,10 +31,10 @@
|
|
31
31
|
</h1>
|
32
32
|
<ol class='paths'>
|
33
33
|
<li>
|
34
|
-
<a href="../../files/lib/asset_hat/
|
34
|
+
<a href="../../files/lib/asset_hat/js_rb.html">lib/asset_hat/js.rb</a>
|
35
35
|
</li>
|
36
36
|
<li class='other'>
|
37
|
-
<a href="../../files/lib/asset_hat/
|
37
|
+
<a href="../../files/lib/asset_hat/js/vendors_rb.html">lib/asset_hat/js/vendors.rb</a>
|
38
38
|
</li>
|
39
39
|
<li>
|
40
40
|
<a class='show' href='#' onclick='this.parentNode.parentNode.className += " expanded"; this.parentNode.removeChild(this); return false'>show all</a>
|
@@ -52,8 +52,8 @@
|
|
52
52
|
<h2>Methods</h2>
|
53
53
|
<h3>public class</h3>
|
54
54
|
<ol>
|
55
|
-
<li><a href="#
|
56
|
-
<li><a href="#
|
55
|
+
<li><a href="#M000025">min_filepath</a></li>
|
56
|
+
<li><a href="#M000026">minify</a></li>
|
57
57
|
</ol>
|
58
58
|
</div>
|
59
59
|
<div id='section'>
|
@@ -92,8 +92,8 @@
|
|
92
92
|
</div>
|
93
93
|
<div id='methods'>
|
94
94
|
<h2>Public class methods</h2>
|
95
|
-
<div class='method public-class' id='method-
|
96
|
-
<a name='
|
95
|
+
<div class='method public-class' id='method-M000025'>
|
96
|
+
<a name='M000025'></a>
|
97
97
|
<div class='synopsis'>
|
98
98
|
<span class='name'>min_filepath</span>
|
99
99
|
<span class='arguments'>(filepath)</span>
|
@@ -106,14 +106,14 @@
|
|
106
106
|
<pre>AssetHat::JS.min_filepath('public/javascripts/bundles/application.js')
 # => 'public/javascripts/bundles/application.min.js'</pre>
|
107
107
|
</div>
|
108
108
|
<div class='source'>
|
109
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
109
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000025-source'); return false">
|
110
110
|
[show source]
|
111
111
|
</a>
|
112
|
-
<pre id='
|
112
|
+
<pre id='M000025-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js.rb, line 19</span>
19: <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>)
20: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">min_filepath</span>(<span class="ruby-identifier">filepath</span>, <span class="ruby-value str">'js'</span>)
21: <span class="ruby-keyword kw">end</span></pre>
|
113
113
|
</div>
|
114
114
|
</div>
|
115
|
-
<div class='method public-class' id='method-
|
116
|
-
<a name='
|
115
|
+
<div class='method public-class' id='method-M000026'>
|
116
|
+
<a name='M000026'></a>
|
117
117
|
<div class='synopsis'>
|
118
118
|
<span class='name'>minify</span>
|
119
119
|
<span class='arguments'>(input_string, options={})</span>
|
@@ -125,17 +125,17 @@
|
|
125
125
|
</p>
|
126
126
|
<dl>
|
127
127
|
<dt>engine</dt><dd>Default is <tt>:jsmin</tt>; see <a href=JS/Engines.html#method-c-jsmin><a
|
128
|
-
href="JS/Engines.html#
|
128
|
+
href="JS/Engines.html#M000029">Engines.jsmin</a></a>. Allowed values are in
|
129
129
|
ENGINES.
|
130
130
|
|
131
131
|
</dd>
|
132
132
|
</dl>
|
133
133
|
</div>
|
134
134
|
<div class='source'>
|
135
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
135
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000026-source'); return false">
|
136
136
|
[show source]
|
137
137
|
</a>
|
138
|
-
<pre id='
|
138
|
+
<pre id='M000026-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js.rb, line 28</span>
28: <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>={})
29: <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">:jsmin</span>)
30: 
31: <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>
32: <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>)
33: <span class="ruby-identifier">raise</span> <span class="ruby-node">%{
34: Unknown JS minification engine '#{engine}'.
35: Allowed: #{ENGINES.map{ |e| "'#{e}'" }.join(', ')}
36: }</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>
37: <span class="ruby-keyword kw">end</span>
38: 
39: <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">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>
40: <span class="ruby-keyword kw">end</span></pre>
|
139
139
|
</div>
|
140
140
|
</div>
|
141
141
|
</div>
|
@@ -46,15 +46,15 @@
|
|
46
46
|
<h2>Methods</h2>
|
47
47
|
<h3>public class</h3>
|
48
48
|
<ol>
|
49
|
-
<li><a href="#
|
50
|
-
<li><a href="#
|
49
|
+
<li><a href="#M000029">jsmin</a></li>
|
50
|
+
<li><a href="#M000028">weak</a></li>
|
51
51
|
</ol>
|
52
52
|
</div>
|
53
53
|
<div id='section'>
|
54
54
|
<div id='methods'>
|
55
55
|
<h2>Public class methods</h2>
|
56
|
-
<div class='method public-class' id='method-
|
57
|
-
<a name='
|
56
|
+
<div class='method public-class' id='method-M000029'>
|
57
|
+
<a name='M000029'></a>
|
58
58
|
<div class='synopsis'>
|
59
59
|
<span class='name'>jsmin</span>
|
60
60
|
<span class='arguments'>(input_string)</span>
|
@@ -77,14 +77,14 @@
|
|
77
77
|
</ul>
|
78
78
|
</div>
|
79
79
|
<div class='source'>
|
80
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
80
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000029-source'); return false">
|
81
81
|
[show source]
|
82
82
|
</a>
|
83
|
-
<pre id='
|
83
|
+
<pre id='M000029-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js.rb, line 79</span>
79: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">jsmin</span>(<span class="ruby-identifier">input_string</span>)
80: <span class="ruby-constant">JSMin</span>.<span class="ruby-identifier">minify</span>(<span class="ruby-identifier">input_string</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>)
81: <span class="ruby-keyword kw">end</span></pre>
|
84
84
|
</div>
|
85
85
|
</div>
|
86
|
-
<div class='method public-class' id='method-
|
87
|
-
<a name='
|
86
|
+
<div class='method public-class' id='method-M000028'>
|
87
|
+
<a name='M000028'></a>
|
88
88
|
<div class='synopsis'>
|
89
89
|
<span class='name'>weak</span>
|
90
90
|
<span class='arguments'>(input_string)</span>
|
@@ -103,10 +103,10 @@
|
|
103
103
|
</ul>
|
104
104
|
</div>
|
105
105
|
<div class='source'>
|
106
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
106
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false">
|
107
107
|
[show source]
|
108
108
|
</a>
|
109
|
-
<pre id='
|
109
|
+
<pre id='M000028-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js.rb, line 48</span>
48: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">weak</span>(<span class="ruby-identifier">input_string</span>)
49: <span class="ruby-identifier">input</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input_string</span>)
50: <span class="ruby-identifier">output</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
51: 
52: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
53: <span class="ruby-comment cmt"># Remove indentation and trailing whitespace</span>
54: <span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip!</span>
55: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">blank?</span>
56: 
57: <span class="ruby-comment cmt"># Skip single-line comments</span>
58: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\/\//</span>).<span class="ruby-identifier">nil?</span>
59: <span class="ruby-comment cmt"># TODO: Also skip single-line comments that began mid-line, but not</span>
60: <span class="ruby-comment cmt"># inside a string or regex</span>
61: 
62: <span class="ruby-comment cmt"># TODO: Skip multi-line comments</span>
63: <span class="ruby-comment cmt"># - Should not strip from within a string or regex</span>
64: <span class="ruby-comment cmt"># - Should not strip comments that begin with `/*!` (e.g., licenses)</span>
65: 
66: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">line</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>)
67: <span class="ruby-keyword kw">end</span>
68: 
69: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">rewind</span>
70: <span class="ruby-identifier">output</span>.<span class="ruby-identifier">read</span>
71: <span class="ruby-keyword kw">end</span></pre>
|
110
110
|
</div>
|
111
111
|
</div>
|
112
112
|
</div>
|
@@ -47,7 +47,7 @@
|
|
47
47
|
<h2>Methods</h2>
|
48
48
|
<h3>public class</h3>
|
49
49
|
<ol>
|
50
|
-
<li><a href="#
|
50
|
+
<li><a href="#M000027">source_for</a></li>
|
51
51
|
</ol>
|
52
52
|
</div>
|
53
53
|
<div id='section'>
|
@@ -56,74 +56,137 @@
|
|
56
56
|
<div class='name-list'>
|
57
57
|
<table summary='Constants'>
|
58
58
|
<tr class='top-aligned-row context-row'>
|
59
|
-
<td class='context-item-name'>
|
59
|
+
<td class='context-item-name'>VENDORS_ON_GOOGLE_CDN</td>
|
60
60
|
<td>=</td>
|
61
|
-
<td class='context-item-value'>[ :
|
61
|
+
<td class='context-item-value'>[ :dojo, :ext_core, :jquery, :jquery_ui, :mootools, :prototype, :scriptaculous, :swfobject, :webfont, :yui ]</td>
|
62
62
|
<td> </td>
|
63
63
|
<td class='context-item-desc'>
|
64
64
|
|
65
65
|
A list of supported 3rd-party JavaScript plugin/vendor names. Homepages:
|
66
66
|
|
67
67
|
<ul>
|
68
|
-
<li
|
68
|
+
<li>Frameworks/libraries:
|
69
69
|
|
70
|
-
|
71
|
-
<li><a href="http://
|
70
|
+
<ul>
|
71
|
+
<li><a href="http://dojotoolkit.org/">Dojo</a>
|
72
72
|
|
73
73
|
</li>
|
74
|
-
<li><a href="http://
|
74
|
+
<li><a href="http://extjs.com/products/extcore/">Ext Core</a>
|
75
75
|
|
76
76
|
</li>
|
77
|
-
<li><a href="http://
|
77
|
+
<li><a href="http://jqueryui.com/">jQuery UI</a>
|
78
78
|
|
79
79
|
</li>
|
80
|
-
<li><a href="http://
|
80
|
+
<li><a href="http://jquery.com/">jQuery</a>
|
81
81
|
|
82
82
|
</li>
|
83
|
-
<li><a href="http://
|
83
|
+
<li><a href="http://mootools.net/">MooTools</a>
|
84
84
|
|
85
85
|
</li>
|
86
|
-
<li><a href="http://
|
86
|
+
<li><a href="http://www.prototypejs.org/">Prototype</a>
|
87
87
|
|
88
88
|
</li>
|
89
|
-
<li><a href="http://
|
89
|
+
<li><a href="http://script.aculo.us/">script.aculo.us</a>
|
90
90
|
|
91
91
|
</li>
|
92
|
-
<li><a href="http://
|
92
|
+
<li><a href="http://code.google.com/p/swfobject/">SWFObject</a>
|
93
93
|
|
94
94
|
</li>
|
95
95
|
<li><a
|
96
96
|
href="http://code.google.com/apis/webfonts/docs/webfont_loader.html">WebFont
|
97
97
|
Loader</a>
|
98
98
|
|
99
|
+
</li>
|
100
|
+
<li><a href="http://developer.yahoo.com/yui/">YUI</a>
|
101
|
+
|
102
|
+
</li>
|
103
|
+
</ul>
|
104
|
+
</li>
|
105
|
+
<li>Loaders:
|
106
|
+
|
107
|
+
<ul>
|
108
|
+
<li><a href="http://labjs.com">LABjs</a>
|
109
|
+
|
110
|
+
</li>
|
111
|
+
</ul>
|
99
112
|
</li>
|
100
113
|
</ul>
|
101
114
|
</td>
|
102
115
|
</tr>
|
116
|
+
<tr class='top-aligned-row context-row'>
|
117
|
+
<td class='context-item-name'>VENDORS_ON_CDNJS</td>
|
118
|
+
<td>=</td>
|
119
|
+
<td class='context-item-value'>[ :lab_js ]</td>
|
120
|
+
</tr>
|
121
|
+
<tr class='top-aligned-row context-row'>
|
122
|
+
<td class='context-item-name'>VENDORS</td>
|
123
|
+
<td>=</td>
|
124
|
+
<td class='context-item-value'>VENDORS_ON_GOOGLE_CDN + VENDORS_ON_CDNJS</td>
|
125
|
+
</tr>
|
103
126
|
</table>
|
104
127
|
</div>
|
105
128
|
</div>
|
106
129
|
<div id='methods'>
|
107
130
|
<h2>Public class methods</h2>
|
108
|
-
<div class='method public-class' id='method-
|
109
|
-
<a name='
|
131
|
+
<div class='method public-class' id='method-M000027'>
|
132
|
+
<a name='M000027'></a>
|
110
133
|
<div class='synopsis'>
|
111
134
|
<span class='name'>source_for</span>
|
112
135
|
<span class='arguments'>(vendor, options={})</span>
|
113
136
|
</div>
|
114
137
|
<div class='description'>
|
115
138
|
<p>
|
116
|
-
Accepts an item from VENDORS
|
117
|
-
asset can be found. The URL is either local (relative) or
|
118
|
-
|
119
|
-
|
139
|
+
Accepts an item from `VENDORS`, and returns the URL at which that vendor
|
140
|
+
asset can be found. The URL is either local (relative) or remote, depending
|
141
|
+
on the environment configuration:
|
142
|
+
</p>
|
143
|
+
<ul>
|
144
|
+
<li>If `<a
|
145
|
+
href="../../AssetHat.html#M000012">AssetHat.consider_all_requests_local?</a>`
|
146
|
+
is true:
|
147
|
+
|
148
|
+
<ul>
|
149
|
+
<li>The local file takes precedence.
|
150
|
+
|
151
|
+
</li>
|
152
|
+
<li>If the local file is missing, the remote URL in assets.yml is used as a
|
153
|
+
fallback.
|
154
|
+
|
155
|
+
</li>
|
156
|
+
<li>If there is no remote URL in assets.yml, the Google CDN URL is used as a
|
157
|
+
fallback. (This makes setup easier: If the app doesn’t already have a
|
158
|
+
local copy of the vendor file, then it’s instead loaded remotely.)
|
159
|
+
|
160
|
+
</li>
|
161
|
+
</ul>
|
162
|
+
</li>
|
163
|
+
<li>If `<a
|
164
|
+
href="../../AssetHat.html#M000012">AssetHat.consider_all_requests_local?</a>`
|
165
|
+
is false:
|
166
|
+
|
167
|
+
<ul>
|
168
|
+
<li>The remote URL in assets.yml takes precedence.
|
169
|
+
|
170
|
+
</li>
|
171
|
+
<li>The <a href="http://code.google.com/apis/ajaxlibs/">Google CDN</a> URL is
|
172
|
+
used as a fallback, but only if a version number can be found (either in
|
173
|
+
assets.yml or via the helper’s `:version` option). If no version
|
174
|
+
number is found, the remote URL cannot be built, so the local file (if any)
|
175
|
+
is used as a fallback.
|
176
|
+
|
177
|
+
</li>
|
178
|
+
</ul>
|
179
|
+
</li>
|
180
|
+
</ul>
|
181
|
+
<p>
|
182
|
+
Options:
|
120
183
|
</p>
|
121
184
|
<dl>
|
122
185
|
<dt>ssl</dt><dd>Boolean for whether to include vendor <a href="../JS.html">JS</a> via
|
123
186
|
HTTPS. Defaults to false.
|
124
187
|
|
125
188
|
</dd>
|
126
|
-
<dt>version</dt><dd>The vendor version, e.g., ‘1.
|
189
|
+
<dt>version</dt><dd>The vendor version, e.g., ‘1.5.0’ for jQuery 1.5. By default,
|
127
190
|
each vendor version is taken from <tt>config/assets.yml</tt>; use this
|
128
191
|
option to override the configuration.
|
129
192
|
|
@@ -131,10 +194,10 @@
|
|
131
194
|
</dl>
|
132
195
|
</div>
|
133
196
|
<div class='source'>
|
134
|
-
<a class='source-toggle' href='#' onclick="toggleCode('
|
197
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false">
|
135
198
|
[show source]
|
136
199
|
</a>
|
137
|
-
<pre id='M000024-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js/vendors.rb, line 42</span>
 42: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">source_for</span>(<span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>={})
 43: <span class="ruby-identifier">vendor_config</span> =
 44: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">config</span>[<span class="ruby-value str">'js'</span>][<span class="ruby-value str">'vendors'</span>][<span class="ruby-identifier">vendor</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 45: <span class="ruby-identifier">use_local</span> = <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">consider_all_requests_local</span>
 46: <span class="ruby-identifier">use_ssl</span> = <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ssl</span>]
 47: <span class="ruby-identifier">version</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:version</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">vendor_config</span>[<span class="ruby-value str">'version'</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 48: 
 49: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">use_local</span>
 50: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">vendor_config</span>[<span class="ruby-value str">'remote_url'</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 51: <span class="ruby-identifier">src</span> = (<span class="ruby-identifier">vendor_config</span>[<span class="ruby-value str">'remote_ssl_url'</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">use_ssl</span>
 52: <span class="ruby-keyword kw">end</span>
 53: 
 54: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">src</span>.<span class="ruby-identifier">blank?</span>
 55: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">vendor</span>
 56: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:jquery</span>
 57: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 58: </span> <span class="ruby-node">"#{['jquery', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 59: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"</span>
 60: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:jquery_ui</span>
 61: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 62: </span> <span class="ruby-node">"#{['jquery-ui', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 63: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/jqueryui/#{version}/jquery-ui.min.js"</span>
 64: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:prototype</span>
 65: <span class="ruby-comment cmt"># Prototype currently doesn't provide an official minified version.</span>
 66: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 67: </span> <span class="ruby-node">"#{['prototype', version].compact.join('-')}.js"</span> <span class="ruby-operator">:</span>
 68: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/prototype/#{version}/prototype.js"</span>
 69: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:scriptaculous</span>
 70: <span class="ruby-comment cmt"># script.aculo.us currently doesn't provide an official minified version.</span>
 71: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 72: </span> <span class="ruby-node">"#{['scriptaculous', version].compact.join('-')}.js"</span> <span class="ruby-operator">:</span>
 73: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/scriptaculous/#{version}/scriptaculous.js"</span>
 74: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:mootools</span>
 75: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 76: </span> <span class="ruby-node">"#{['mootools', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 77: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/mootools/#{version}/mootools-yui-compressed.js"</span>
 78: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:dojo</span>
 79: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 80: </span> <span class="ruby-node">"#{['dojo', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 81: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/dojo/#{version}/dojo/dojo.xd.js"</span>
 82: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:swfobject</span>
 83: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 84: </span> <span class="ruby-node">"#{['swfobject', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 85: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/swfobject/#{version}/swfobject.js"</span>
 86: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:yui</span>
 87: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 88: </span> <span class="ruby-node">"#{['yui', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 89: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/yui/#{version}/build/yuiloader/yuiloader-min.js"</span>
 90: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:ext_core</span>
 91: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 92: </span> <span class="ruby-node">"#{['ext_core', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 93: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/ext-core/#{version}/ext-core.js"</span>
 94: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:webfont</span>
 95: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">?
 96: </span> <span class="ruby-node">"#{['webfont', version].compact.join('-')}.min.js"</span> <span class="ruby-operator">:</span>
 97: <span class="ruby-node">"http#{'s' if use_ssl}://ajax.googleapis.com/ajax/libs/webfont/#{version}/webfont.js"</span>
 98: <span class="ruby-keyword kw">else</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># TODO: Write to log</span>
 99: <span class="ruby-keyword kw">end</span>
100: <span class="ruby-keyword kw">end</span>
101: 
102: <span class="ruby-identifier">src</span>
103: <span class="ruby-keyword kw">end</span></pre>
|
200
|
+
<pre id='M000027-source'> <span class="ruby-comment cmt"># File lib/asset_hat/js/vendors.rb, line 67</span>
 67: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">source_for</span>(<span class="ruby-identifier">vendor</span>, <span class="ruby-identifier">options</span>={})
 68: <span class="ruby-identifier">vendor_config</span> =
 69: <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">config</span>[<span class="ruby-value str">'js'</span>][<span class="ruby-value str">'vendors'</span>][<span class="ruby-identifier">vendor</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 70: <span class="ruby-identifier">use_local</span> = <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">consider_all_requests_local?</span>
 71: <span class="ruby-identifier">use_ssl</span> = <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-identifier">:ssl</span>]
 72: <span class="ruby-identifier">version</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:version</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">vendor_config</span>[<span class="ruby-value str">'version'</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 73: 
 74: <span class="ruby-comment cmt"># Prepare local path and default remote URL</span>
 75: <span class="ruby-identifier">srcs</span> = <span class="ruby-constant">Vendors</span>.<span class="ruby-identifier">vendor_uris</span>(<span class="ruby-identifier">vendor</span>,
 76: <span class="ruby-identifier">:use_ssl</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">use_ssl</span>, <span class="ruby-identifier">:version</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">version</span>)
 77: <span class="ruby-identifier">local_src</span>, <span class="ruby-identifier">remote_src</span> = <span class="ruby-identifier">srcs</span>[<span class="ruby-identifier">:local</span>], <span class="ruby-identifier">srcs</span>[<span class="ruby-identifier">:remote</span>]
 78: 
 79: <span class="ruby-comment cmt"># Using the local URL requires that the vendor file exists locally. If</span>
 80: <span class="ruby-comment cmt"># the vendor file doesn't exist, use the remote URL as fallback.</span>
 81: <span class="ruby-identifier">use_local</span> <span class="ruby-operator">&&=</span> <span class="ruby-constant">AssetHat</span>.<span class="ruby-identifier">asset_exists?</span>(<span class="ruby-identifier">local_src</span>, <span class="ruby-identifier">:js</span>)
 82: 
 83: <span class="ruby-comment cmt"># If no version given, can't determine the remote URL; use the local</span>
 84: <span class="ruby-comment cmt"># URL as fallback.</span>
 85: <span class="ruby-identifier">use_local</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">version</span>.<span class="ruby-identifier">blank?</span>
 86: 
 87: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">use_local</span>
 88: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">local_src</span>
 89: <span class="ruby-keyword kw">else</span>
 90: <span class="ruby-comment cmt"># To ease setup, if no local copy of the vendor code is found,</span>
 91: <span class="ruby-comment cmt"># use a remote URL as a fallback.</span>
 92: 
 93: <span class="ruby-comment cmt"># Give precedence to configured remote URLs</span>
 94: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">vendor_config</span>.<span class="ruby-identifier">try</span>(<span class="ruby-identifier">:[]</span>, <span class="ruby-value str">'remote_ssl_url'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">use_ssl</span>
 95: <span class="ruby-identifier">src</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">vendor_config</span>.<span class="ruby-identifier">try</span>(<span class="ruby-identifier">:[]</span>, <span class="ruby-value str">'remote_url'</span>)
 96: 
 97: <span class="ruby-comment cmt"># Use default remote URL as fallback</span>
 98: <span class="ruby-identifier">src</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">remote_src</span>
 99: 
100: <span class="ruby-comment cmt"># Use local URL as final resort, even though the file doesn't</span>
101: <span class="ruby-comment cmt"># exist, in hopes that the app maintainer finds the 404 (or the</span>
102: <span class="ruby-comment cmt"># warning below) in the logs. This needs to be fixed in the app,</span>
103: <span class="ruby-comment cmt"># rather than relying on a CDN to dynamically provide the latest</span>
104: <span class="ruby-comment cmt"># stable vendor version.</span>
105: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">src</span>.<span class="ruby-identifier">blank?</span>
106: <span class="ruby-identifier">src</span> = <span class="ruby-identifier">local_src</span>
107: <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">warn</span> <span class="ruby-node">"\n\nAssetHat WARNING (#{Time.now}):\n"</span> <span class="ruby-operator">+</span> <span class="ruby-node">%{
108: Tried to reference the vendor JS `:#{vendor}`, but
109: #{AssetHat.assets_dir(:js)}/#{local_src} couldn't be found, and
110: couldn't use a remote fallback because no vendor version was
111: given in #{AssetHat::RELATIVE_CONFIG_FILEPATH}.
112: }</span>.<span class="ruby-identifier">squish!</span>
113: <span class="ruby-comment cmt"># TODO: Create `AssetHat::Logger.warn`, etc. methods</span>
114: <span class="ruby-keyword kw">end</span>
115: <span class="ruby-keyword kw">end</span>
116: 
117: <span class="ruby-identifier">src</span>
118: <span class="ruby-keyword kw">end</span></pre>
|
138
201
|
</div>
|
139
202
|
</div>
|
140
203
|
</div>
|