tailog 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8036aae9bdd63431019506197d16da8dc03f8078
4
- data.tar.gz: 75a7f2f95b80ae5a4d3e8a78290ba8f2fe3a17c3
3
+ metadata.gz: dbe0ce3cbc6cfee5b3f0654a74e6c1b7b88e3095
4
+ data.tar.gz: 64b6ce2ddab91b524011d8d9e826ad70df0c5c42
5
5
  SHA512:
6
- metadata.gz: 46d340edf38fadf9a8e42a6ea8865d9892fb762d6217c60f76f3f658f2a11124652efa4928483574a0c0e86c802e6c447ad8e30ccd4d99e43014287880aca1d4
7
- data.tar.gz: 0722815ec64c24bdb81347e33fa95e6af6626fc6f44eaa979f54d417b24a197f5fc98d15bfd001dd77838b7a45fb4c389acc452fe0afa3e0504e6976fed383b3
6
+ metadata.gz: 4a8eabf2bd84d64aebb6bf3670ff0a6cfb87b8661b1992838f2a58fdb569754cce0f07f842bb3207554b60f376860a6390998e9fe241af73e5d0d48a86d81821
7
+ data.tar.gz: 390fb9fbc007d02fd2d6a9acaec2adad9aa4e0e2c011475d8b05a674df2c85081ef852129e7c64e1f0fdb5f84e44ca5920a78bff2275c921fe7c95ce3d569c61
@@ -8,7 +8,10 @@
8
8
  <option value="ruby_debug">Ruby (Debug Mode)</option>
9
9
  <option value="bash">Bash</option>
10
10
  </select>
11
- <button type="submit" class="btn btn-primary">Submit</button>
11
+ <button id="submit-button" type="submit" class="btn btn-primary">Submit</button>
12
+ </div>
13
+ <div>
14
+ Press <kbd><kbd>Ctrl</kbd> + <kbd>Enter</kbd></kbd> to submit code
12
15
  </div>
13
16
  </form>
14
17
 
@@ -19,14 +22,17 @@
19
22
  <script type="text/javascript" src="javascripts/mode/shell.js"></script>
20
23
  <link rel="stylesheet" type="text/css" href="stylesheets/codemirror.css">
21
24
  <script type="text/javascript">
25
+ var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault;
26
+ CodeMirror.keyMap.default["Tab"] = function(editor) {
27
+ var spaces = Array(editor.getOption("indentUnit") + 1).join(" ");
28
+ editor.replaceSelection(spaces);
29
+ };
30
+ CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Enter"] = function(editor) {
31
+ $("#submit-button").trigger('click');
32
+ };
33
+
22
34
  var editor = CodeMirror.fromTextArea($("#editor")[0], {
23
- lineNumbers: true,
24
- extraKeys: {
25
- Tab: function(editor) {
26
- var spaces = Array(editor.getOption("indentUnit") + 1).join(" ");
27
- editor.replaceSelection(spaces);
28
- }
29
- }
35
+ lineNumbers: true
30
36
  });
31
37
 
32
38
  ModeMap = {
@@ -1,12 +1,11 @@
1
1
  <% begin %>
2
-
3
- <% input = StringIO.new(script) %>
4
2
  <% output = StringIO.new %>
5
- <% binding = Object.new.send :binding %>
6
3
 
7
4
  <% begin %>
8
- <% Pry.start binding, input: input, output: output %>
9
- <%= h output.string %>
5
+ <% output.send :eval, script %>
6
+ <% output.string.each_line do |line| %>
7
+ <p><%= h line %></p>
8
+ <% end %>
10
9
  <% rescue => error %>
11
10
  <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
12
11
  <% error.backtrace.each do |backtrace| %>
@@ -1,16 +1,28 @@
1
1
  <% begin %>
2
- <% binding = Object.new.send :binding %>
3
- <% script.each_line do |line| %>
4
- <% next if line.strip.empty? %>
5
- <p class="text-info">&gt; <%= h line %></p>
6
- <% begin %>
7
- <% result = binding.eval(line).inspect %>
8
- <p>=> <%= h result %></p>
9
- <% rescue => error %>
10
- <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
11
- <% break %>
2
+ <% irb = IRB::Irb.new nil, StringInputMethod.new(script + "\n") %>
3
+ <% IRB.conf[:MAIN_CONTEXT] = irb.context %>
4
+ <% IRB.conf[:OUTPUT] = [] %>
5
+
6
+ <% begin %>
7
+ <% irb.eval_input %>
8
+ <% IRB.Output.each do |key, line| %>
9
+ <% case key %>
10
+ <% when :stdin %>
11
+ <p><%= h line %></p>
12
+ <% when :stdout %>
13
+ <p class="text-info"><%= h line %></p>
14
+ <% when :stderr %>
15
+ <p class="text-danger"><%= h line %></p>
16
+ <% end %>
17
+ <% end %>
18
+ <% rescue => error %>
19
+ <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
20
+ <% error.backtrace.each do |backtrace| %>
21
+ <p class="text-danger"> <%= h backtrace %></p>
12
22
  <% end %>
13
23
  <% end %>
24
+
14
25
  <% rescue => error %>
15
26
  <%= erb :error, locals: { error: error }, layout: false %>
16
27
  <% end %>
28
+
@@ -0,0 +1,51 @@
1
+ require 'irb'
2
+
3
+ IRB.setup nil
4
+
5
+ def IRB.Output
6
+ IRB.conf[:OUTPUT]
7
+ end
8
+
9
+ class IRB::WorkSpace
10
+ def evaluate(context, statements, file = __FILE__, line = __LINE__)
11
+ @after_ruby_debug_erb = false
12
+ eval(statements, @binding, file, line)
13
+ end
14
+
15
+ FILTER_BACKTRACE_REGEX = /#{__FILE__}/
16
+ def filter_backtrace backtrace
17
+ return if @after_ruby_debug_erb
18
+ if backtrace =~ FILTER_BACKTRACE_REGEX
19
+ @after_ruby_debug_erb = true
20
+ return
21
+ else
22
+ backtrace.sub(/:\s*in `irb_binding'/, '')
23
+ end
24
+ end
25
+ end
26
+
27
+ class IRB::Irb
28
+ def output_value
29
+ context = IRB.CurrentContext
30
+ IRB.Output << [ :stdout, context.return_format % context.inspect_last_value ]
31
+ end
32
+
33
+ def print *args
34
+ IRB.Output << [ :stderr, args.join ]
35
+ end
36
+
37
+ def printf format, *args
38
+ IRB.Output << [ :stderr, format % args ]
39
+ end
40
+ end
41
+
42
+ class StringInputMethod < StringIO
43
+ attr_accessor :prompt
44
+ def encoding; string.encoding end
45
+
46
+ def gets
47
+ line = super
48
+ IRB.Output << [ :stdin, line ] if line
49
+ line
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
data/lib/tailog.rb CHANGED
@@ -4,6 +4,7 @@ require 'tailog/request_id'
4
4
  require 'tailog/watch_methods'
5
5
  require 'tailog/ext/file'
6
6
  require 'tailog/ext/integer'
7
+ require 'tailog/ext/irb'
7
8
 
8
9
  require 'sinatra/base'
9
10
  require 'socket'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbtfr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-22 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -98,6 +98,7 @@ files:
98
98
  - lib/tailog/eval.rb
99
99
  - lib/tailog/ext/file.rb
100
100
  - lib/tailog/ext/integer.rb
101
+ - lib/tailog/ext/irb.rb
101
102
  - lib/tailog/request_id.rb
102
103
  - lib/tailog/version.rb
103
104
  - lib/tailog/watch_methods.rb