oration 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,558 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
7
+
8
+ <title>Module: Generator</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="module">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./lib/generator_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/generator.rb">lib/generator.rb</a></li>
43
+
44
+ </ul>
45
+ </div>
46
+ </div>
47
+
48
+
49
+ </div>
50
+
51
+ <div id="class-metadata">
52
+
53
+ <!-- Parent Class -->
54
+
55
+
56
+ <!-- Namespace Contents -->
57
+
58
+
59
+ <!-- Method Quickref -->
60
+
61
+ <div id="method-list-section" class="section">
62
+ <h3 class="section-header">Methods</h3>
63
+ <ul class="link-list">
64
+
65
+ <li><a href="#method-c-generate_app">::generate_app</a></li>
66
+
67
+ <li><a href="#method-c-generate_go_app">::generate_go_app</a></li>
68
+
69
+ <li><a href="#method-c-generate_python_app">::generate_python_app</a></li>
70
+
71
+ <li><a href="#method-c-get_go_function">::get_go_function</a></li>
72
+
73
+ <li><a href="#method-c-get_python_function">::get_python_function</a></li>
74
+
75
+ <li><a href="#method-c-write_go_app_yaml_file">::write_go_app_yaml_file</a></li>
76
+
77
+ <li><a href="#method-c-write_go_cicero_code">::write_go_cicero_code</a></li>
78
+
79
+ <li><a href="#method-c-write_python_app_yaml_file">::write_python_app_yaml_file</a></li>
80
+
81
+ <li><a href="#method-c-write_python_cicero_code">::write_python_cicero_code</a></li>
82
+
83
+ </ul>
84
+ </div>
85
+
86
+
87
+ <!-- Included Modules -->
88
+
89
+ </div>
90
+
91
+ <div id="project-metadata">
92
+
93
+
94
+
95
+ <div id="classindex-section" class="section project-section">
96
+ <h3 class="section-header">Class/Module Index
97
+ <span class="search-toggle"><img src="./images/find.png"
98
+ height="16" width="16" alt="[+]"
99
+ title="show/hide quicksearch" /></span></h3>
100
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
101
+ <fieldset>
102
+ <legend>Quicksearch</legend>
103
+ <input type="text" name="quicksearch" value=""
104
+ class="quicksearch-field" />
105
+ </fieldset>
106
+ </form>
107
+
108
+ <ul class="link-list">
109
+
110
+ <li><a href="./Generator.html">Generator</a></li>
111
+
112
+ <li><a href="./Object.html">Object</a></li>
113
+
114
+ </ul>
115
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
116
+ </div>
117
+
118
+
119
+ </div>
120
+ </div>
121
+
122
+ <div id="documentation">
123
+ <h1 class="module">Generator</h1>
124
+
125
+ <div id="description">
126
+
127
+ </div>
128
+
129
+ <!-- Constants -->
130
+
131
+
132
+ <!-- Attributes -->
133
+
134
+
135
+ <!-- Methods -->
136
+
137
+ <div id="public-class-method-details" class="method-section section">
138
+ <h3 class="section-header">Public Class Methods</h3>
139
+
140
+
141
+ <div id="generate_app-method" class="method-detail ">
142
+ <a name="method-c-generate_app"></a>
143
+
144
+
145
+ <div class="method-heading">
146
+ <span class="method-name">generate_app</span><span
147
+ class="method-args">(main_file, function_name, output_dir, generate_python_app=Generator.method(:generate_python_app), generate_go_app=Generator.method(:generate_go_app))</span>
148
+ <span class="method-click-advice">click to toggle source</span>
149
+ </div>
150
+
151
+
152
+ <div class="method-description">
153
+
154
+ <p>This function finds out what language the application we need to make
155
+ ‘Cicero-ready’ is, and if it is a supported language, dispatches the
156
+ necessary function to do so. See SUPPORTED_LANGUAGES for the currently
157
+ supported languages.</p>
158
+
159
+
160
+
161
+ <div class="method-source-code"
162
+ id="generate_app-source">
163
+ <pre>
164
+ <span class="ruby-comment"># File lib/generator.rb, line 18</span>
165
+ def self.generate_app(main_file,
166
+ function_name,
167
+ output_dir,
168
+ generate_python_app=<span class="ruby-constant">Generator</span>.method(:generate_python_app),
169
+ generate_go_app=<span class="ruby-constant">Generator</span>.method(:generate_go_app))
170
+
171
+ file_suffix = main_file.scan(<span class="ruby-regexp">/\.(.*)\Z/</span>).flatten.to_s
172
+
173
+ if file_suffix.empty? <span class="ruby-comment"># no suffix</span>
174
+ abort(<span class="ruby-string">&quot;The file specified needs an extension.&quot;</span>)
175
+ end
176
+
177
+ if !<span class="ruby-constant">SUPPORTED_LANGUAGES</span>.include?(file_suffix)
178
+ abort(<span class="ruby-string">&quot;The file specified is not in a supported language. Supported &quot;</span> +
179
+ &quot;languages are #{SUPPORTED_LANGUAGES.join(', ')}&quot;)
180
+ end
181
+
182
+ case file_suffix
183
+ when <span class="ruby-string">&quot;py&quot;</span>
184
+ generate_python_app.call(main_file, function_name, output_dir)
185
+ when <span class="ruby-string">&quot;go&quot;</span>
186
+ generate_go_app.call(main_file, function_name, output_dir)
187
+ end
188
+ end</pre>
189
+ </div>
190
+
191
+ </div>
192
+
193
+
194
+
195
+
196
+ </div>
197
+
198
+
199
+ <div id="generate_go_app-method" class="method-detail ">
200
+ <a name="method-c-generate_go_app"></a>
201
+
202
+
203
+ <div class="method-heading">
204
+ <span class="method-name">generate_go_app</span><span
205
+ class="method-args">(main_file, function_name, output_dir, get_go_function=Generator.method(:get_go_function), make_directory=FileUtils.method(:mkdir_p), write_go_app_yaml=Generator.method(:write_go_app_yaml_file), write_go_cicero_code=Generator.method(:write_go_cicero_code))</span>
206
+ <span class="method-click-advice">click to toggle source</span>
207
+ </div>
208
+
209
+
210
+ <div class="method-description">
211
+
212
+ <p>This method generates a Go Google App Engine application containing the
213
+ function that the user specified.</p>
214
+
215
+
216
+
217
+ <div class="method-source-code"
218
+ id="generate_go_app-source">
219
+ <pre>
220
+ <span class="ruby-comment"># File lib/generator.rb, line 62</span>
221
+ def self.generate_go_app(main_file, function_name, output_dir,
222
+ get_go_function=<span class="ruby-constant">Generator</span>.method(:get_go_function),
223
+ make_directory=<span class="ruby-constant">FileUtils</span>.method(:mkdir_p),
224
+ write_go_app_yaml=<span class="ruby-constant">Generator</span>.method(:write_go_app_yaml_file),
225
+ write_go_cicero_code=<span class="ruby-constant">Generator</span>.method(:write_go_cicero_code))
226
+
227
+ function = get_go_function.call(main_file, function_name)
228
+ make_directory.call(output_dir)
229
+
230
+ go_code_folder = output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> + function_name
231
+ make_directory.call(go_code_folder)
232
+
233
+ write_go_app_yaml.call(function_name, output_dir)
234
+ write_go_cicero_code.call(function, function_name, go_code_folder)
235
+ end</pre>
236
+ </div>
237
+
238
+ </div>
239
+
240
+
241
+
242
+
243
+ </div>
244
+
245
+
246
+ <div id="generate_python_app-method" class="method-detail ">
247
+ <a name="method-c-generate_python_app"></a>
248
+
249
+
250
+ <div class="method-heading">
251
+ <span class="method-name">generate_python_app</span><span
252
+ class="method-args">(main_file, function_name, output_dir, get_python_function=Generator.method(:get_python_function), make_directory=FileUtils.method(:mkdir_p), write_python_app_yaml=Generator.method(:write_python_app_yaml_file), write_python_cicero_code=Generator.method(:write_python_cicero_code))</span>
253
+ <span class="method-click-advice">click to toggle source</span>
254
+ </div>
255
+
256
+
257
+ <div class="method-description">
258
+
259
+ <p>This method generates a Python Google App Engine application containing the
260
+ function that the user specified. This requires us to search their code for
261
+ the actual function, make a directory for their app, write an app.yaml for
262
+ the app, and a Python file containing our Cicero interface and their
263
+ function.</p>
264
+
265
+
266
+
267
+ <div class="method-source-code"
268
+ id="generate_python_app-source">
269
+ <pre>
270
+ <span class="ruby-comment"># File lib/generator.rb, line 48</span>
271
+ def self.generate_python_app(main_file, function_name, output_dir,
272
+ get_python_function=<span class="ruby-constant">Generator</span>.method(:get_python_function),
273
+ make_directory=<span class="ruby-constant">FileUtils</span>.method(:mkdir_p),
274
+ write_python_app_yaml=<span class="ruby-constant">Generator</span>.method(:write_python_app_yaml_file),
275
+ write_python_cicero_code=<span class="ruby-constant">Generator</span>.method(:write_python_cicero_code))
276
+
277
+ function = get_python_function.call(main_file, function_name)
278
+ make_directory.call(output_dir)
279
+ write_python_app_yaml.call(function_name, output_dir)
280
+ write_python_cicero_code.call(function, function_name, output_dir)
281
+ end</pre>
282
+ </div>
283
+
284
+ </div>
285
+
286
+
287
+
288
+
289
+ </div>
290
+
291
+
292
+ <div id="get_go_function-method" class="method-detail ">
293
+ <a name="method-c-get_go_function"></a>
294
+
295
+
296
+ <div class="method-heading">
297
+ <span class="method-name">get_go_function</span><span
298
+ class="method-args">(main_file, function_name, file=File)</span>
299
+ <span class="method-click-advice">click to toggle source</span>
300
+ </div>
301
+
302
+
303
+ <div class="method-description">
304
+
305
+ <p>Given a Go source code file to read, finds the named function and returns
306
+ everything at and after that method’s definition. TODO(cgb): Parse just
307
+ the function instead of everything in the file after where the function
308
+ starts.</p>
309
+
310
+
311
+
312
+ <div class="method-source-code"
313
+ id="get_go_function-source">
314
+ <pre>
315
+ <span class="ruby-comment"># File lib/generator.rb, line 131</span>
316
+ def self.get_go_function(main_file, function_name, file=<span class="ruby-constant">File</span>)
317
+ contents = file.open(main_file) { |f| f.read }
318
+ function = contents.scan(/(func #{function_name}(.|\n)*)/).flatten[0]
319
+ return function
320
+ end</pre>
321
+ </div>
322
+
323
+ </div>
324
+
325
+
326
+
327
+
328
+ </div>
329
+
330
+
331
+ <div id="get_python_function-method" class="method-detail ">
332
+ <a name="method-c-get_python_function"></a>
333
+
334
+
335
+ <div class="method-heading">
336
+ <span class="method-name">get_python_function</span><span
337
+ class="method-args">(main_file, function_name, file=File)</span>
338
+ <span class="method-click-advice">click to toggle source</span>
339
+ </div>
340
+
341
+
342
+ <div class="method-description">
343
+
344
+ <p>This method opens main_file and parses out the function named
345
+ function_name, returning a string with the contents of that function. We
346
+ assume that the user only has one function in their file right now after
347
+ zero or more import statements.</p>
348
+
349
+
350
+
351
+ <div class="method-source-code"
352
+ id="get_python_function-source">
353
+ <pre>
354
+ <span class="ruby-comment"># File lib/generator.rb, line 82</span>
355
+ def self.get_python_function(main_file, function_name, file=<span class="ruby-constant">File</span>)
356
+ contents = file.open(main_file) { |f| f.read }
357
+ function = contents.scan(/(def #{function_name}(.|\n)*)/).flatten[0]
358
+ return function
359
+ end</pre>
360
+ </div>
361
+
362
+ </div>
363
+
364
+
365
+
366
+
367
+ </div>
368
+
369
+
370
+ <div id="write_go_app_yaml_file-method" class="method-detail ">
371
+ <a name="method-c-write_go_app_yaml_file"></a>
372
+
373
+
374
+ <div class="method-heading">
375
+ <span class="method-name">write_go_app_yaml_file</span><span
376
+ class="method-args">(function_name, output_dir, file=File)</span>
377
+ <span class="method-click-advice">click to toggle source</span>
378
+ </div>
379
+
380
+
381
+ <div class="method-description">
382
+
383
+ <p>Writes an app.yaml file for use with Go Google App Engine applications.
384
+ Right now, we direct all URL requests to the Go app we are about to
385
+ construct, but in the future we may add support for jQuery and Bootstrap to
386
+ automatically put a nice UI on the / url.</p>
387
+
388
+
389
+
390
+ <div class="method-source-code"
391
+ id="write_go_app_yaml_file-source">
392
+ <pre>
393
+ <span class="ruby-comment"># File lib/generator.rb, line 141</span>
394
+ def self.write_go_app_yaml_file(function_name, output_dir, file=<span class="ruby-constant">File</span>)
395
+ app_yaml_contents = <span class="ruby-string">application: #{function_name}version: 1runtime: goapi_version: 3handlers:- url: /.* script: _go_app</span>
396
+
397
+ app_yaml_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
398
+ <span class="ruby-string">&quot;app.yaml&quot;</span>)
399
+
400
+ file.open(app_yaml_location, <span class="ruby-string">&quot;w+&quot;</span>) { |file| file.write(app_yaml_contents) }
401
+ end</pre>
402
+ </div>
403
+
404
+ </div>
405
+
406
+
407
+
408
+
409
+ </div>
410
+
411
+
412
+ <div id="write_go_cicero_code-method" class="method-detail ">
413
+ <a name="method-c-write_go_cicero_code"></a>
414
+
415
+
416
+ <div class="method-heading">
417
+ <span class="method-name">write_go_cicero_code</span><span
418
+ class="method-args">(function, function_name, output_dir, file=File)</span>
419
+ <span class="method-click-advice">click to toggle source</span>
420
+ </div>
421
+
422
+
423
+ <div class="method-description">
424
+
425
+ <p>Writes a main.go function that is a Go Google App Engine application with
426
+ the user’s function in it.</p>
427
+
428
+
429
+
430
+ <div class="method-source-code"
431
+ id="write_go_cicero_code-source">
432
+ <pre>
433
+ <span class="ruby-comment"># File lib/generator.rb, line 161</span>
434
+ def self.write_go_cicero_code(function, function_name, output_dir, file=<span class="ruby-constant">File</span>)
435
+ template_location = <span class="ruby-constant">File</span>.join(<span class="ruby-constant">File</span>.dirname(__FILE__), <span class="ruby-string">&quot;..&quot;</span>,
436
+ <span class="ruby-string">&quot;templates&quot;</span>, <span class="ruby-string">&quot;main.go&quot;</span>)
437
+ main_go_contents = file.open(template_location) { |f| f.read }
438
+ main_go_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_CONTENTS/</span>, function)
439
+ main_go_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_NAME/</span>, function_name)
440
+
441
+ main_go_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
442
+ <span class="ruby-string">&quot;main.go&quot;</span>)
443
+
444
+ file.open(main_go_location, <span class="ruby-string">&quot;w+&quot;</span>) { |file| file.write(main_go_contents) }
445
+ end</pre>
446
+ </div>
447
+
448
+ </div>
449
+
450
+
451
+
452
+
453
+ </div>
454
+
455
+
456
+ <div id="write_python_app_yaml_file-method" class="method-detail ">
457
+ <a name="method-c-write_python_app_yaml_file"></a>
458
+
459
+
460
+ <div class="method-heading">
461
+ <span class="method-name">write_python_app_yaml_file</span><span
462
+ class="method-args">(function_name, output_dir, file=File)</span>
463
+ <span class="method-click-advice">click to toggle source</span>
464
+ </div>
465
+
466
+
467
+ <div class="method-description">
468
+
469
+ <p>Writes an app.yaml file for use with Python Google App Engine applications.
470
+ TODO(cgb): Add support for jquery and bootstrap? If so, also be sure to
471
+ write those files in the given directory.</p>
472
+
473
+
474
+
475
+ <div class="method-source-code"
476
+ id="write_python_app_yaml_file-source">
477
+ <pre>
478
+ <span class="ruby-comment"># File lib/generator.rb, line 91</span>
479
+ def self.write_python_app_yaml_file(function_name, output_dir, file=<span class="ruby-constant">File</span>)
480
+ app_yaml_contents = <span class="ruby-string">application: #{function_name}version: 1runtime: pythonapi_version: 1- url: .* script: main.py</span>
481
+
482
+ app_yaml_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
483
+ <span class="ruby-string">&quot;app.yaml&quot;</span>)
484
+
485
+ file.open(app_yaml_location, <span class="ruby-string">&quot;w+&quot;</span>) { |file| file.write(app_yaml_contents) }
486
+ end</pre>
487
+ </div>
488
+
489
+ </div>
490
+
491
+
492
+
493
+
494
+ </div>
495
+
496
+
497
+ <div id="write_python_cicero_code-method" class="method-detail ">
498
+ <a name="method-c-write_python_cicero_code"></a>
499
+
500
+
501
+ <div class="method-heading">
502
+ <span class="method-name">write_python_cicero_code</span><span
503
+ class="method-args">(function, function_name, output_dir, file=File)</span>
504
+ <span class="method-click-advice">click to toggle source</span>
505
+ </div>
506
+
507
+
508
+ <div class="method-description">
509
+
510
+ <p>Writes a main.py file for use with Python Google App Engine applications.
511
+ Sets up a standard set of routes according to the Cicero API. TODO(cgb):
512
+ The user may have their own imports in the code - consider automatically
513
+ placing them in as well.</p>
514
+
515
+
516
+
517
+ <div class="method-source-code"
518
+ id="write_python_cicero_code-source">
519
+ <pre>
520
+ <span class="ruby-comment"># File lib/generator.rb, line 112</span>
521
+ def self.write_python_cicero_code(function, function_name, output_dir,
522
+ file=<span class="ruby-constant">File</span>)
523
+
524
+ template_location = <span class="ruby-constant">File</span>.join(<span class="ruby-constant">File</span>.dirname(__FILE__), <span class="ruby-string">&quot;..&quot;</span>,
525
+ <span class="ruby-string">&quot;templates&quot;</span>, <span class="ruby-string">&quot;main.py&quot;</span>)
526
+ main_py_contents = file.open(template_location) { |f| f.read }
527
+ main_py_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_CONTENTS/</span>, function)
528
+ main_py_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_NAME/</span>, function_name)
529
+
530
+ main_py_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
531
+ <span class="ruby-string">&quot;main.py&quot;</span>)
532
+
533
+ file.open(main_py_location, <span class="ruby-string">&quot;w+&quot;</span>) { |file| file.write(main_py_contents) }
534
+ end</pre>
535
+ </div>
536
+
537
+ </div>
538
+
539
+
540
+
541
+
542
+ </div>
543
+
544
+
545
+ </div>
546
+
547
+
548
+ </div>
549
+
550
+ <div id="validator-badges">
551
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
552
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
553
+ Rdoc Generator</a> 2</small>.</p>
554
+ </div>
555
+
556
+ </body>
557
+ </html>
558
+