digital_ocean 0.0.1 → 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. data/.gitignore +0 -1
  2. data/CHANGELOG.md +40 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +114 -2
  5. data/digital_ocean.gemspec +1 -0
  6. data/doc/DigitalOcean/API.html +844 -0
  7. data/doc/DigitalOcean/AuthenticationMiddleware.html +342 -0
  8. data/doc/DigitalOcean/Resource/Base.html +206 -0
  9. data/doc/DigitalOcean/Resource/Droplet.html +1016 -0
  10. data/doc/DigitalOcean/Resource/Image.html +312 -0
  11. data/doc/DigitalOcean/Resource/Region.html +247 -0
  12. data/doc/DigitalOcean/Resource/SSHKey.html +312 -0
  13. data/doc/DigitalOcean/Resource/Size.html +208 -0
  14. data/doc/DigitalOcean/Resource.html +117 -0
  15. data/doc/DigitalOcean.html +131 -0
  16. data/doc/_index.html +213 -0
  17. data/doc/class_list.html +53 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +57 -0
  20. data/doc/css/style.css +328 -0
  21. data/doc/file.README.html +402 -0
  22. data/doc/file_list.html +55 -0
  23. data/doc/frames.html +28 -0
  24. data/doc/index.html +402 -0
  25. data/doc/js/app.js +214 -0
  26. data/doc/js/full_list.js +173 -0
  27. data/doc/js/jquery.js +4 -0
  28. data/doc/method_list.html +332 -0
  29. data/doc/top-level-namespace.html +112 -0
  30. data/lib/digital_ocean/api.rb +28 -0
  31. data/lib/digital_ocean/resource/droplet.rb +2 -2
  32. data/lib/digital_ocean/resource/region.rb +3 -0
  33. data/lib/digital_ocean/version.rb +1 -1
  34. data/spec/api_spec.rb +8 -4
  35. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_create/should_be_successful.yml +7 -5
  36. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_create/should_return_droplet_id.yml +50 -0
  37. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_delete/should_be_successful.yml +8 -6
  38. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_disable_backups/should_be_successful.yml +8 -6
  39. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_enable_backups/should_be_successful.yml +8 -6
  40. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_list/should_be_successful.yml +7 -5
  41. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_list/should_return_a_list_of_all_droplets.yml +7 -5
  42. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/{_reset_root_password → _password_reset}/should_be_successful.yml +10 -9
  43. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_cycle/should_be_successful.yml +8 -6
  44. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_off/should_be_successful.yml +8 -6
  45. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_on/should_be_successful.yml +8 -6
  46. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_reboot/should_be_successful.yml +8 -6
  47. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_rebuild/should_be_successful.yml +8 -6
  48. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_resize/should_be_successful.yml +8 -6
  49. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_restore/should_be_successful.yml +1 -1
  50. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_show/should_be_successful.yml +6 -4
  51. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_shutdown/should_be_successful.yml +8 -6
  52. data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_snapshot/should_be_successful.yml +8 -6
  53. metadata +34 -7
data/doc/index.html ADDED
@@ -0,0 +1,402 @@
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.3
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" 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#!" + escape(window.location.href);
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'><h1>DigitalOcean</h1>
65
+
66
+ <p><a href="https://travis-ci.org/rmoriz/digital_ocean"><img src="https://travis-ci.org/rmoriz/digital_ocean.png" alt="Build Status"></a>
67
+ <a href="https://gemnasium.com/rmoriz/digital_ocean"><img src="https://gemnasium.com/rmoriz/digital_ocean.png" height="13" /></a>
68
+ <a href="https://codeclimate.com/github/rmoriz/digital_ocean"><img src="https://codeclimate.com/github/rmoriz/digital_ocean.png" height="13" /></a></p>
69
+
70
+ <p>DigitalOcean provides simple cloud hosting. Create and delete
71
+ SSD-based virtual machines within seconds for a very affordable price.</p>
72
+
73
+ <p>Go to <a href="https://www.digitalocean.com/">https://www.digitalocean.com/</a> for more information.</p>
74
+
75
+ <p>This gem is a simple ruby wrapper for the <a href="https://api.digitalocean.com/">HTTP API of DigitalOcean</a> using
76
+ the great <a href="https://github.com/lostisland/faraday">Faraday</a> library.</p>
77
+
78
+ <p><strong><em>If you use <a href="http://www.opscode.com/">Opscode Chef</a> for DevOps, make sure to checkout my knife plugin <a href="https://github.com/rmoriz/knife-digital_ocean">knife-digital_ocean</a></em></strong></p>
79
+
80
+ <h2>Installation</h2>
81
+
82
+ <p>Add this line to your application&#39;s Gemfile:</p>
83
+
84
+ <pre class="code ruby"><code><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>digital_ocean</span><span class='tstring_end'>'</span></span>
85
+ </code></pre>
86
+
87
+ <p>And then execute:</p>
88
+
89
+ <pre class="code ruby"><code>$ bundle
90
+ </code></pre>
91
+
92
+ <p>Or install it yourself as:</p>
93
+
94
+ <pre class="code ruby"><code>$ gem install digital_ocean
95
+ </code></pre>
96
+
97
+ <h2>Prerequisite: Create an account and API credentials</h2>
98
+
99
+ <p><a href="https://www.digitalocean.com/login"><img src="http://i.imgur.com/1iYdSFF.png" alt="Create API credentials"></a></p>
100
+
101
+ <h2>Usage</h2>
102
+
103
+ <h3>Examples</h3>
104
+
105
+ <pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>digital_ocean</span><span class='tstring_end'>'</span></span>
106
+
107
+ <span class='comment'># 1. create a client instance
108
+ </span><span class='comment'>#
109
+ </span><span class='id identifier rubyid_dc'>dc</span> <span class='op'>=</span> <span class='const'>DigitalOcean</span><span class='op'>::</span><span class='const'>API</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:client_id</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>YOUR_CLIENT_ID</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
110
+ <span class='symbol'>:api_key</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>YOUR_API_KEY</span><span class='tstring_end'>'</span></span>
111
+
112
+ <span class='comment'># 2. get all regions (server locations)
113
+ </span><span class='comment'>#
114
+ </span><span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_dc'>dc</span><span class='period'>.</span><span class='id identifier rubyid_regions'>regions</span><span class='period'>.</span><span class='id identifier rubyid_list'>list</span>
115
+ <span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_regions'>regions</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='comment'># =&gt; 2
116
+ </span><span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_regions'>regions</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='comment'># =&gt; &quot;New York 1&quot;
117
+ </span>
118
+ <span class='comment'># 3. get all available machine types (sizes)
119
+ </span><span class='comment'>#
120
+ </span><span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_dc'>dc</span><span class='period'>.</span><span class='id identifier rubyid_sizes'>sizes</span><span class='period'>.</span><span class='id identifier rubyid_list'>list</span>
121
+ <span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_sizes'>sizes</span>
122
+ <span class='comment'># =&gt; [#&lt;Hashie::Rash id=66 name=&quot;512MB&quot;&gt;,
123
+ </span><span class='comment'># #&lt;Hashie::Rash id=63 name=&quot;1GB&quot;&gt;,
124
+ </span><span class='comment'># #&lt;Hashie::Rash id=62 name=&quot;2GB&quot;&gt;,
125
+ </span><span class='comment'># #&lt;Hashie::Rash id=64 name=&quot;4GB&quot;&gt;,
126
+ </span><span class='comment'># #&lt;Hashie::Rash id=65 name=&quot;8GB&quot;&gt;,
127
+ </span><span class='comment'># #&lt;Hashie::Rash id=61 name=&quot;16GB&quot;&gt;,
128
+ </span><span class='comment'># #&lt;Hashie::Rash id=60 name=&quot;32GB&quot;&gt;,
129
+ </span><span class='comment'># #&lt;Hashie::Rash id=70 name=&quot;48GB&quot;&gt;,
130
+ </span><span class='comment'># #&lt;Hashie::Rash id=69 name=&quot;64GB&quot;&gt;,
131
+ </span><span class='comment'># #&lt;Hashie::Rash id=68 name=&quot;96GB&quot;&gt;]
132
+ </span>
133
+ <span class='comment'># 4. get all available images (e.g. OS-Images, snapshots, backups)
134
+ </span><span class='comment'>#
135
+ </span><span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_dc'>dc</span><span class='period'>.</span><span class='id identifier rubyid_images'>images</span><span class='period'>.</span><span class='id identifier rubyid_list'>list</span>
136
+ <span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_images'>images</span>
137
+ <span class='comment'># =&gt; [#&lt;Hashie::Rash distribution=&quot;CentOS&quot; id=1601 name=&quot;CentOS 5.8 x64&quot;&gt;,
138
+ </span><span class='comment'># #&lt;Hashie::Rash distribution=&quot;CentOS&quot; id=1602 name=&quot;CentOS 5.8 x32&quot;&gt;,
139
+ </span><span class='comment'># ...
140
+ </span><span class='comment'># #&lt;Hashie::Rash distribution=&quot;Ubuntu&quot; id=2676 name=&quot;Ubuntu 12.04 x64 Server&quot;&gt;,
141
+ </span><span class='comment'># ...
142
+ </span><span class='comment'># #&lt;Hashie::Rash distribution=&quot;Ubuntu&quot; id=25306 name=&quot;Ubuntu 12.10 x32 Server&quot;&gt;,
143
+ </span><span class='comment'># ...]
144
+ </span>
145
+ <span class='comment'># 5. start a new instance (called droplet)
146
+ </span><span class='comment'>#
147
+ </span><span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_dc'>dc</span><span class='period'>.</span><span class='id identifier rubyid_droplets'>droplets</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span> <span class='symbol'>:name</span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>new_hostname</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
148
+ <span class='symbol'>:size_id</span> <span class='op'>=&gt;</span> <span class='int'>64</span><span class='comma'>,</span>
149
+ <span class='symbol'>:image_id</span> <span class='op'>=&gt;</span> <span class='int'>2676</span><span class='comma'>,</span>
150
+ <span class='symbol'>:region_id</span> <span class='op'>=&gt;</span> <span class='int'>1</span>
151
+
152
+ <span class='comment'># 6. query droplet status (e.g. to get the IP of a droplet)
153
+ </span><span class='comment'>#
154
+ </span><span class='id identifier rubyid_res'>res</span> <span class='op'>=</span> <span class='id identifier rubyid_dc'>dc</span><span class='period'>.</span><span class='id identifier rubyid_droplets'>droplets</span><span class='period'>.</span><span class='id identifier rubyid_list'>list</span>
155
+ <span class='id identifier rubyid_res'>res</span><span class='period'>.</span><span class='id identifier rubyid_droplets'>droplets</span>
156
+ <span class='comment'># =&gt; [#&lt;Hashie::Rash backups_active=false id=123456
157
+ </span><span class='comment'># image_id=25306 ip_address=&quot;123.123.123.123&quot;
158
+ </span><span class='comment'># name=&quot;new_hostname&quot; region_id=1 size_id=64
159
+ </span><span class='comment'># status=&quot;active&quot;&gt;]
160
+ </span>
161
+ </code></pre>
162
+
163
+ <p>see <code>spec/api_spec.rb</code> for more details and all implemented
164
+ resources.</p>
165
+
166
+ <h2>Features</h2>
167
+
168
+ <h3>DigitalOcean::API</h3>
169
+
170
+ <ul>
171
+ <li>.new
172
+
173
+ <ul>
174
+ <li>should return an instance when called with the essential parameters</li>
175
+ </ul></li>
176
+ <li>#droplets
177
+
178
+ <ul>
179
+ <li>#list
180
+
181
+ <ul>
182
+ <li>should be successful</li>
183
+ <li>should return a list of all droplets</li>
184
+ </ul></li>
185
+ <li>#show
186
+
187
+ <ul>
188
+ <li>should be successful</li>
189
+ </ul></li>
190
+ <li>#create
191
+
192
+ <ul>
193
+ <li>should be successful</li>
194
+ <li>should return a droplet.id</li>
195
+ </ul></li>
196
+ <li>#reboot
197
+
198
+ <ul>
199
+ <li>should be successful</li>
200
+ </ul></li>
201
+ <li>#power_cycle
202
+
203
+ <ul>
204
+ <li>should be successful</li>
205
+ </ul></li>
206
+ <li>#shutdown
207
+
208
+ <ul>
209
+ <li>should be successful</li>
210
+ </ul></li>
211
+ <li>#power_on
212
+
213
+ <ul>
214
+ <li>should be successful</li>
215
+ </ul></li>
216
+ <li>#power_off
217
+
218
+ <ul>
219
+ <li>should be successful</li>
220
+ </ul></li>
221
+ <li>#password_reset
222
+
223
+ <ul>
224
+ <li>should be successful</li>
225
+ </ul></li>
226
+ <li>#resize
227
+
228
+ <ul>
229
+ <li>should be successful</li>
230
+ </ul></li>
231
+ <li>#snapshot
232
+
233
+ <ul>
234
+ <li>should be successful</li>
235
+ </ul></li>
236
+ <li>#restore
237
+
238
+ <ul>
239
+ <li>should be successful</li>
240
+ </ul></li>
241
+ <li>#rebuild
242
+
243
+ <ul>
244
+ <li>should be successful</li>
245
+ </ul></li>
246
+ <li>#enable_backups
247
+
248
+ <ul>
249
+ <li>should be successful</li>
250
+ </ul></li>
251
+ <li>#disable_backups
252
+
253
+ <ul>
254
+ <li>should be successful</li>
255
+ </ul></li>
256
+ <li>#delete
257
+ #<Hashie::Rash event_id=594739 status="OK">
258
+
259
+ <ul>
260
+ <li>should be successful</li>
261
+ </ul></li>
262
+ </ul></li>
263
+ <li>#sizes
264
+
265
+ <ul>
266
+ <li>#list
267
+
268
+ <ul>
269
+ <li>should be successful</li>
270
+ <li>should return a list of all droplet sizes</li>
271
+ <li>should return the correct ID for the 96GB size</li>
272
+ </ul></li>
273
+ </ul></li>
274
+ <li>#regions
275
+
276
+ <ul>
277
+ <li>#list
278
+
279
+ <ul>
280
+ <li>should be successful</li>
281
+ <li>should return a list of all regions</li>
282
+ </ul></li>
283
+ </ul></li>
284
+ <li>#ssh_keys
285
+
286
+ <ul>
287
+ <li>#list
288
+
289
+ <ul>
290
+ <li>should be successful</li>
291
+ <li>should return a list of all SSH keys</li>
292
+ </ul></li>
293
+ <li>#show
294
+
295
+ <ul>
296
+ <li>valid</li>
297
+ <li>should be successful</li>
298
+ <li>should return the public keykey</li>
299
+ <li>invalid</li>
300
+ <li>should not be successful</li>
301
+ </ul></li>
302
+ <li>#add
303
+
304
+ <ul>
305
+ <li>does not work, ask digitalocean to fix (PENDING: No reason given)</li>
306
+ <li>should be successful (PENDING: Temporarily disabled with xit)</li>
307
+ </ul></li>
308
+ <li>#edit
309
+
310
+ <ul>
311
+ <li>does not work, ask digitalocean to fix (PENDING: No reason given)</li>
312
+ </ul></li>
313
+ <li>#delete
314
+
315
+ <ul>
316
+ <li>should be successful</li>
317
+ </ul></li>
318
+ </ul></li>
319
+ <li>#images
320
+
321
+ <ul>
322
+ <li>#list
323
+
324
+ <ul>
325
+ <li>without filter</li>
326
+ <li>should be successful</li>
327
+ <li>should return a list of all images</li>
328
+ <li>with filter: global</li>
329
+ <li>should be successful</li>
330
+ <li>should return global images</li>
331
+ <li>with filter: my_images</li>
332
+ <li>should be successful</li>
333
+ <li>should return my_images</li>
334
+ </ul></li>
335
+ <li>#show
336
+
337
+ <ul>
338
+ <li>valid</li>
339
+ <li>should be successful</li>
340
+ <li>should return the image</li>
341
+ <li>invalid</li>
342
+ <li>should not be successful</li>
343
+ </ul></li>
344
+ <li>#delete
345
+
346
+ <ul>
347
+ <li>valid</li>
348
+ <li>should be successful (PENDING: does not work, ask digitalocean to fix)</li>
349
+ <li>invalid</li>
350
+ <li>should not be successful</li>
351
+ </ul></li>
352
+ </ul></li>
353
+ </ul>
354
+
355
+ <h3>DigitalOcean</h3>
356
+
357
+ <ul>
358
+ <li>should have a version number</li>
359
+ </ul>
360
+
361
+ <h2>Contributing</h2>
362
+
363
+ <ol>
364
+ <li>Fork it</li>
365
+ <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
366
+ <li>Commit your changes (<code>git commit -am &#39;Add some feature&#39;</code>)</li>
367
+ <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
368
+ <li>Create new Pull Request</li>
369
+ </ol>
370
+
371
+ <h3>Contributors</h3>
372
+
373
+ <ul>
374
+ <li> <a href="https://github.com/joshfng">joshfng</a> </li>
375
+ <li> <a href="https://github.com/willglynn">willglynn</a> </li>
376
+ </ul>
377
+
378
+ <p>For more information and a complete list see <a href="https://github.com/rmoriz/digital_ocean/contributors">the contributor page on GitHub</a>.</p>
379
+
380
+ <h2>License</h2>
381
+
382
+ <p>MIT</p>
383
+
384
+ <h2>Commercial Support</h2>
385
+
386
+ <p>Commercial support is available. Please contact <a href="https://roland.io/">https://roland.io/</a> or <a href="http://moriz.com/">http://moriz.com/</a></p>
387
+
388
+ <h2>Copyright</h2>
389
+
390
+ <p>Copyright © 2013 <a href="https://roland.io">Roland Moriz</a>, <a href="https://moriz.de/">Moriz GmbH</a></p>
391
+
392
+ <p><a href="http://www.linkedin.com/in/rmoriz"><img src="http://www.linkedin.com/img/webpromo/btn_viewmy_160x25.png" alt="LinkedIn"></a></p>
393
+ </div></div>
394
+
395
+ <div id="footer">
396
+ Generated on Wed Feb 20 12:33:48 2013 by
397
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
398
+ 0.8.3 (ruby-1.9.3).
399
+ </div>
400
+
401
+ </body>
402
+ </html>
data/doc/js/app.js ADDED
@@ -0,0 +1,214 @@
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
+ window.top.document.title = $('html head title').text();
82
+ }
83
+ else {
84
+ $('#menu .noframes a').text('frames').attr('href', framesUrl);
85
+ }
86
+ }
87
+
88
+ function keyboardShortcuts() {
89
+ if (window.top.frames.main) return;
90
+ $(document).keypress(function(evt) {
91
+ if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return;
92
+ if (typeof evt.target !== "undefined" &&
93
+ (evt.target.nodeName == "INPUT" ||
94
+ evt.target.nodeName == "TEXTAREA")) return;
95
+ switch (evt.charCode) {
96
+ case 67: case 99: $('#class_list_link').click(); break; // 'c'
97
+ case 77: case 109: $('#method_list_link').click(); break; // 'm'
98
+ case 70: case 102: $('#file_list_link').click(); break; // 'f'
99
+ default: break;
100
+ }
101
+ });
102
+ }
103
+
104
+ function summaryToggle() {
105
+ $('.summary_toggle').click(function() {
106
+ if (localStorage) {
107
+ localStorage.summaryCollapsed = $(this).text();
108
+ }
109
+ $('.summary_toggle').each(function() {
110
+ $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
111
+ var next = $(this).parent().parent().nextAll('ul.summary').first();
112
+ if (next.hasClass('compact')) {
113
+ next.toggle();
114
+ next.nextAll('ul.summary').first().toggle();
115
+ }
116
+ else if (next.hasClass('summary')) {
117
+ var list = $('<ul class="summary compact" />');
118
+ list.html(next.html());
119
+ list.find('.summary_desc, .note').remove();
120
+ list.find('a').each(function() {
121
+ $(this).html($(this).find('strong').html());
122
+ $(this).parent().html($(this)[0].outerHTML);
123
+ });
124
+ next.before(list);
125
+ next.toggle();
126
+ }
127
+ });
128
+ return false;
129
+ });
130
+ if (localStorage) {
131
+ if (localStorage.summaryCollapsed == "collapse") {
132
+ $('.summary_toggle').first().click();
133
+ }
134
+ else localStorage.summaryCollapsed = "expand";
135
+ }
136
+ }
137
+
138
+ function fixOutsideWorldLinks() {
139
+ $('a').each(function() {
140
+ if (window.location.host != this.host) this.target = '_parent';
141
+ });
142
+ }
143
+
144
+ function generateTOC() {
145
+ if ($('#filecontents').length === 0) return;
146
+ var _toc = $('<ol class="top"></ol>');
147
+ var show = false;
148
+ var toc = _toc;
149
+ var counter = 0;
150
+ var tags = ['h2', 'h3', 'h4', 'h5', 'h6'];
151
+ var i;
152
+ if ($('#filecontents h1').length > 1) tags.unshift('h1');
153
+ for (i = 0; i < tags.length; i++) { tags[i] = '#filecontents ' + tags[i]; }
154
+ var lastTag = parseInt(tags[0][1], 10);
155
+ $(tags.join(', ')).each(function() {
156
+ if ($(this).parents('.method_details .docstring').length != 0) return;
157
+ if (this.id == "filecontents") return;
158
+ show = true;
159
+ var thisTag = parseInt(this.tagName[1], 10);
160
+ if (this.id.length === 0) {
161
+ var proposedId = $(this).attr('toc-id');
162
+ if (typeof(proposedId) != "undefined") this.id = proposedId;
163
+ else {
164
+ var proposedId = $(this).text().replace(/[^a-z0-9-]/ig, '_');
165
+ if ($('#' + proposedId).length > 0) { proposedId += counter; counter++; }
166
+ this.id = proposedId;
167
+ }
168
+ }
169
+ if (thisTag > lastTag) {
170
+ for (i = 0; i < thisTag - lastTag; i++) {
171
+ var tmp = $('<ol/>'); toc.append(tmp); toc = tmp;
172
+ }
173
+ }
174
+ if (thisTag < lastTag) {
175
+ for (i = 0; i < lastTag - thisTag; i++) toc = toc.parent();
176
+ }
177
+ var title = $(this).attr('toc-title');
178
+ if (typeof(title) == "undefined") title = $(this).text();
179
+ toc.append('<li><a href="#' + this.id + '">' + title + '</a></li>');
180
+ lastTag = thisTag;
181
+ });
182
+ if (!show) return;
183
+ 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>';
184
+ $('#content').prepend(html);
185
+ $('#toc').append(_toc);
186
+ $('#toc .hide_toc').toggle(function() {
187
+ $('#toc .top').slideUp('fast');
188
+ $('#toc').toggleClass('hidden');
189
+ $('#toc .title small').toggle();
190
+ }, function() {
191
+ $('#toc .top').slideDown('fast');
192
+ $('#toc').toggleClass('hidden');
193
+ $('#toc .title small').toggle();
194
+ });
195
+ $('#toc .float_toc').toggle(function() {
196
+ $(this).text('float');
197
+ $('#toc').toggleClass('nofloat');
198
+ }, function() {
199
+ $(this).text('left');
200
+ $('#toc').toggleClass('nofloat');
201
+ });
202
+ }
203
+
204
+ $(framesInit);
205
+ $(createSourceLinks);
206
+ $(createDefineLinks);
207
+ $(createFullTreeLinks);
208
+ $(fixBoxInfoHeights);
209
+ $(searchFrameLinks);
210
+ $(linkSummaries);
211
+ $(keyboardShortcuts);
212
+ $(summaryToggle);
213
+ $(fixOutsideWorldLinks);
214
+ $(generateTOC);