Created
November 29, 2011 02:47
-
-
Save ambethia/1403137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ -> | |
| return if $("#console").length < 1 | |
| $("#console_input").keyup (event) -> | |
| if event.which == 13 | |
| command = $(this).val() | |
| $.ajax | |
| url: '/console' | |
| type: 'POST' | |
| dataType: 'text' | |
| data: | |
| cmd: command | |
| success: (data) -> | |
| cmd = $("<div class='cmd'></div>").text(command) | |
| out = $("<div class='out'></div>").text(data) | |
| $("#console .output").append(cmd).append(out) | |
| $("#console_input").val('') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #console | |
| .output | |
| .input | |
| %input#console_input{type:"text", autofocus:true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #console | |
| background-color: #333 | |
| color: #fff | |
| padding: 10px | |
| .output | |
| height: 20em | |
| .cmd | |
| color: #999 | |
| #console_input | |
| padding: 5px | |
| margin: 0 | |
| background-color: #666 | |
| color: #fff | |
| border: none | |
| height: 1em | |
| width: 740px |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ConsoleController < ApplicationController | |
| def index | |
| if params[:cmd] | |
| result = begin | |
| $repl ||= REPL.new | |
| result = $repl.instance_eval <<-EOF.trim_gutter | |
| | result = (#{params['cmd']}) | |
| | @_#{current_employee.id} ||= {} | |
| | @_#{current_employee.id}.update(local_variables.inject({}) do |h, v| | |
| | h.update({v => eval(v.to_s)}) | |
| | end) | |
| | result | |
| EOF | |
| result.inspect | |
| rescue=>e | |
| "Error: " + e.message | |
| end | |
| render :text => result | |
| end | |
| end | |
| class REPL | |
| def method_missing(method, *args, &block) | |
| eval <<-EOF.trim_gutter | |
| | @_#{current_employee.id} ||= {} | |
| | @_#{current_employee.id}[method.to_sym] || super(method, *args, &block) | |
| EOF | |
| end | |
| def reload! | |
| $repl = REPL.new | |
| 'ok' | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| match 'console' => 'console#index' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment