ec2-host 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +8 -0
- data/README.md +42 -8
- data/docs/EC2.html +132 -0
- data/docs/EC2/Host.html +889 -0
- data/docs/EC2/Host/CLI.html +616 -0
- data/docs/EC2/Host/Config.html +1193 -0
- data/docs/EC2/Host/EC2Client.html +273 -0
- data/docs/EC2/Host/HashUtil.html +178 -0
- data/docs/EC2/Host/HostData.html +1772 -0
- data/docs/EC2/Host/RoleData.html +932 -0
- data/docs/EC2/Host/StringUtil.html +359 -0
- data/docs/_index.html +201 -0
- data/docs/class_list.html +58 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +57 -0
- data/docs/css/style.css +339 -0
- data/docs/file.LICENSE.html +95 -0
- data/docs/file.README.html +323 -0
- data/docs/file_list.html +63 -0
- data/docs/frames.html +26 -0
- data/docs/index.html +323 -0
- data/docs/js/app.js +219 -0
- data/docs/js/full_list.js +181 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +489 -0
- data/docs/top-level-namespace.html +112 -0
- data/ec2-host.gemspec +1 -2
- data/{sample.conf → example/example.conf} +1 -1
- data/lib/ec2-host.rb +1 -1
- data/lib/ec2/host.rb +12 -4
- data/lib/ec2/host/config.rb +13 -15
- data/lib/ec2/host/ec2_client.rb +60 -0
- data/lib/ec2/host/host_data.rb +156 -103
- data/lib/ec2/host/role_data.rb +11 -7
- data/spec/host_spec.rb +67 -42
- data/spec/spec_helper.rb +6 -6
- data/terraform.tf +39 -0
- metadata +31 -22
- data/doc.sh +0 -5
- data/lib/ec2/host/client_util.rb +0 -44
- data/spec/README.md +0 -35
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,323 @@
|
|
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
|
+
— 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> »
|
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-ec2-host">ec2-host</h1>
|
66
|
+
|
67
|
+
<p>Search hosts on AWS EC2</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_ec2'>ec2</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="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html">tagging
|
78
|
+
of EC2 resources</a>. You can configure, but basically use
|
79
|
+
<code>Name</code> tag for hostname (this is default of EC2) and
|
80
|
+
<code>Roles</code> tag for roles.</p>
|
81
|
+
|
82
|
+
<p>You can manage roles of a host, and search hosts having a specified role
|
83
|
+
using thease tags with this gem.</p>
|
84
|
+
|
85
|
+
<h2 id="label-Configuration">Configuration</h2>
|
86
|
+
|
87
|
+
<p>You can write a configuration file located at
|
88
|
+
<code>/etc/sysconfig/ec2-host</code> (You can configure this path by
|
89
|
+
<code>EC2_HOST_CONFIG_FILE</code> environment variable), or as environment
|
90
|
+
variables:</p>
|
91
|
+
|
92
|
+
<p>AWS SDK (CLI) parameters:</p>
|
93
|
+
<ul><li>
|
94
|
+
<p><strong>AWS_ACCESS_KEY_ID</strong>: AWS SDK (CLI) crendentials. Default
|
95
|
+
loads a credentials file</p>
|
96
|
+
</li><li>
|
97
|
+
<p><strong>AWS_SECRET_ACCESS_KEY</strong>: AWS SDK (CLI) credentials. Default
|
98
|
+
load a credentials file</p>
|
99
|
+
</li><li>
|
100
|
+
<p><strong>AWS_DEFAULT_REGION</strong> (<strong>AWS_REGION</strong>); AWS SDK
|
101
|
+
(CLI) region such as <code>ap-northeast-1</code>, <code>us-east-1</code>.</p>
|
102
|
+
</li><li>
|
103
|
+
<p><strong>AWS_DEFAULT_PROFILE</strong> (<strong>AWS_PROFILE</strong>): The
|
104
|
+
profile key of the AWS SDK (CLI) credentails file. Default is
|
105
|
+
<code>default</code></p>
|
106
|
+
</li><li>
|
107
|
+
<p><strong>AWS_CREDENTIAL_FILE</strong>
|
108
|
+
(<strong>AWS_CREDENTIALS_FILE</strong>): Path of the AWS SDK (CLI)
|
109
|
+
credentails file. Default is <code>$HOME/.aws/credentials</code>. See <a
|
110
|
+
href="http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files">Configuring
|
111
|
+
the AWS Command Line Interface</a> for details.</p>
|
112
|
+
</li></ul>
|
113
|
+
|
114
|
+
<p>ec2-host parameters:</p>
|
115
|
+
<ul><li>
|
116
|
+
<p><strong>HOSTNAME_TAG (optional)</strong>: EC2 tag key used to express a
|
117
|
+
hostname. The default is <code>Name</code>.</p>
|
118
|
+
</li><li>
|
119
|
+
<p><strong>ROLES_TAG (optional)</strong>: EC2 tag keys used to express roles.
|
120
|
+
The default is <code>Roles</code></p>
|
121
|
+
</li><li>
|
122
|
+
<p>You can assign multiple roles seperated by <code>ARRAY_TAG_DELIMITER</code>
|
123
|
+
(default: <code>,</code>)</p>
|
124
|
+
</li><li>
|
125
|
+
<p>Also, you can express levels of roles delimited by
|
126
|
+
<code>ROLE_TAG_DELIMITER</code> (default <code>:</code>)</p>
|
127
|
+
</li><li>
|
128
|
+
<p>Example: admin:ami, then <code>EC2::Host.new(role:
|
129
|
+
'admin:ami')</code> and also <code>EC2::Host.new(role1:
|
130
|
+
'admin')</code> returns this host</p>
|
131
|
+
</li><li>
|
132
|
+
<p><strong>ROLE_TAG_DELIMITER (optional)</strong>: A delimiter to express
|
133
|
+
levels of roles. Default is <code>:</code></p>
|
134
|
+
</li><li>
|
135
|
+
<p><strong>OPTIONAL_STRING_TAGS (optional)</strong>: You may add optional
|
136
|
+
non-array tags. You can specify multiple tags like
|
137
|
+
<code>Service,Status</code>.</p>
|
138
|
+
</li><li>
|
139
|
+
<p><strong>OPTIONAL_ARRAY_TAGS (optional)</strong>: You may add optional array
|
140
|
+
tags. Array tags allows multiple values delimited by
|
141
|
+
<code>ARRAY_TAG_DELIMITER</code> (default: <code>,</code>)</p>
|
142
|
+
</li><li>
|
143
|
+
<p><strong>ARRAY_TAG_DELIMITER (optional)</strong>: A delimiter to express
|
144
|
+
array. Default is <code>,</code></p>
|
145
|
+
</li><li>
|
146
|
+
<p><strong>LOG_LEVEL (optional)</strong>: Log level such as <code>info</code>,
|
147
|
+
<code>debug</code>, <code>error</code>. The default is <code>info</code>.</p>
|
148
|
+
</li></ul>
|
149
|
+
|
150
|
+
<p>See <a href="./example/example.conf">example.conf</a></p>
|
151
|
+
|
152
|
+
<h2 id="label-Tag+Example">Tag Example</h2>
|
153
|
+
<ul><li>
|
154
|
+
<p><strong>Name</strong>: hostname</p>
|
155
|
+
</li><li>
|
156
|
+
<p><strong>Roles</strong>: app:web,app:db</p>
|
157
|
+
</li><li>
|
158
|
+
<p><strong>Service</strong>: sugoi</p>
|
159
|
+
</li><li>
|
160
|
+
<p><strong>Status</strong>: setup</p>
|
161
|
+
</li></ul>
|
162
|
+
|
163
|
+
<h2 id="label-CLI+Usage">CLI Usage</h2>
|
164
|
+
|
165
|
+
<h3 id="label-CLI+Example">CLI Example</h3>
|
166
|
+
|
167
|
+
<pre class="code ruby"><code class="ruby">$ ec2-host -j
|
168
|
+
{"hostname":"test","roles":["admin:ami","test"],"region":"ap-northeast-1","instance_id":"i-85900780","private_ip_address":"172.31.23.50","public_ip_address":null,"launch_time":"2013-09-16 06:14:20 UTC","state":"running","monitoring":"disabled"}
|
169
|
+
{"hostname":"ip-172-31-6-194","roles":["isucon4:qual"],"region":"ap-northeast-1","instance_id":"i-f88cc8e1","private_ip_address":"172.31.6.194","public_ip_address":null,"launch_time":"2014-10-20 15:57:23 UTC","state":"running","monitoring":"disabled"}</code></pre>
|
170
|
+
|
171
|
+
<pre class="code ruby"><code class="ruby">$ ec2-host
|
172
|
+
test
|
173
|
+
ip-172-31-6-194 # if Name tag is not available</code></pre>
|
174
|
+
|
175
|
+
<pre class="code ruby"><code class="ruby">$ ec2-host --role1 admin
|
176
|
+
test</code></pre>
|
177
|
+
|
178
|
+
<pre class="code ruby"><code class="ruby">$ ec2-host --role admin:ami
|
179
|
+
test</code></pre>
|
180
|
+
|
181
|
+
<pre class="code ruby"><code class="ruby">$ ec2-host --pretty-json
|
182
|
+
[
|
183
|
+
{
|
184
|
+
"hostname": "test",
|
185
|
+
"roles": [
|
186
|
+
"admin:ami",
|
187
|
+
"test"
|
188
|
+
],
|
189
|
+
"region": "ap-northeast-1",
|
190
|
+
"instance_id": "i-85900780",
|
191
|
+
"private_ip_address": "172.31.23.50",
|
192
|
+
"public_ip_address": null,
|
193
|
+
"launch_time": "2013-09-16 06:14:20 UTC",
|
194
|
+
"state": "running",
|
195
|
+
"monitoring": "disabled"
|
196
|
+
},
|
197
|
+
{
|
198
|
+
"hostname": "ip-172-31-6-194",
|
199
|
+
"roles": [
|
200
|
+
"isucon4:qual"
|
201
|
+
],
|
202
|
+
"region": "ap-northeast-1",
|
203
|
+
"instance_id": "i-f88cc8e1",
|
204
|
+
"private_ip_address": "172.31.6.194",
|
205
|
+
"public_ip_address": null,
|
206
|
+
"launch_time": "2014-10-20 15:57:23 UTC",
|
207
|
+
"state": "running",
|
208
|
+
"monitoring": "disabled"
|
209
|
+
}
|
210
|
+
]</code></pre>
|
211
|
+
|
212
|
+
<h3 id="label-CLI+Help">CLI Help</h3>
|
213
|
+
|
214
|
+
<pre class="code ruby"><code class="ruby">$ bin/ec2-host --help
|
215
|
+
Usage: ec2-host [options]
|
216
|
+
--hostname one,two,three name or private_dns_name
|
217
|
+
-r, --role one,two,three role
|
218
|
+
--r1, --role1 one,two,three role1, the 1st part of role delimited by :
|
219
|
+
--r2, --role2 one,two,three role2, the 2st part of role delimited by :
|
220
|
+
--r3, --role3 one,two,three role3, the 3st part of role delimited by :
|
221
|
+
--instance-id one,two,three instance_id
|
222
|
+
--state one,two,three filter with instance state (default: running)
|
223
|
+
--monitoring one,two,three filter with instance monitoring
|
224
|
+
-a, --all list all hosts (remove default filter)
|
225
|
+
--private-ip, --ip show private ip address instead of hostname
|
226
|
+
--public-ip show public ip address instead of hostname
|
227
|
+
-i, --info show host info
|
228
|
+
-j, --jsonl show host info in line delimited json
|
229
|
+
--json show host info in json
|
230
|
+
--pretty-json show host info in pretty json
|
231
|
+
--debug debug mode
|
232
|
+
-h, --help show help</code></pre>
|
233
|
+
|
234
|
+
<h2 id="label-Library+Usage">Library Usage</h2>
|
235
|
+
|
236
|
+
<h3 id="label-Library+Example">Library Example</h3>
|
237
|
+
|
238
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ec2-host</span><span class='tstring_end'>'</span></span>
|
239
|
+
|
240
|
+
<span class='id identifier rubyid_hosts'>hosts</span> <span class='op'>=</span> <span class='const'>EC2</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'>'</span><span class='tstring_content'>admin:ami</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
241
|
+
<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>
|
242
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_host'>host</span>
|
243
|
+
<span class='kw'>end</span>
|
244
|
+
</code></pre>
|
245
|
+
|
246
|
+
<h3 id="label-Library+Reference">Library Reference</h3>
|
247
|
+
|
248
|
+
<p>See <a
|
249
|
+
href="http://sonots.github.io/ec2-host/frames.html">sonots.github.io/ec2-host/frames.html</a>.</p>
|
250
|
+
|
251
|
+
<h2 id="label-ChangeLog">ChangeLog</h2>
|
252
|
+
|
253
|
+
<p>See <a href="CHANGELOG.md">CHANGELOG.md</a> for details.</p>
|
254
|
+
|
255
|
+
<h2 id="label-For+Developers">For Developers</h2>
|
256
|
+
|
257
|
+
<h3 id="label-ToDo">ToDo</h3>
|
258
|
+
<ul><li>
|
259
|
+
<p>Support assume-roles</p>
|
260
|
+
</li><li>
|
261
|
+
<p>Use mock/stub to run test (currently, directly accessing to EC2)</p>
|
262
|
+
</li><li>
|
263
|
+
<p>Should cache a result of describe-instances in like 30 seconds?</p>
|
264
|
+
</li></ul>
|
265
|
+
|
266
|
+
<h3 id="label-How+to+Run+test">How to Run test</h3>
|
267
|
+
|
268
|
+
<p>NOTE: Currently, mock is not supported yet. So, you have to create your own
|
269
|
+
AWS account, and instances.</p>
|
270
|
+
|
271
|
+
<p>Configure .env file as</p>
|
272
|
+
|
273
|
+
<pre class="code ruby"><code class="ruby">AWS_ACCESS_KEY_ID=
|
274
|
+
AWS_SECRET_ACCESS_KEY=
|
275
|
+
AWS_DEFAULT_REGION=
|
276
|
+
EC2_HOST_CONFIG_FILE=.env
|
277
|
+
OPTIONAL_ARRAY_TAGS=Tags
|
278
|
+
OPTIONAL_STRING_TAGS=Service,Status</code></pre>
|
279
|
+
|
280
|
+
<p>Install terraform and run to create instances for tests</p>
|
281
|
+
|
282
|
+
<pre class="code ruby"><code class="ruby">$ brew install terraform
|
283
|
+
$ env $(cat .env) terraform plan
|
284
|
+
$ env ($cat .env) terraform apply</code></pre>
|
285
|
+
|
286
|
+
<p>Run test</p>
|
287
|
+
|
288
|
+
<pre class="code ruby"><code class="ruby">$ bundle exec rspec</code></pre>
|
289
|
+
|
290
|
+
<p>After working, destory instances by commenting out
|
291
|
+
<code>terraform.tf</code> and apply.</p>
|
292
|
+
|
293
|
+
<h3 id="label-How+to+Release+Gem">How to Release Gem</h3>
|
294
|
+
<ol><li>
|
295
|
+
<p>Update gem.version in the gemspec</p>
|
296
|
+
</li><li>
|
297
|
+
<p>Update CHANGELOG.md</p>
|
298
|
+
</li><li>
|
299
|
+
<p>git commit && git push</p>
|
300
|
+
</li><li>
|
301
|
+
<p>Run <code>bundle exec rake release</code></p>
|
302
|
+
</li></ol>
|
303
|
+
|
304
|
+
<h3 id="label-How+to+Update+doc">How to Update doc</h3>
|
305
|
+
<ol><li>
|
306
|
+
<p>Run <code>bundle exec yard</code></p>
|
307
|
+
</li><li>
|
308
|
+
<p>git commit && git push</p>
|
309
|
+
</li></ol>
|
310
|
+
|
311
|
+
<h3 id="label-Licenses">Licenses</h3>
|
312
|
+
|
313
|
+
<p>See <a href="LICENSE">LICENSE</a></p>
|
314
|
+
</div></div>
|
315
|
+
|
316
|
+
<div id="footer">
|
317
|
+
Generated on Thu Nov 24 10:25:35 2016 by
|
318
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
319
|
+
0.8.7.6 (ruby-2.3.2).
|
320
|
+
</div>
|
321
|
+
|
322
|
+
</body>
|
323
|
+
</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);
|