gce-host 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.yardopts +6 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +22 -0
  7. data/README.md +210 -0
  8. data/Rakefile +30 -0
  9. data/bin/gce-host +4 -0
  10. data/docs/GCE.html +132 -0
  11. data/docs/GCE/Host.html +901 -0
  12. data/docs/GCE/Host/CLI.html +610 -0
  13. data/docs/GCE/Host/Config.html +1195 -0
  14. data/docs/GCE/Host/GCEClient.html +215 -0
  15. data/docs/GCE/Host/GCEClient/Error.html +127 -0
  16. data/docs/GCE/Host/GCEClient/NotFound.html +131 -0
  17. data/docs/GCE/Host/HashUtil.html +178 -0
  18. data/docs/GCE/Host/HostData.html +1658 -0
  19. data/docs/GCE/Host/RoleData.html +932 -0
  20. data/docs/GCE/Host/StringUtil.html +359 -0
  21. data/docs/_index.html +231 -0
  22. data/docs/class_list.html +58 -0
  23. data/docs/css/common.css +1 -0
  24. data/docs/css/full_list.css +57 -0
  25. data/docs/css/style.css +339 -0
  26. data/docs/file.LICENSE.html +95 -0
  27. data/docs/file.README.html +312 -0
  28. data/docs/file_list.html +63 -0
  29. data/docs/frames.html +26 -0
  30. data/docs/index.html +312 -0
  31. data/docs/js/app.js +219 -0
  32. data/docs/js/full_list.js +181 -0
  33. data/docs/js/jquery.js +4 -0
  34. data/docs/method_list.html +477 -0
  35. data/docs/top-level-namespace.html +112 -0
  36. data/example/example.conf +8 -0
  37. data/example/example.rb +6 -0
  38. data/gce-host.gemspec +26 -0
  39. data/lib/gce-host.rb +7 -0
  40. data/lib/gce/host.rb +120 -0
  41. data/lib/gce/host/cli.rb +151 -0
  42. data/lib/gce/host/config.rb +109 -0
  43. data/lib/gce/host/gce_client.rb +69 -0
  44. data/lib/gce/host/hash_util.rb +11 -0
  45. data/lib/gce/host/host_data.rb +227 -0
  46. data/lib/gce/host/role_data.rb +64 -0
  47. data/lib/gce/host/string_util.rb +31 -0
  48. data/lib/gce/host/version.rb +5 -0
  49. data/spec/gce_client_spec.rb +29 -0
  50. data/spec/host_spec.rb +199 -0
  51. data/spec/spec_helper.rb +22 -0
  52. data/terraform.tf +52 -0
  53. metadata +226 -0
data/docs/frames.html ADDED
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+ <title>Documentation by YARD 0.8.7.6</title>
8
+ </head>
9
+ <script type="text/javascript" charset="utf-8">
10
+ window.onload = function() {
11
+ var match = unescape(window.location.hash).match(/^#!(.+)/);
12
+ var name = match ? match[1] : 'index.html';
13
+ name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
14
+ document.writeln('<frameset cols="20%,*">' +
15
+ '<frame name="list" src="class_list.html" />' +
16
+ '<frame name="main" src="' + escape(name) + '" />' +
17
+ '</frameset>');
18
+ }
19
+ </script>
20
+ <noscript>
21
+ <frameset cols="20%,*">
22
+ <frame name="list" src="class_list.html" />
23
+ <frame name="main" src="index.html" />
24
+ </frameset>
25
+ </noscript>
26
+ </html>
data/docs/index.html ADDED
@@ -0,0 +1,312 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.8.7.6
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!file.README.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+ <span class="title">File: README</span>
36
+
37
+
38
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
39
+ </div>
40
+
41
+ <div id="search">
42
+
43
+ <a class="full_list_link" id="class_list_link"
44
+ href="class_list.html">
45
+ Class List
46
+ </a>
47
+
48
+ <a class="full_list_link" id="method_list_link"
49
+ href="method_list.html">
50
+ Method List
51
+ </a>
52
+
53
+ <a class="full_list_link" id="file_list_link"
54
+ href="file_list.html">
55
+ File List
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <iframe id="search_frame"></iframe>
63
+
64
+ <div id="content"><div id='filecontents'>
65
+ <h1 id="label-gce-host">gce-host</h1>
66
+
67
+ <p>Search hosts on GCP GCE</p>
68
+
69
+ <h2 id="label-Installation">Installation</h2>
70
+
71
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_gce'>gce</span><span class='op'>-</span><span class='id identifier rubyid_host'>host</span>
72
+ </code></pre>
73
+
74
+ <h2 id="label-How+it+works">How it works</h2>
75
+
76
+ <p>This gems uses <a
77
+ href="https://cloud.google.com/compute/docs/storing-retrieving-metadata">metadata
78
+ of GCE resources</a>. You can configure, but basically use
79
+ <code>roles</code> key for roles.</p>
80
+
81
+ <p>You can manage roles of a host, and search hosts having a specified role
82
+ using thease metadata with this gem.</p>
83
+
84
+ <h2 id="label-Configuration">Configuration</h2>
85
+
86
+ <p>You can write a configuration file located at
87
+ <code>/etc/sysconfig/gce-host</code> (You can configure this path by
88
+ <code>GCE_HOST_CONFIG_FILE</code> environment variable), or as environment
89
+ variables:</p>
90
+
91
+ <p>GOOGLE API parameters:</p>
92
+ <ul><li>
93
+ <p><strong>AUTH_METHOD</strong>: Authentication method. Currently,
94
+ <code>compute_engine</code>, <code>json_key</code> and
95
+ <code>application_default</code> is available. The default is
96
+ <code>applilcation_default</code>.</p>
97
+ </li><li>
98
+ <p><strong>GOOGLE_CREDENTIAL_FILE</strong>: Path of credential file. Specify
99
+ your service account json file for <code>json_key</code> authentication
100
+ method.</p>
101
+ </li></ul>
102
+
103
+ <p>gce-host parameters:</p>
104
+ <ul><li>
105
+ <p><strong>ROLES_KEY (optional)</strong>: GCE metadata keys used to express
106
+ roles. The default is <code>roles</code></p>
107
+ </li><li>
108
+ <p>You can assign multiple roles seperated by
109
+ <code>ARRAY_VALUE_DELIMITER</code> (default: <code>,</code>)</p>
110
+ </li><li>
111
+ <p>Also, you can express levels of roles delimited by
112
+ <code>ROLE_VALUE_DELIMITER</code> (default <code>:</code>)</p>
113
+ </li><li>
114
+ <p>Example: admin:ami, then <code>GCE::Host.new(role:
115
+ &#39;admin:ami&#39;)</code> and also <code>GCE::Host.new(role1:
116
+ &#39;admin&#39;)</code> returns this host</p>
117
+ </li><li>
118
+ <p><strong>ROLE_VALUE_DELIMITER (optional)</strong>: A delimiter to express
119
+ levels of roles. Default is <code>:</code></p>
120
+ </li><li>
121
+ <p><strong>OPTIONAL_STRING_KEYS (optional)</strong>: You may add optional
122
+ non-array metadata keys. You can specify multiple keys like
123
+ <code>service,status</code>.</p>
124
+ </li><li>
125
+ <p><strong>OPTIONAL_ARRAY_KEYS (optional)</strong>: You may add optional array
126
+ metadata keys. Array allows multiple values delimited by
127
+ <code>ARRAY_VALUE_DELIMITER</code> (default: <code>,</code>)</p>
128
+ </li><li>
129
+ <p><strong>ARRAY_VALUE_DELIMITER (optional)</strong>: A delimiter to express
130
+ array. Default is <code>,</code></p>
131
+ </li><li>
132
+ <p><strong>LOG_LEVEL (optional)</strong>: Log level such as <code>info</code>,
133
+ <code>debug</code>, <code>error</code>. The default is <code>info</code>.</p>
134
+ </li></ul>
135
+
136
+ <p>See <a href="./example/example.conf">example.conf</a></p>
137
+
138
+ <h2 id="label-Metadata+Example">Metadata Example</h2>
139
+ <ul><li>
140
+ <p><strong>roles</strong>: app:web,app:db</p>
141
+ </li><li>
142
+ <p><strong>service</strong>: awesome</p>
143
+ </li><li>
144
+ <p><strong>status</strong>: setup</p>
145
+ </li></ul>
146
+
147
+ <h2 id="label-CLI+Usage">CLI Usage</h2>
148
+
149
+ <h3 id="label-CLI+Example">CLI Example</h3>
150
+
151
+ <pre class="code ruby"><code class="ruby">$ gce-host -j
152
+ {&quot;hostname&quot;:&quot;gce-host-db&quot;,&quot;roles&quot;:[&quot;foo&quot;,&quot;db:test&quot;],&quot;zone&quot;:&quot;asia-northeast1-a&quot;,&quot;service&quot;:&quot;gce-host&quot;,&quot;status&quot;:&quot;active&quot;,&quot;tags&quot;:[&quot;master&quot;],&quot;instance_id&quot;:&quot;4263858691219514807&quot;,&quot;private_ip_address&quot;:&quot;10.240.0.6&quot;,&quot;public_ip_address&quot;:&quot;104.198.89.55&quot;,&quot;creation_timestamp&quot;:&quot;2016-11-22T06:51:04.650-08:00&quot;,&quot;state&quot;:&quot;RUNNING&quot;}
153
+ {&quot;hostname&quot;:&quot;gce-host-web&quot;,&quot;roles&quot;:[&quot;foo&quot;,&quot;web:test&quot;],&quot;zone&quot;:&quot;asia-northeast1-a&quot;,&quot;service&quot;:&quot;gce-host&quot;,&quot;status&quot;:&quot;reserve&quot;,&quot;tags&quot;:[&quot;standby&quot;],&quot;instance_id&quot;:&quot;8807276062743061943&quot;,&quot;private_ip_address&quot;:&quot;10.240.0.5&quot;,&quot;public_ip_address&quot;:&quot;104.198.87.6&quot;,&quot;creation_timestamp&quot;:&quot;2016-11-22T06:51:04.653-08:00&quot;,&quot;state&quot;:&quot;RUNNING&quot;}</code></pre>
154
+
155
+ <pre class="code ruby"><code class="ruby">$ gce-host
156
+ gce-host-db
157
+ gce-host-web</code></pre>
158
+
159
+ <pre class="code ruby"><code class="ruby">$ gce-host --role1 db
160
+ gce-host-db</code></pre>
161
+
162
+ <pre class="code ruby"><code class="ruby">$ gce-host --role web:test
163
+ gce-host-web</code></pre>
164
+
165
+ <pre class="code ruby"><code class="ruby">$ gce-host --pretty-json
166
+ [
167
+ {
168
+ &quot;hostname&quot;: &quot;gce-host-db&quot;,
169
+ &quot;roles&quot;: [
170
+ &quot;foo&quot;,
171
+ &quot;db:test&quot;
172
+ ],
173
+ &quot;zone&quot;: &quot;asia-northeast1-a&quot;,
174
+ &quot;service&quot;: &quot;gce-host&quot;,
175
+ &quot;status&quot;: &quot;active&quot;,
176
+ &quot;tags&quot;: [
177
+ &quot;master&quot;
178
+ ],
179
+ &quot;instance_id&quot;: &quot;4263858691219514807&quot;,
180
+ &quot;private_ip_address&quot;: &quot;10.240.0.6&quot;,
181
+ &quot;public_ip_address&quot;: &quot;104.198.89.55&quot;,
182
+ &quot;creation_timestamp&quot;: &quot;2016-11-22T06:51:04.650-08:00&quot;,
183
+ &quot;state&quot;: &quot;RUNNING&quot;
184
+ },
185
+ {
186
+ &quot;hostname&quot;: &quot;gce-host-web&quot;,
187
+ &quot;roles&quot;: [
188
+ &quot;foo&quot;,
189
+ &quot;web:test&quot;
190
+ ],
191
+ &quot;zone&quot;: &quot;asia-northeast1-a&quot;,
192
+ &quot;service&quot;: &quot;gce-host&quot;,
193
+ &quot;status&quot;: &quot;reserve&quot;,
194
+ &quot;tags&quot;: [
195
+ &quot;standby&quot;
196
+ ],
197
+ &quot;instance_id&quot;: &quot;8807276062743061943&quot;,
198
+ &quot;private_ip_address&quot;: &quot;10.240.0.5&quot;,
199
+ &quot;public_ip_address&quot;: &quot;104.198.87.6&quot;,
200
+ &quot;creation_timestamp&quot;: &quot;2016-11-22T06:51:04.653-08:00&quot;,
201
+ &quot;state&quot;: &quot;RUNNING&quot;
202
+ }
203
+ ]</code></pre>
204
+
205
+ <h3 id="label-CLI+Help">CLI Help</h3>
206
+
207
+ <pre class="code ruby"><code class="ruby">$ bin/gce-host --help
208
+ Usage: gce-host [options]
209
+ --hostname one,two,three name or private_dns_name
210
+ -r, --role one,two,three role
211
+ --r1, --role1 one,two,three role1, the 1st part of role delimited by :
212
+ --r2, --role2 one,two,three role2, the 2st part of role delimited by :
213
+ --r3, --role3 one,two,three role3, the 3st part of role delimited by :
214
+ --state one,two,three filter with instance state (default: running)
215
+ -a, --all list all hosts (remove default filter)
216
+ --private-ip, --ip show private ip address instead of hostname
217
+ --public-ip show public ip address instead of hostname
218
+ -i, --info show host info
219
+ -j, --jsonl show host info in line delimited json
220
+ --json show host info in json
221
+ --pretty-json show host info in pretty json
222
+ --debug debug mode
223
+ -h, --help show help</code></pre>
224
+
225
+ <h2 id="label-Library+Usage">Library Usage</h2>
226
+
227
+ <h3 id="label-Library+Example">Library Example</h3>
228
+
229
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>gce-host</span><span class='tstring_end'>&#39;</span></span>
230
+
231
+ <span class='id identifier rubyid_hosts'>hosts</span> <span class='op'>=</span> <span class='const'>GCE</span><span class='op'>::</span><span class='const'>Host</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>role:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>db:test</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
232
+ <span class='id identifier rubyid_hosts'>hosts</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_host'>host</span><span class='op'>|</span>
233
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_host'>host</span>
234
+ <span class='kw'>end</span>
235
+ </code></pre>
236
+
237
+ <h3 id="label-Library+Reference">Library Reference</h3>
238
+
239
+ <p>See <a
240
+ href="http://sonots.github.io/gce-host/frames.html">sonots.github.io/gce-host/frames.html</a>.</p>
241
+
242
+ <h2 id="label-ChangeLog">ChangeLog</h2>
243
+
244
+ <p>See <a href="CHANGELOG.md">CHANGELOG.md</a> for details.</p>
245
+
246
+ <h2 id="label-For+Developers">For Developers</h2>
247
+
248
+ <h3 id="label-ToDo">ToDo</h3>
249
+ <ul><li>
250
+ <p>Use mock/stub to run test (currently, directly accessing to GCE)</p>
251
+ </li><li>
252
+ <p>Should cache a result of list_instances in like 30 seconds?</p>
253
+ </li></ul>
254
+
255
+ <h3 id="label-How+to+Run+test">How to Run test</h3>
256
+
257
+ <p>NOTE: Currently, mock is not supported yet. So, you have to create your own
258
+ gcloud account, and instances.</p>
259
+
260
+ <p>Configure .env file as</p>
261
+
262
+ <pre class="code ruby"><code class="ruby"><span class='const'>AUTH_METHOD</span><span class='op'>=</span><span class='id identifier rubyid_json_key'>json_key</span>
263
+ <span class='const'>GOOGLE_CREDENTIAL_FILE</span><span class='op'>=</span><span class='id identifier rubyid_service_acount'>service_acount</span><span class='period'>.</span><span class='id identifier rubyid_json'>json</span>
264
+ <span class='const'>GOOGLE_PROJECT</span><span class='op'>=</span><span class='const'>XXXXXXXXXXXXX</span>
265
+ <span class='const'>OPTIONAL_STRING_KEYS</span><span class='op'>=</span><span class='id identifier rubyid_service'>service</span><span class='comma'>,</span><span class='id identifier rubyid_status'>status</span>
266
+ <span class='const'>OPTIONAL_ARRAY_KEYS</span><span class='op'>=</span><span class='id identifier rubyid_tags'>tags</span>
267
+ </code></pre>
268
+
269
+ <p>Install terraform and run to create instances for tests</p>
270
+
271
+ <pre class="code ruby"><code class="ruby">$ brew install terraform
272
+ $ env $(cat .env) terraform plan
273
+ $ env ($cat .env) terraform apply</code></pre>
274
+
275
+ <p>Run test</p>
276
+
277
+ <pre class="code ruby"><code class="ruby">$ bundle exec rspec</code></pre>
278
+
279
+ <p>After working, destory instances by commenting out
280
+ <code>terraform.tf</code> and apply.</p>
281
+
282
+ <h3 id="label-How+to+Release+Gem">How to Release Gem</h3>
283
+ <ol><li>
284
+ <p>Update gem.version in the gemspec</p>
285
+ </li><li>
286
+ <p>Update CHANGELOG.md</p>
287
+ </li><li>
288
+ <p>git commit &amp;&amp; git push</p>
289
+ </li><li>
290
+ <p>Run <code>bundle exec rake release</code></p>
291
+ </li></ol>
292
+
293
+ <h3 id="label-How+to+Update+doc">How to Update doc</h3>
294
+ <ol><li>
295
+ <p>Run <code>bundle exec yard</code></p>
296
+ </li><li>
297
+ <p>git commit &amp;&amp; git push</p>
298
+ </li></ol>
299
+
300
+ <h3 id="label-Licenses">Licenses</h3>
301
+
302
+ <p>See <a href="LICENSE">LICENSE</a></p>
303
+ </div></div>
304
+
305
+ <div id="footer">
306
+ Generated on Wed Nov 23 20:08:31 2016 by
307
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
308
+ 0.8.7.6 (ruby-2.3.2).
309
+ </div>
310
+
311
+ </body>
312
+ </html>
data/docs/js/app.js ADDED
@@ -0,0 +1,219 @@
1
+ function createSourceLinks() {
2
+ $('.method_details_list .source_code').
3
+ before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
+ $('.toggleSource').toggle(function() {
5
+ $(this).parent().nextAll('.source_code').slideDown(100);
6
+ $(this).text("Hide source");
7
+ },
8
+ function() {
9
+ $(this).parent().nextAll('.source_code').slideUp(100);
10
+ $(this).text("View source");
11
+ });
12
+ }
13
+
14
+ function createDefineLinks() {
15
+ var tHeight = 0;
16
+ $('.defines').after(" <a href='#' class='toggleDefines'>more...</a>");
17
+ $('.toggleDefines').toggle(function() {
18
+ tHeight = $(this).parent().prev().height();
19
+ $(this).prev().show();
20
+ $(this).parent().prev().height($(this).parent().height());
21
+ $(this).text("(less)");
22
+ },
23
+ function() {
24
+ $(this).prev().hide();
25
+ $(this).parent().prev().height(tHeight);
26
+ $(this).text("more...");
27
+ });
28
+ }
29
+
30
+ function createFullTreeLinks() {
31
+ var tHeight = 0;
32
+ $('.inheritanceTree').toggle(function() {
33
+ tHeight = $(this).parent().prev().height();
34
+ $(this).parent().toggleClass('showAll');
35
+ $(this).text("(hide)");
36
+ $(this).parent().prev().height($(this).parent().height());
37
+ },
38
+ function() {
39
+ $(this).parent().toggleClass('showAll');
40
+ $(this).parent().prev().height(tHeight);
41
+ $(this).text("show all");
42
+ });
43
+ }
44
+
45
+ function fixBoxInfoHeights() {
46
+ $('dl.box dd.r1, dl.box dd.r2').each(function() {
47
+ $(this).prev().height($(this).height());
48
+ });
49
+ }
50
+
51
+ function searchFrameLinks() {
52
+ $('.full_list_link').click(function() {
53
+ toggleSearchFrame(this, $(this).attr('href'));
54
+ return false;
55
+ });
56
+ }
57
+
58
+ function toggleSearchFrame(id, link) {
59
+ var frame = $('#search_frame');
60
+ $('#search a').removeClass('active').addClass('inactive');
61
+ if (frame.attr('src') == link && frame.css('display') != "none") {
62
+ frame.slideUp(100);
63
+ $('#search a').removeClass('active inactive');
64
+ }
65
+ else {
66
+ $(id).addClass('active').removeClass('inactive');
67
+ frame.attr('src', link).slideDown(100);
68
+ }
69
+ }
70
+
71
+ function linkSummaries() {
72
+ $('.summary_signature').click(function() {
73
+ document.location = $(this).find('a').attr('href');
74
+ });
75
+ }
76
+
77
+ function framesInit() {
78
+ if (hasFrames) {
79
+ document.body.className = 'frames';
80
+ $('#menu .noframes a').attr('href', document.location);
81
+ try {
82
+ window.top.document.title = $('html head title').text();
83
+ } catch(error) {
84
+ // some browsers will not allow this when serving from file://
85
+ // but we don't want to stop the world.
86
+ }
87
+ }
88
+ else {
89
+ $('#menu .noframes a').text('frames').attr('href', framesUrl);
90
+ }
91
+ }
92
+
93
+ function keyboardShortcuts() {
94
+ if (window.top.frames.main) return;
95
+ $(document).keypress(function(evt) {
96
+ if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
97
+ if (typeof evt.target !== "undefined" &&
98
+ (evt.target.nodeName == "INPUT" ||
99
+ evt.target.nodeName == "TEXTAREA")) return;
100
+ switch (evt.charCode) {
101
+ case 67: case 99: $('#class_list_link').click(); break; // 'c'
102
+ case 77: case 109: $('#method_list_link').click(); break; // 'm'
103
+ case 70: case 102: $('#file_list_link').click(); break; // 'f'
104
+ default: break;
105
+ }
106
+ });
107
+ }
108
+
109
+ function summaryToggle() {
110
+ $('.summary_toggle').click(function() {
111
+ if (localStorage) {
112
+ localStorage.summaryCollapsed = $(this).text();
113
+ }
114
+ $('.summary_toggle').each(function() {
115
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
116
+ var next = $(this).parent().parent().nextAll('ul.summary').first();
117
+ if (next.hasClass('compact')) {
118
+ next.toggle();
119
+ next.nextAll('ul.summary').first().toggle();
120
+ }
121
+ else if (next.hasClass('summary')) {
122
+ var list = $('<ul class="summary compact" />');
123
+ list.html(next.html());
124
+ list.find('.summary_desc, .note').remove();
125
+ list.find('a').each(function() {
126
+ $(this).html($(this).find('strong').html());
127
+ $(this).parent().html($(this)[0].outerHTML);
128
+ });
129
+ next.before(list);
130
+ next.toggle();
131
+ }
132
+ });
133
+ return false;
134
+ });
135
+ if (localStorage) {
136
+ if (localStorage.summaryCollapsed == "collapse") {
137
+ $('.summary_toggle').first().click();
138
+ }
139
+ else localStorage.summaryCollapsed = "expand";
140
+ }
141
+ }
142
+
143
+ function fixOutsideWorldLinks() {
144
+ $('a').each(function() {
145
+ if (window.location.host != this.host) this.target = '_parent';
146
+ });
147
+ }
148
+
149
+ function generateTOC() {
150
+ if ($('#filecontents').length === 0) return;
151
+ var _toc = $('<ol class="top"></ol>');
152
+ var show = false;
153
+ var toc = _toc;
154
+ var counter = 0;
155
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
156
+ var i;
157
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
158
+ for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
159
+ var lastTag = parseInt(tags[0][1], 10);
160
+ $(tags.join(', ')).each(function() {
161
+ if ($(this).parents('.method_details .docstring').length != 0) return;
162
+ if (this.id == "filecontents") return;
163
+ show = true;
164
+ var thisTag = parseInt(this.tagName[1], 10);
165
+ if (this.id.length === 0) {
166
+ var proposedId = $(this).attr('toc-id');
167
+ if (typeof(proposedId) != "undefined") this.id = proposedId;
168
+ else {
169
+ var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
170
+ if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
171
+ this.id = proposedId;
172
+ }
173
+ }
174
+ if (thisTag > lastTag) {
175
+ for (i = 0; i < thisTag - lastTag; i++) {
176
+ var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
177
+ }
178
+ }
179
+ if (thisTag < lastTag) {
180
+ for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
181
+ }
182
+ var title = $(this).attr('toc-title');
183
+ if (typeof(title) == "undefined") title = $(this).text();
184
+ toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
185
+ lastTag = thisTag;
186
+ });
187
+ if (!show) return;
188
+ html = '<div id="toc"><p class="title"><a class="hide_toc" href="#"><strong>Table of Contents</strong></a> <small>(<a href="#" class="float_toc">left</a>)</small></p></div>';
189
+ $('#content').prepend(html);
190
+ $('#toc').append(_toc);
191
+ $('#toc .hide_toc').toggle(function() {
192
+ $('#toc .top').slideUp('fast');
193
+ $('#toc').toggleClass('hidden');
194
+ $('#toc .title small').toggle();
195
+ }, function() {
196
+ $('#toc .top').slideDown('fast');
197
+ $('#toc').toggleClass('hidden');
198
+ $('#toc .title small').toggle();
199
+ });
200
+ $('#toc .float_toc').toggle(function() {
201
+ $(this).text('float');
202
+ $('#toc').toggleClass('nofloat');
203
+ }, function() {
204
+ $(this).text('left');
205
+ $('#toc').toggleClass('nofloat');
206
+ });
207
+ }
208
+
209
+ $(framesInit);
210
+ $(createSourceLinks);
211
+ $(createDefineLinks);
212
+ $(createFullTreeLinks);
213
+ $(fixBoxInfoHeights);
214
+ $(searchFrameLinks);
215
+ $(linkSummaries);
216
+ $(keyboardShortcuts);
217
+ $(summaryToggle);
218
+ $(fixOutsideWorldLinks);
219
+ $(generateTOC);