iamjwc-hirb 0.1.0 → 0.1.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.
data/lib/hirb.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Hirb; end
2
+
3
+ $: << File.join(File.dirname(__FILE__))
4
+
5
+ require 'hirb/app'
6
+ require 'hirb/eval'
7
+
data/lib/hirb/app.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rack'
2
+
3
+ class Hirb::App
4
+ class << self
5
+ def call(env)
6
+ r = Rack::Request.new(env)
7
+
8
+ if r.path_info =~ /^\/hirb\/eval/
9
+ [200, {"Content-Type" => "text/plain"}, Hirb::Eval.boom_shakalaka(r[:cmd])]
10
+ elsif r.path_info =~ /^\/hirb/
11
+ html = File.read(File.join(File.dirname(__FILE__), "..", "..", "public", "hirb", "index.html"))
12
+ [200, {"Content-Type" => "text/html", "Content-Length" => html.size.to_s}, html]
13
+ else
14
+ [404, {"Content-Type" => "text/html"}, "Not Found"]
15
+ end
16
+ end
17
+ end
18
+ end
19
+
data/lib/hirb/eval.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+
3
+ $binding ||= binding
4
+
5
+ class Hirb::Eval
6
+ class << self
7
+ def boom_shakalaka(cmd)
8
+ puts "=" * 80
9
+ puts cmd
10
+ puts "=" * 80
11
+ JSON.generate(
12
+ steal_output { Kernel.eval("_ = #{cmd}", $binding) }
13
+ )
14
+ end
15
+
16
+ def steal_output(&b)
17
+ # Hold on to stdout and stderr
18
+ stdout, stderr = $stdout, $stderr
19
+
20
+ # Redirect stdout and stderr
21
+ $stdout, $stderr = StringIO.new, StringIO.new
22
+
23
+ result = nil
24
+ begin
25
+ result = b.call.inspect
26
+ rescue
27
+ $stderr.puts $!
28
+ $stderr.puts $!.backtrace
29
+
30
+ stderr.puts $!
31
+ stderr.puts $!.backtrace
32
+ end
33
+
34
+ r = {
35
+ :result => result,
36
+ :out => $stdout.string.split("\n"),
37
+ :err => $stderr.string.split("\n")
38
+ }
39
+
40
+ # Set stdout and stderr back
41
+ $stdout, $stderr = stdout, stderr
42
+
43
+ r
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,126 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
5
+ <title>hirb</title>
6
+
7
+ <style type="text/css">
8
+ #irb * {
9
+ font-family: "Andale Mono", "Monaco", monospace;
10
+ font-size: 14px;
11
+ }
12
+ #irb {
13
+ border: 1px solid #43d;
14
+ background: #fff;
15
+
16
+ }
17
+ #irb ul {
18
+ list-style: none;
19
+ margin: 0;
20
+ padding: 0;
21
+ }
22
+ #irb ul li {
23
+ margin: 0;
24
+ padding: 0 5px;
25
+ }
26
+ #irb ul li.code:before {
27
+ content: "> ";
28
+ color: #ddddff;
29
+ }
30
+ #irb ul li.result:before {
31
+ content: "# => ";
32
+ color: #0000ff;
33
+ }
34
+ #irb ul li.result {
35
+ font-style: italic;
36
+ color: #888;
37
+ }
38
+ #irb input {
39
+ border: 0;
40
+ padding: 0;
41
+ margin: 0;
42
+ width: 85%;
43
+ }
44
+ </style>
45
+
46
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
47
+ <script type="text/javascript">
48
+ $(document).ready(function() {
49
+ var commands = [];
50
+ var commandIndex = null;
51
+ var tempCommand = null;
52
+
53
+ $("#irb input#code").focus(function() {
54
+ window.p.smartPlaylistFormFocus = true;
55
+ }).blur(function() {
56
+ window.p.smartPlaylistFormFocus = false;
57
+ });
58
+
59
+ $('#irb input#code').keypress(function(e) {
60
+ if(e.keyCode == 13) {
61
+ $('<li class="code">' + $('#code').val() + '</li>').insertBefore('#irb ul li.code:last');
62
+
63
+ $.get("/hirb/eval?cmd=" + escape($('#code').val()), function(json) {
64
+ json = eval('(' + json + ')')
65
+
66
+ if(json.out.length) {
67
+ $('<li class="stdout"></li>').text(json.out.join("\n")).insertBefore('#irb ul li.code:last')
68
+ }
69
+ if(json.err.length) {
70
+ jQuery.each(json.err, function() {
71
+ $('<li class="stderr"></li>').text(this.toString()).insertBefore('#irb ul li.code:last')
72
+ });
73
+ }
74
+ if(json.result) {
75
+ $('<li class="result"></li>').text(json.result).insertBefore('#irb ul li.code:last')
76
+ }
77
+ })
78
+
79
+ if(commands[commands.length - 1] != $('#code').val()) {
80
+ commands.push($('#code').val());
81
+ }
82
+ commandIndex = null;
83
+ tempCommand = null;
84
+
85
+ $('#code').val("").focus();
86
+ } else if(e.keyCode == 38) { // Pressed up
87
+ if(!tempCommand) {
88
+ tempCommand = $('#code').val();
89
+ commandIndex = commands.length;
90
+ }
91
+
92
+ if(commandIndex != 0) {
93
+ commandIndex -= 1;
94
+ }
95
+
96
+ $('#code').val(commands[commandIndex]);
97
+ } else if(e.keyCode == 40) { // Pressed down
98
+ if(tempCommand) {
99
+ if(commandIndex != commands.length - 1) {
100
+ commandIndex += 1;
101
+ $('#code').val(commands[commandIndex]);
102
+ } else {
103
+ commandIndex = null;
104
+ $('#code').val(tempCommand);
105
+ tempCommand = null;
106
+ }
107
+ }
108
+ }
109
+
110
+ console.log("tempCommand: " + (tempCommand || "null"));
111
+ console.log("commandIndex: " + (commandIndex || "null"));
112
+ });
113
+ });
114
+ </script>
115
+
116
+
117
+ </head>
118
+ <body>
119
+ <div id="irb">
120
+ <ul>
121
+ <li class="code"><input type="text" id="code" /></li>
122
+ </ul>
123
+ </div>
124
+ </body>
125
+ </html>
126
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iamjwc-hirb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Camerer
@@ -40,8 +40,11 @@ extensions: []
40
40
 
41
41
  extra_rdoc_files: []
42
42
 
43
- files: []
44
-
43
+ files:
44
+ - lib/hirb.rb
45
+ - lib/hirb/app.rb
46
+ - lib/hirb/eval.rb
47
+ - public/hirb/index.html
45
48
  has_rdoc: false
46
49
  homepage:
47
50
  licenses: