Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 1b1d397f1076ff24f64b4ebeb8c891291f0076c1 Rodrigo Rosenfeld Rosas committed Oct 6, 2010
@@ -0,0 +1 @@
+*.swp
@@ -0,0 +1,20 @@
+Copyright (c) 2010 [Rodrigo Rosenfeld Rosas]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 README
@@ -0,0 +1,12 @@
+Console
+=======
+
+A Rails 3 plugin for running Ruby scripts on the browser in the context of a controller action.
+
+Just put it in your vendor/plugins/console. For instance:
+
+git submodule add git://github.com/rosenfeld/rails-web-console.git vendor/plugins/console
+
+Then, access "/console" in your browser.
+
+Copyright (c) 2010 [Rodrigo Rosenfeld Rosas], released under the MIT license
@@ -0,0 +1,20 @@
+require 'stringio'
+class ConsoleController < ApplicationController
+ def index
+ end
+
+ def run
+ session[:script] = params[:script]
+ stdout_orig = $stdout
+ $stdout = StringIO.new
+ begin
+ result_eval = eval params[:script], binding
+ $stdout.rewind
+ result = %Q{<div class="stdout">#{$stdout.read}</div><div class="return">#{result_eval.inspect}</div>}
+ rescue Exception => e
+ result = e.to_s
+ end
+ $stdout = stdout_orig
+ render text: result.gsub("\n", "<br />\n")
+ end
+end
@@ -0,0 +1,3 @@
+<textarea id="script" rows="10" cols="80"><%= session[:script] %></textarea>
+<div><input type="button" value="Clear" id="clearResults" /><input type="button" value="Run" id="runScript" /></div>
+<div id="results"></div>
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Console</title>
+ <%= javascript_include_tag 'http://code.jquery.com/jquery-1.4.2.min.js' %>
+ <%= javascript_include_tag 'console' %>
+ <%= stylesheet_link_tag 'console' %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,4 @@
+Rails::Application.routes.draw do
+ get 'console' => 'console#index'
+ post 'console/run' => 'console#run'
+end
@@ -0,0 +1 @@
+config.middleware.use ::ActionDispatch::Static, "#{root}/public"
@@ -0,0 +1,7 @@
+module Console
+ class Engine < Rails::Engine
+# initializer "static assets" do |app|
+# app.middleware.use ::ActionDispatch::Static, "#{root}/public"
+# end
+ end
+end
@@ -0,0 +1,8 @@
+jQuery(function($) {
+ $('#clearResults').click(function() { $('#results').empty() })
+ $('#runScript').click(function() {
+ $.post('/console/run', {script: $('#script').val()}, function(data) {
+ $('<div/>').attr('class', 'console_result').html(data).appendTo('#results')
+ })
+ })
+})
@@ -0,0 +1,10 @@
+#script {width: 100%}
+.console_result {
+ background-color: black;
+ color: white;
+ margin: 1em 0;
+}
+
+.return {
+ background-color: blue;
+}

0 comments on commit 1b1d397

Please sign in to comment.